diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/models/audit_event_spec.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/models/audit_event_spec.rb')
-rw-r--r-- | spec/models/audit_event_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/models/audit_event_spec.rb b/spec/models/audit_event_spec.rb index bc603bc5ab6..4fba5fddc92 100644 --- a/spec/models/audit_event_spec.rb +++ b/spec/models/audit_event_spec.rb @@ -10,6 +10,71 @@ RSpec.describe AuditEvent do end end + describe 'callbacks' do + describe '#parallel_persist' do + shared_examples 'a parallel persisted field' do + using RSpec::Parameterized::TableSyntax + + where(:column, :details, :expected_value) do + :value | nil | :value + nil | :value | :value + :value | :another_value | :value + nil | nil | nil + end + + with_them do + let(:values) { { value: value, another_value: "#{value}88" } } + + let(:audit_event) do + build(:audit_event, name => values[column], details: { name => values[details] }) + end + + it 'sets both values to be the same', :aggregate_failures do + audit_event.validate + + expect(audit_event[name]).to eq(values[expected_value]) + expect(audit_event.details[name]).to eq(values[expected_value]) + end + end + end + + context 'wih author_name' do + let(:name) { :author_name } + let(:value) { 'Mary Poppins' } + + it_behaves_like 'a parallel persisted field' + end + + context 'with entity_path' do + let(:name) { :entity_path } + let(:value) { 'gitlab-org' } + + it_behaves_like 'a parallel persisted field' + end + + context 'with target_details' do + let(:name) { :target_details } + let(:value) { 'gitlab-org/gitlab' } + + it_behaves_like 'a parallel persisted field' + end + + context 'with target_type' do + let(:name) { :target_type } + let(:value) { 'Project' } + + it_behaves_like 'a parallel persisted field' + end + + context 'with target_id' do + let(:name) { :target_id } + let(:value) { 8 } + + it_behaves_like 'a parallel persisted field' + end + end + end + it 'sanitizes custom_message in the details hash' do audit_event = create(:project_audit_event, details: { target_id: 678, custom_message: '<strong>Arnold</strong>' }) |