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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user