From b4b20e0295764fe8ee2213916b03aeee55af1b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 12 Oct 2019 03:48:54 +0200 Subject: [PATCH] Assign attributes to test invalid updates Using `update` is a bit ambiguous; when we do it we aren't expressing whether we expect the update operation to succeed or fail. --- spec/lib/evaluation_comment_email_spec.rb | 2 +- spec/lib/reply_email_spec.rb | 2 +- spec/models/admin_notification_spec.rb | 2 +- spec/models/budget/investment_spec.rb | 2 +- spec/models/budget/phase_spec.rb | 6 +++--- spec/models/concerns/globalizable.rb | 8 ++++---- spec/models/newsletter_spec.rb | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/lib/evaluation_comment_email_spec.rb b/spec/lib/evaluation_comment_email_spec.rb index ec4ed6f33..f45901752 100644 --- a/spec/lib/evaluation_comment_email_spec.rb +++ b/spec/lib/evaluation_comment_email_spec.rb @@ -43,7 +43,7 @@ describe EvaluationCommentEmail do end it "returns false if the comment doesn't exist" do - comment.update(commentable: nil) + comment.commentable = nil expect(comment_email.can_be_sent?).to be false end diff --git a/spec/lib/reply_email_spec.rb b/spec/lib/reply_email_spec.rb index 68054e08f..834eb89af 100644 --- a/spec/lib/reply_email_spec.rb +++ b/spec/lib/reply_email_spec.rb @@ -39,7 +39,7 @@ describe ReplyEmail do end it "returns false if the comment doesn't exist" do - reply.update(commentable: nil) + reply.commentable = nil expect(reply_email.can_be_sent?).to be false end diff --git a/spec/models/admin_notification_spec.rb b/spec/models/admin_notification_spec.rb index 7bb56a311..db03ca383 100644 --- a/spec/models/admin_notification_spec.rb +++ b/spec/models/admin_notification_spec.rb @@ -67,7 +67,7 @@ describe AdminNotification do describe "#valid_segment_recipient?" do it "is false when segment_recipient value is invalid" do - admin_notification.update(segment_recipient: "invalid_segment_name") + admin_notification.segment_recipient = "invalid_segment_name" error = "The user recipients segment is invalid" expect(admin_notification).not_to be_valid diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index d01a10f1d..a322956a7 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -315,7 +315,7 @@ describe Budget::Investment do end it "returns false if unfeasibility explanation blank" do - investment.update(unfeasibility_explanation: "") + investment.unfeasibility_explanation = "" Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| budget.update(phase: phase) diff --git a/spec/models/budget/phase_spec.rb b/spec/models/budget/phase_spec.rb index 921d9eca1..375c82c9f 100644 --- a/spec/models/budget/phase_spec.rb +++ b/spec/models/budget/phase_spec.rb @@ -32,19 +32,19 @@ describe Budget::Phase do describe "#dates_range_valid?" do it "is valid when start & end dates are different & consecutive" do - first_phase.update_attributes(starts_at: Date.current, ends_at: Date.tomorrow) + first_phase.assign_attributes(starts_at: Date.current, ends_at: Date.tomorrow) expect(first_phase).to be_valid end it "is not valid when dates are equal" do - first_phase.update_attributes(starts_at: Date.current, ends_at: Date.current) + first_phase.assign_attributes(starts_at: Date.current, ends_at: Date.current) expect(first_phase).not_to be_valid end it "is not valid when start date is later than end date" do - first_phase.update_attributes(starts_at: Date.tomorrow, ends_at: Date.current) + first_phase.assign_attributes(starts_at: Date.tomorrow, ends_at: Date.current) expect(first_phase).not_to be_valid end diff --git a/spec/models/concerns/globalizable.rb b/spec/models/concerns/globalizable.rb index 58900442b..e45df8ba0 100644 --- a/spec/models/concerns/globalizable.rb +++ b/spec/models/concerns/globalizable.rb @@ -124,10 +124,10 @@ shared_examples_for "globalizable" do |factory_name| it "Does not remove all translations" do skip("cannot have invalid translations") if required_fields.empty? - record.update(translations_attributes: [ + record.translations_attributes = [ { id: record.translations.find_by(locale: :en).id, _destroy: true }, { id: record.translations.find_by(locale: :es).id, _destroy: true } - ]) + ] expect(record).not_to be_valid @@ -139,10 +139,10 @@ shared_examples_for "globalizable" do |factory_name| it "Does not remove translations when there's invalid data" do skip("cannot have invalid translations") if required_fields.empty? - record.update(translations_attributes: [ + record.translations_attributes = [ { id: record.translations.find_by(locale: :es).id, attribute => "" }, { id: record.translations.find_by(locale: :en).id, _destroy: true }, - ]) + ] expect(record).not_to be_valid diff --git a/spec/models/newsletter_spec.rb b/spec/models/newsletter_spec.rb index d04f7e8d0..82e8087ba 100644 --- a/spec/models/newsletter_spec.rb +++ b/spec/models/newsletter_spec.rb @@ -39,7 +39,7 @@ describe Newsletter do describe "#valid_segment_recipient?" do it "is false when segment_recipient value is invalid" do - newsletter.update(segment_recipient: "invalid_segment_name") + newsletter.segment_recipient = "invalid_segment_name" error = "The user recipients segment is invalid" expect(newsletter).not_to be_valid