diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/models/application_record_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/models/application_record_spec.rb')
-rw-r--r-- | spec/models/application_record_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/models/application_record_spec.rb b/spec/models/application_record_spec.rb index cc314d9077d..d9ab326505b 100644 --- a/spec/models/application_record_spec.rb +++ b/spec/models/application_record_spec.rb @@ -38,6 +38,21 @@ RSpec.describe ApplicationRecord do expect { Suggestion.safe_find_or_create_by(build(:suggestion).attributes) } .to change { Suggestion.count }.by(1) end + + it 'passes a block to find_or_create_by' do + attributes = build(:suggestion).attributes + + expect do |block| + Suggestion.safe_find_or_create_by(attributes, &block) + end.to yield_with_args(an_object_having_attributes(attributes)) + end + + it 'does not create a record when is not valid' do + raw_usage_data = RawUsageData.safe_find_or_create_by({ recorded_at: nil }) + + expect(raw_usage_data.id).to be_nil + expect(raw_usage_data).not_to be_valid + end end describe '.safe_find_or_create_by!' do @@ -51,6 +66,14 @@ RSpec.describe ApplicationRecord do it 'raises a validation error if the record was not persisted' do expect { Suggestion.find_or_create_by!(note: nil) }.to raise_error(ActiveRecord::RecordInvalid) end + + it 'passes a block to find_or_create_by' do + attributes = build(:suggestion).attributes + + expect do |block| + Suggestion.safe_find_or_create_by!(attributes, &block) + end.to yield_with_args(an_object_having_attributes(attributes)) + end end describe '.underscore' do |