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.
This commit is contained in:
Javi Martín
2019-10-12 03:48:54 +02:00
parent 0070b73304
commit b4b20e0295
7 changed files with 12 additions and 12 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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