diff --git a/app/models/signature.rb b/app/models/signature.rb index 5b2331bed..8395e7cca 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -37,7 +37,7 @@ class Signature < ApplicationRecord def assign_signature_to_vote vote = Vote.where(votable: signable, voter: user).first - vote&.update(signature: self) + vote&.update!(signature: self) end def user_exists? diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index 6b6a41fdf..0541b249f 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -158,7 +158,7 @@ describe "Admin legislation questions" do context "Special translation behaviour" do before do - question.update_attributes(title_en: "Title in English", title_es: "Título en Español") + question.update!(title_en: "Title in English", title_es: "Título en Español") end scenario "Add translation for question option", :js do diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index fe54152b2..fb00018db 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -38,7 +38,7 @@ describe "Budgets" do heading1 = create(:budget_heading, group: group1) heading2 = create(:budget_heading, group: group2) - budget.update_attributes!(phase: "informing") + budget.update!(phase: "informing") visit budgets_path @@ -51,7 +51,7 @@ describe "Budgets" do expect(page).to have_link("See all phases") end - budget.update_attributes!(phase: "publishing_prices") + budget.update!(phase: "publishing_prices") visit budgets_path within("#budget_heading") do @@ -114,7 +114,7 @@ describe "Budgets" do end scenario "Show informing index without links" do - budget.update_attributes!(phase: "informing") + budget.update!(phase: "informing") heading = create(:budget_heading, budget: budget) visit budgets_path @@ -132,7 +132,7 @@ describe "Budgets" do end scenario "Show finished index without heading links" do - budget.update_attributes!(phase: "finished") + budget.update!(phase: "finished") heading = create(:budget_heading, budget: budget) visit budgets_path diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb index 5cc2e7bcc..12e526059 100644 --- a/spec/features/comments/legislation_questions_spec.rb +++ b/spec/features/comments/legislation_questions_spec.rb @@ -226,7 +226,7 @@ describe "Commenting legislation questions" do end scenario "Can't create comments if debate phase is not open", :js do - process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) + process.update!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index bba16eace..c9a6e65d6 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -160,7 +160,7 @@ describe "Notifications" do end scenario "With internal link" do - admin_notification.update_attributes!(link: "/stats") + admin_notification.update!(link: "/stats") visit notifications_path expect(page).to have_content("Notification title") @@ -171,7 +171,7 @@ describe "Notifications" do end scenario "Without a link" do - admin_notification.update_attributes!(link: "/stats") + admin_notification.update!(link: "/stats") visit notifications_path expect(page).to have_content("Notification title") diff --git a/spec/models/budget/phase_spec.rb b/spec/models/budget/phase_spec.rb index 375c82c9f..8fae98edd 100644 --- a/spec/models/budget/phase_spec.rb +++ b/spec/models/budget/phase_spec.rb @@ -132,35 +132,35 @@ describe Budget::Phase do describe "when being enabled" do before do - second_phase.update_attributes(enabled: false, - starts_at: Date.current, - ends_at: Date.current + 2.days) + second_phase.update!(enabled: false, + starts_at: Date.current, + ends_at: Date.current + 2.days) end it "adjusts previous enabled phase end date to its own start date" do - expect { second_phase.update_attributes(enabled: true) } + expect { second_phase.update(enabled: true) } .to change { prev_enabled_phase.ends_at.to_date }.to(Date.current) end it "adjusts next enabled phase start date to its own end date" do expect do - second_phase.update_attributes(enabled: true) + second_phase.update(enabled: true) end.to change { next_enabled_phase.starts_at.to_date }.to(Date.current + 2.days) end end describe "when disabled" do before do - second_phase.update_attributes(enabled: false) + second_phase.update!(enabled: false) end it "doesn't change previous enabled phase end date" do - expect { second_phase.update_attributes(starts_at: Date.current, ends_at: Date.current + 2.days) } + expect { second_phase.update(starts_at: Date.current, ends_at: Date.current + 2.days) } .not_to change { prev_enabled_phase.ends_at } end it "doesn't change next enabled phase start date" do - expect { second_phase.update_attributes(starts_at: Date.current, ends_at: Date.current + 2.days) } + expect { second_phase.update(starts_at: Date.current, ends_at: Date.current + 2.days) } .not_to change { next_enabled_phase.starts_at } end end @@ -168,17 +168,17 @@ describe Budget::Phase do describe "when being disabled" do it "doesn't adjust previous enabled phase end date to its own start date" do expect do - second_phase.update_attributes(enabled: false, - starts_at: Date.current, - ends_at: Date.current + 2.days) + second_phase.update(enabled: false, + starts_at: Date.current, + ends_at: Date.current + 2.days) end.not_to change { prev_enabled_phase.ends_at } end it "adjusts next enabled phase start date to its own start date" do expect do - second_phase.update_attributes(enabled: false, - starts_at: Date.current, - ends_at: Date.current + 2.days) + second_phase.update(enabled: false, + starts_at: Date.current, + ends_at: Date.current + 2.days) end.to change { next_enabled_phase.starts_at.to_date }.to(Date.current) end end @@ -186,7 +186,7 @@ describe Budget::Phase do describe "next & prev enabled phases" do before do - second_phase.update_attributes(enabled: false) + second_phase.update(enabled: false) end describe "#next_enabled_phase" do diff --git a/spec/models/concerns/sluggable.rb b/spec/models/concerns/sluggable.rb index bb5896f20..1b91d40a5 100644 --- a/spec/models/concerns/sluggable.rb +++ b/spec/models/concerns/sluggable.rb @@ -15,14 +15,14 @@ shared_examples_for "sluggable" do |updatable_slug_trait:| context "slug updating condition is true" do it "slug is updated" do updatable = create(factory_name, updatable_slug_trait, name: "Old Name") - expect { updatable.update_attributes(name: "New Name") } + expect { updatable.update(name: "New Name") } .to change { updatable.slug }.from("old-name").to("new-name") end end context "slug updating condition is false" do it "slug isn't updated" do - expect { sluggable.update_attributes(name: "New Name") } + expect { sluggable.update(name: "New Name") } .not_to change { sluggable.slug } end end diff --git a/spec/models/legislation/process/phase_spec.rb b/spec/models/legislation/process/phase_spec.rb index d30cc6265..965b5ced3 100644 --- a/spec/models/legislation/process/phase_spec.rb +++ b/spec/models/legislation/process/phase_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Legislation::Process::Phase, type: :model do it "checks debate phase" do expect(process.debate_phase.enabled?).to be true - process.update_attributes!(debate_phase_enabled: false) + process.update!(debate_phase_enabled: false) expect(process.debate_phase.enabled?).to be false end @@ -16,14 +16,14 @@ RSpec.describe Legislation::Process::Phase, type: :model do expect(process.draft_phase.enabled?).to be false expect(process_in_draft_phase.draft_phase.enabled?).to be true - process.update_attributes!(draft_phase_enabled: false) + process.update!(draft_phase_enabled: false) expect(process.draft_phase.enabled?).to be false end it "checks allegations phase" do expect(process.allegations_phase.enabled?).to be true - process.update_attributes!(allegations_phase_enabled: false) + process.update!(allegations_phase_enabled: false) expect(process.allegations_phase.enabled?).to be false end end @@ -31,67 +31,67 @@ RSpec.describe Legislation::Process::Phase, type: :model do describe "#started?" do it "checks debate phase" do # future - process.update_attributes!(debate_start_date: Date.current + 2.days, - debate_end_date: Date.current + 3.days) + process.update!(debate_start_date: Date.current + 2.days, + debate_end_date: Date.current + 3.days) expect(process.debate_phase.started?).to be false # started - process.update_attributes!(debate_start_date: Date.current - 2.days, - debate_end_date: Date.current + 1.day) + process.update!(debate_start_date: Date.current - 2.days, + debate_end_date: Date.current + 1.day) expect(process.debate_phase.started?).to be true # starts today - process.update_attributes!(debate_start_date: Date.current, - debate_end_date: Date.current + 1.day) + process.update!(debate_start_date: Date.current, + debate_end_date: Date.current + 1.day) expect(process.debate_phase.started?).to be true # past - process.update_attributes!(debate_start_date: Date.current - 2.days, - debate_end_date: Date.current - 1.day) + process.update!(debate_start_date: Date.current - 2.days, + debate_end_date: Date.current - 1.day) expect(process.debate_phase.started?).to be true end it "checks draft phase" do # future - process.update_attributes!(draft_start_date: Date.current + 2.days, - draft_end_date: Date.current + 3.days, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current + 2.days, + draft_end_date: Date.current + 3.days, draft_phase_enabled: true) expect(process.draft_phase.started?).to be false # started - process.update_attributes!(draft_start_date: Date.current - 2.days, - draft_end_date: Date.current + 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current - 2.days, + draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true # starts today - process.update_attributes!(draft_start_date: Date.current, - draft_end_date: Date.current + 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current, + draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true # past - process.update_attributes!(draft_start_date: Date.current - 2.days, - draft_end_date: Date.current - 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current - 2.days, + draft_end_date: Date.current - 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true end it "checks allegations phase" do # future - process.update_attributes!(allegations_start_date: Date.current + 2.days, - allegations_end_date: Date.current + 3.days) + process.update!(allegations_start_date: Date.current + 2.days, + allegations_end_date: Date.current + 3.days) expect(process.allegations_phase.started?).to be false # started - process.update_attributes!(allegations_start_date: Date.current - 2.days, - allegations_end_date: Date.current + 1.day) + process.update!(allegations_start_date: Date.current - 2.days, + allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.started?).to be true # starts today - process.update_attributes!(allegations_start_date: Date.current, - allegations_end_date: Date.current + 1.day) + process.update!(allegations_start_date: Date.current, + allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.started?).to be true # past - process.update_attributes!(allegations_start_date: Date.current - 2.days, - allegations_end_date: Date.current - 1.day) + process.update!(allegations_start_date: Date.current - 2.days, + allegations_end_date: Date.current - 1.day) expect(process.allegations_phase.started?).to be true end end @@ -99,68 +99,68 @@ RSpec.describe Legislation::Process::Phase, type: :model do describe "#open?" do it "checks debate phase" do # future - process.update_attributes!(debate_start_date: Date.current + 2.days, - debate_end_date: Date.current + 3.days) + process.update!(debate_start_date: Date.current + 2.days, + debate_end_date: Date.current + 3.days) expect(process.debate_phase.open?).to be false # started - process.update_attributes!(debate_start_date: Date.current - 2.days, - debate_end_date: Date.current + 1.day) + process.update!(debate_start_date: Date.current - 2.days, + debate_end_date: Date.current + 1.day) expect(process.debate_phase.open?).to be true # starts today - process.update_attributes!(debate_start_date: Date.current, - debate_end_date: Date.current + 1.day) + process.update!(debate_start_date: Date.current, + debate_end_date: Date.current + 1.day) expect(process.debate_phase.open?).to be true # past - process.update_attributes!(debate_start_date: Date.current - 2.days, - debate_end_date: Date.current - 1.day) + process.update!(debate_start_date: Date.current - 2.days, + debate_end_date: Date.current - 1.day) expect(process.debate_phase.open?).to be false end it "checks draft phase" do # future - process.update_attributes!(draft_start_date: Date.current + 2.days, - draft_end_date: Date.current + 3.days, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current + 2.days, + draft_end_date: Date.current + 3.days, draft_phase_enabled: true) expect(process.draft_phase.open?).to be false # started - process.update_attributes!(draft_start_date: Date.current - 2.days, - draft_end_date: Date.current + 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current - 2.days, + draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be true # starts today - process.update_attributes!(draft_start_date: Date.current, - draft_end_date: Date.current + 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current, + draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be true # past - process.update_attributes!(draft_start_date: Date.current - 2.days, - draft_end_date: Date.current - 1.day, draft_phase_enabled: true) + process.update!(draft_start_date: Date.current - 2.days, + draft_end_date: Date.current - 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be false end it "checks allegations phase" do # future - process.update_attributes!(allegations_start_date: Date.current + 2.days, - allegations_end_date: Date.current + 3.days) + process.update!(allegations_start_date: Date.current + 2.days, + allegations_end_date: Date.current + 3.days) expect(process.allegations_phase.open?).to be false # started - process.update_attributes!(allegations_start_date: Date.current - 2.days, - allegations_end_date: Date.current + 1.day) + process.update!(allegations_start_date: Date.current - 2.days, + allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.open?).to be true # starts today - process.update_attributes!(allegations_start_date: Date.current, - allegations_end_date: Date.current + 1.day) + process.update!(allegations_start_date: Date.current, + allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.open?).to be true # past - process.update_attributes!(allegations_start_date: Date.current - 2.days, - allegations_end_date: Date.current - 1.day) + process.update!(allegations_start_date: Date.current - 2.days, + allegations_end_date: Date.current - 1.day) expect(process.allegations_phase.open?).to be false end end diff --git a/spec/models/legislation/process/publication_spec.rb b/spec/models/legislation/process/publication_spec.rb index e09eb2f1c..3a347b962 100644 --- a/spec/models/legislation/process/publication_spec.rb +++ b/spec/models/legislation/process/publication_spec.rb @@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Publication, type: :model do it "checks draft publication" do expect(process.draft_publication.enabled?).to be true - process.update_attributes!(draft_publication_enabled: false) + process.update!(draft_publication_enabled: false) expect(process.draft_publication.enabled?).to be false end it "checks result publication" do expect(process.result_publication.enabled?).to be true - process.update_attributes!(result_publication_enabled: false) + process.update!(result_publication_enabled: false) expect(process.result_publication.enabled?).to be false end end @@ -22,29 +22,29 @@ RSpec.describe Legislation::Process::Publication, type: :model do describe "#started?" do it "checks draft publication" do # future - process.update_attributes!(draft_publication_date: Date.current + 2.days) + process.update!(draft_publication_date: Date.current + 2.days) expect(process.draft_publication.started?).to be false # past - process.update_attributes!(draft_publication_date: Date.current - 2.days) + process.update!(draft_publication_date: Date.current - 2.days) expect(process.draft_publication.started?).to be true # starts today - process.update_attributes!(draft_publication_date: Date.current) + process.update!(draft_publication_date: Date.current) expect(process.draft_publication.started?).to be true end it "checks result publication" do # future - process.update_attributes!(result_publication_date: Date.current + 2.days) + process.update!(result_publication_date: Date.current + 2.days) expect(process.result_publication.started?).to be false # past - process.update_attributes!(result_publication_date: Date.current - 2.days) + process.update!(result_publication_date: Date.current - 2.days) expect(process.result_publication.started?).to be true # starts today - process.update_attributes!(result_publication_date: Date.current) + process.update!(result_publication_date: Date.current) expect(process.result_publication.started?).to be true end end @@ -52,29 +52,29 @@ RSpec.describe Legislation::Process::Publication, type: :model do describe "#open?" do it "checks draft publication" do # future - process.update_attributes!(draft_publication_date: Date.current + 2.days) + process.update!(draft_publication_date: Date.current + 2.days) expect(process.draft_publication.open?).to be false # past - process.update_attributes!(draft_publication_date: Date.current - 2.days) + process.update!(draft_publication_date: Date.current - 2.days) expect(process.draft_publication.open?).to be true # starts today - process.update_attributes!(draft_publication_date: Date.current) + process.update!(draft_publication_date: Date.current) expect(process.draft_publication.open?).to be true end it "checks result publication" do # future - process.update_attributes!(result_publication_date: Date.current + 2.days) + process.update!(result_publication_date: Date.current + 2.days) expect(process.result_publication.open?).to be false # past - process.update_attributes!(result_publication_date: Date.current - 2.days) + process.update!(result_publication_date: Date.current - 2.days) expect(process.result_publication.open?).to be true # starts today - process.update_attributes!(result_publication_date: Date.current) + process.update!(result_publication_date: Date.current) expect(process.result_publication.open?).to be true end end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index ce4600981..75401b762 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -162,12 +162,12 @@ describe Legislation::Process do describe "#status" do it "detects planned phase" do - process.update_attributes!(start_date: Date.current + 2.days) + process.update!(start_date: Date.current + 2.days) expect(process.status).to eq(:planned) end it "detects closed phase" do - process.update_attributes!(end_date: Date.current - 2.days) + process.update!(end_date: Date.current - 2.days) expect(process.status).to eq(:closed) end