FIX: Admin logging should not log permissions if none has been set.

This commit is contained in:
Guo Xiang Tan 2015-12-06 15:29:13 +08:00
parent ad98f270c9
commit 8b6b3cf858
2 changed files with 12 additions and 1 deletions

View file

@ -215,7 +215,7 @@ class StaffActionLogger
changed_attributes = category.previous_changes.slice(*category_params.keys)
if old_permissions != category_params[:permissions]
if !old_permissions.empty? && (old_permissions != category_params[:permissions])
changed_attributes.merge!({ permissions: [old_permissions.to_json, category_params[:permissions].to_json] })
end

View file

@ -306,6 +306,17 @@ describe StaffActionLogger do
expect(name_user_history.previous_value).to eq('haha')
expect(name_user_history.new_value).to eq('new_name')
end
it "does not log permissions changes for category visible to everyone" do
attributes = { name: 'new_name' }
old_permission = category.permissions_params
category.update!(attributes)
logger.log_category_settings_change(category, attributes.merge({ permissions: { "everyone" => 1 } }), old_permission)
expect(UserHistory.count).to eq(1)
expect(UserHistory.find_by_subject('name').category).to eq(category)
end
end
describe 'log_category_deletion' do