Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.
There are a few methods I've kept the same way they were.
The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.
We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").
Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.
There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.
For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
This commit is contained in:
@@ -13,7 +13,7 @@ describe Abilities::Valuator do
|
||||
let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, :finished), valuators: [valuator]) }
|
||||
|
||||
it "cannot valuate an assigned investment with a finished valuation" do
|
||||
assigned_investment.update(valuation_finished: true)
|
||||
assigned_investment.update!(valuation_finished: true)
|
||||
|
||||
should_not be_able_to(:valuate, assigned_investment)
|
||||
end
|
||||
|
||||
@@ -81,7 +81,7 @@ describe AdminNotification do
|
||||
before do
|
||||
2.times { create(:user) }
|
||||
erased_user.erase
|
||||
admin_notification.update(segment_recipient: "all_users")
|
||||
admin_notification.update!(segment_recipient: "all_users")
|
||||
end
|
||||
|
||||
it "returns list of all active users" do
|
||||
|
||||
@@ -20,24 +20,24 @@ describe Budget::Ballot::Line do
|
||||
|
||||
describe "Money" do
|
||||
it "is not valid if insufficient funds" do
|
||||
investment.update(price: heading.price + 1)
|
||||
investment.update!(price: heading.price + 1)
|
||||
expect(ballot_line).not_to be_valid
|
||||
end
|
||||
|
||||
it "is valid if sufficient funds" do
|
||||
investment.update(price: heading.price - 1)
|
||||
investment.update!(price: heading.price - 1)
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "Selectibility" do
|
||||
it "is not valid if investment is unselected" do
|
||||
investment.update(selected: false)
|
||||
investment.update!(selected: false)
|
||||
expect(ballot_line).not_to be_valid
|
||||
end
|
||||
|
||||
it "is valid if investment is selected" do
|
||||
investment.update(selected: true, price: 20000)
|
||||
investment.update!(selected: true, price: 20000)
|
||||
expect(ballot_line).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,13 +19,13 @@ describe Budget::Group do
|
||||
end
|
||||
|
||||
it "may be repeated for the same group and a different locale" do
|
||||
group.update(name_fr: "object name")
|
||||
group.update!(name_fr: "object name")
|
||||
|
||||
expect(group.translations.last).to be_valid
|
||||
end
|
||||
|
||||
it "must not be repeated for a different group in any locale" do
|
||||
group.update(name_en: "English", name_es: "Español")
|
||||
group.update!(name_en: "English", name_es: "Español")
|
||||
|
||||
expect(build(:budget_group, budget: budget, name_en: "English")).not_to be_valid
|
||||
expect(build(:budget_group, budget: budget, name_en: "Español")).not_to be_valid
|
||||
|
||||
@@ -40,13 +40,13 @@ describe Budget::Heading do
|
||||
end
|
||||
|
||||
it "can be repeated for the same heading and a different locale" do
|
||||
heading.update(name_fr: "object name")
|
||||
heading.update!(name_fr: "object name")
|
||||
|
||||
expect(heading.translations.last).to be_valid
|
||||
end
|
||||
|
||||
it "must not be repeated for a different heading in any locale" do
|
||||
heading.update(name_en: "English", name_es: "Español")
|
||||
heading.update!(name_en: "English", name_es: "Español")
|
||||
|
||||
expect(build(:budget_heading, group: group, name_en: "English")).not_to be_valid
|
||||
expect(build(:budget_heading, group: group, name_en: "Español")).not_to be_valid
|
||||
|
||||
@@ -50,7 +50,7 @@ describe Budget::Investment do
|
||||
expect(investment.budget_id).to eq budget.id
|
||||
expect(investment.group_id).to eq group_1.id
|
||||
|
||||
investment.update(heading: heading_2)
|
||||
investment.update!(heading: heading_2)
|
||||
|
||||
expect(investment.budget_id).to eq budget.id
|
||||
expect(investment.group_id).to eq group_2.id
|
||||
@@ -68,7 +68,7 @@ describe Budget::Investment do
|
||||
|
||||
expect(investment.previous_heading_id).to eq nil
|
||||
|
||||
investment.update(heading: heading_2)
|
||||
investment.update!(heading: heading_2)
|
||||
|
||||
expect(investment.previous_heading_id).to eq heading_1.id
|
||||
end
|
||||
@@ -220,7 +220,7 @@ describe Budget::Investment do
|
||||
|
||||
it "returns true for selected investments which budget's phase is publishing_prices or later" do
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_price?).to eq(true)
|
||||
end
|
||||
@@ -228,7 +228,7 @@ describe Budget::Investment do
|
||||
|
||||
it "returns false in any other phase" do
|
||||
(Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_price?).to eq(false)
|
||||
end
|
||||
@@ -255,7 +255,7 @@ describe Budget::Investment do
|
||||
|
||||
it "returns true for selected with price_explanation & budget in publishing_prices or later" do
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_price_explanation?).to eq(true)
|
||||
end
|
||||
@@ -263,7 +263,7 @@ describe Budget::Investment do
|
||||
|
||||
it "returns false in any other phase" do
|
||||
(Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_price_explanation?).to eq(false)
|
||||
end
|
||||
@@ -290,25 +290,25 @@ describe Budget::Investment do
|
||||
|
||||
it "returns true for unfeasible investments with unfeasibility explanation and valuation finished" do
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_unfeasibility_explanation?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false in valuation has not finished" do
|
||||
investment.update(valuation_finished: false)
|
||||
investment.update!(valuation_finished: false)
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false if not unfeasible" do
|
||||
investment.update(feasibility: "undecided")
|
||||
investment.update!(feasibility: "undecided")
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
|
||||
end
|
||||
@@ -317,7 +317,7 @@ describe Budget::Investment do
|
||||
it "returns false if unfeasibility explanation blank" do
|
||||
investment.unfeasibility_explanation = ""
|
||||
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
|
||||
expect(investment.should_show_unfeasibility_explanation?).to eq(false)
|
||||
end
|
||||
@@ -703,7 +703,7 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
it "returns selected investments" do
|
||||
budget.update(phase: "balloting")
|
||||
budget.update!(phase: "balloting")
|
||||
|
||||
investment1 = create(:budget_investment, :feasible, :selected, budget: budget)
|
||||
investment2 = create(:budget_investment, :feasible, :selected, budget: budget)
|
||||
@@ -717,7 +717,7 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
it "returns unselected investments" do
|
||||
budget.update(phase: "balloting")
|
||||
budget.update!(phase: "balloting")
|
||||
|
||||
investment1 = create(:budget_investment, :feasible, :unselected, budget: budget)
|
||||
investment2 = create(:budget_investment, :feasible, :unselected, budget: budget)
|
||||
@@ -855,7 +855,7 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
it "accepts votes in multiple headings of the same group" do
|
||||
group.update(max_votable_headings: 2)
|
||||
group.update!(max_votable_headings: 2)
|
||||
carabanchel = create(:budget_heading, group: group)
|
||||
salamanca = create(:budget_heading, group: group)
|
||||
|
||||
@@ -867,7 +867,7 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
it "accepts votes in any heading previously voted in" do
|
||||
group.update(max_votable_headings: 2)
|
||||
group.update!(max_votable_headings: 2)
|
||||
|
||||
carabanchel = create(:budget_heading, group: group)
|
||||
salamanca = create(:budget_heading, group: group)
|
||||
@@ -927,7 +927,7 @@ describe Budget::Investment do
|
||||
let(:latina_investment) { create(:budget_investment, heading: latina) }
|
||||
|
||||
it "returns true if the user has voted in less headings than the maximum" do
|
||||
districts.update(max_votable_headings: 2)
|
||||
districts.update!(max_votable_headings: 2)
|
||||
|
||||
create(:vote, votable: carabanchel_investment, voter: user)
|
||||
|
||||
@@ -935,7 +935,7 @@ describe Budget::Investment do
|
||||
end
|
||||
|
||||
it "returns false if the user has already voted in the maximum number of headings" do
|
||||
districts.update(max_votable_headings: 2)
|
||||
districts.update!(max_votable_headings: 2)
|
||||
|
||||
create(:vote, votable: carabanchel_investment, voter: user)
|
||||
create(:vote, votable: salamanca_investment, voter: user)
|
||||
@@ -997,7 +997,7 @@ describe Budget::Investment do
|
||||
|
||||
it "does not get updated if the user is erased" do
|
||||
user.erase
|
||||
user.update(document_number: nil)
|
||||
user.update!(document_number: nil)
|
||||
expect(user.document_number).to be_blank
|
||||
investment.touch
|
||||
expect(investment.responsible_name).to eq("123456")
|
||||
@@ -1127,7 +1127,7 @@ describe Budget::Investment do
|
||||
|
||||
it "returns false if budget is not balloting phase" do
|
||||
Budget::Phase::PHASE_KINDS.reject { |phase| phase == "balloting" }.each do |phase|
|
||||
budget.update(phase: phase)
|
||||
budget.update!(phase: phase)
|
||||
investment = create(:budget_investment, budget: budget)
|
||||
|
||||
investment.heading = heading2
|
||||
@@ -1147,7 +1147,7 @@ describe Budget::Investment do
|
||||
expect(investment.previous_heading_id).to eq(nil)
|
||||
|
||||
investment.heading = heading2
|
||||
investment.save
|
||||
investment.save!
|
||||
|
||||
investment.reload
|
||||
expect(investment.heading_id).to eq(heading2.id)
|
||||
@@ -1205,7 +1205,7 @@ describe Budget::Investment do
|
||||
expect(investment.ballot_lines_count).to eq(3)
|
||||
|
||||
investment.heading = heading2
|
||||
investment.save
|
||||
investment.save!
|
||||
investment.reload
|
||||
|
||||
expect(investment.ballot_lines_count).to eq(0)
|
||||
@@ -1219,7 +1219,7 @@ describe Budget::Investment do
|
||||
|
||||
expect(investment.ballot_lines_count).to eq(3)
|
||||
|
||||
investment.save
|
||||
investment.save!
|
||||
investment.reload
|
||||
|
||||
expect(investment.ballot_lines_count).to eq(3)
|
||||
|
||||
@@ -64,7 +64,7 @@ describe Budget::Result do
|
||||
create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600)
|
||||
create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500)
|
||||
|
||||
wrong_win.update(incompatible: true)
|
||||
wrong_win.update!(incompatible: true)
|
||||
|
||||
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([800, 700, 600])
|
||||
end
|
||||
@@ -79,7 +79,7 @@ describe Budget::Result do
|
||||
create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600)
|
||||
create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500)
|
||||
|
||||
miss.update(incompatible: false)
|
||||
miss.update!(incompatible: false)
|
||||
|
||||
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700])
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ describe Budget do
|
||||
end
|
||||
|
||||
it "may be repeated for the same budget and a different locale" do
|
||||
budget.update(name_fr: "object name")
|
||||
budget.update!(name_fr: "object name")
|
||||
expect(budget.translations.last).to be_valid
|
||||
end
|
||||
end
|
||||
@@ -45,7 +45,7 @@ describe Budget do
|
||||
before do
|
||||
budget.phases.each do |phase|
|
||||
phase.description = phase.kind.humanize
|
||||
phase.save
|
||||
phase.save!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -273,28 +273,28 @@ describe Budget do
|
||||
|
||||
describe "#formatted_amount" do
|
||||
it "correctly formats Euros with Spanish" do
|
||||
budget.update(currency_symbol: "€")
|
||||
budget.update!(currency_symbol: "€")
|
||||
I18n.locale = :es
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 €"
|
||||
end
|
||||
|
||||
it "correctly formats Dollars with Spanish" do
|
||||
budget.update(currency_symbol: "$")
|
||||
budget.update!(currency_symbol: "$")
|
||||
I18n.locale = :es
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "1.000 $"
|
||||
end
|
||||
|
||||
it "correctly formats Dollars with English" do
|
||||
budget.update(currency_symbol: "$")
|
||||
budget.update!(currency_symbol: "$")
|
||||
I18n.locale = :en
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "$1,000"
|
||||
end
|
||||
|
||||
it "correctly formats Euros with English" do
|
||||
budget.update(currency_symbol: "€")
|
||||
budget.update!(currency_symbol: "€")
|
||||
I18n.locale = :en
|
||||
|
||||
expect(budget.formatted_amount(1000.00)).to eq "€1,000"
|
||||
@@ -314,7 +314,7 @@ describe Budget do
|
||||
|
||||
it "returns array of investments milestone_tags" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
investment1.save!
|
||||
budget.investments << investment1
|
||||
|
||||
expect(budget.milestone_tags).to eq(["tag1"])
|
||||
@@ -322,9 +322,9 @@ describe Budget do
|
||||
|
||||
it "returns uniq list of investments milestone_tags" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
investment1.save!
|
||||
investment2.milestone_tag_list = "tag1"
|
||||
investment2.save
|
||||
investment2.save!
|
||||
budget.investments << investment1
|
||||
budget.investments << investment2
|
||||
|
||||
@@ -333,9 +333,9 @@ describe Budget do
|
||||
|
||||
it "returns tags only for winner investments" do
|
||||
investment1.milestone_tag_list = "tag1"
|
||||
investment1.save
|
||||
investment1.save!
|
||||
investment3.milestone_tag_list = "tag2"
|
||||
investment3.save
|
||||
investment3.save!
|
||||
budget.investments << investment1
|
||||
budget.investments << investment3
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
record.update_attribute(attribute, "In English")
|
||||
|
||||
I18n.with_locale(:es) do
|
||||
record.update(required_fields.map { |field| [field, "En español"] }.to_h)
|
||||
record.update!(required_fields.map { |field| [field, "En español"] }.to_h)
|
||||
record.update_attribute(attribute, "En español")
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
|
||||
describe "Add a translation" do
|
||||
it "Maintains existing translations" do
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ locale: :fr }.merge(fields.map { |field| [field, "En Français"] }.to_h)
|
||||
])
|
||||
record.reload
|
||||
@@ -36,7 +36,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
end
|
||||
|
||||
it "Works with non-underscored locale name" do
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ locale: :"pt-BR" }.merge(fields.map { |field| [field, "Português"] }.to_h)
|
||||
])
|
||||
record.reload
|
||||
@@ -62,7 +62,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
record.translations.destroy_all
|
||||
record.reload
|
||||
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ locale: :de }.merge(fields.map { |field| [field, "Deutsch"] }.to_h)
|
||||
])
|
||||
|
||||
@@ -74,7 +74,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
|
||||
describe "Update a translation" do
|
||||
it "Changes the existing translation" do
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ id: record.translations.find_by(locale: :es).id, attribute => "Actualizado" }
|
||||
])
|
||||
record.reload
|
||||
@@ -98,10 +98,10 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
end
|
||||
|
||||
it "Does not automatically add a translation for the current locale" do
|
||||
record.translations.find_by(locale: :en).destroy
|
||||
record.translations.find_by(locale: :en).destroy!
|
||||
record.reload
|
||||
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ id: record.translations.first.id }.merge(fields.map { |field| [field, "Cambiado"] }.to_h)
|
||||
])
|
||||
|
||||
@@ -113,7 +113,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
|
||||
describe "Remove a translation" do
|
||||
it "Keeps the other languages" do
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ id: record.translations.find_by(locale: :en).id, _destroy: true }
|
||||
])
|
||||
record.reload
|
||||
@@ -155,7 +155,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
describe "Fallbacks" do
|
||||
before do
|
||||
I18n.with_locale(:de) do
|
||||
record.update(required_fields.map { |field| [field, "Deutsch"] }.to_h)
|
||||
record.update!(required_fields.map { |field| [field, "Deutsch"] }.to_h)
|
||||
record.update_attribute(attribute, "Deutsch")
|
||||
end
|
||||
end
|
||||
@@ -181,7 +181,7 @@ shared_examples_for "globalizable" do |factory_name|
|
||||
it "Falls back to the first available locale after removing a locale" do
|
||||
expect(record.send(attribute)).to eq "In English"
|
||||
|
||||
record.update(translations_attributes: [
|
||||
record.update!(translations_attributes: [
|
||||
{ id: record.translations.find_by(locale: :en).id, _destroy: true }
|
||||
])
|
||||
|
||||
|
||||
@@ -15,13 +15,13 @@ shared_examples "reportable" do
|
||||
end
|
||||
|
||||
it "can save the value to the database" do
|
||||
reportable.update(results_enabled: true)
|
||||
reportable.update!(results_enabled: true)
|
||||
saved_reportable = described_class.last
|
||||
|
||||
expect(saved_reportable.results_enabled?).to be true
|
||||
expect(saved_reportable.results_enabled).to be true
|
||||
|
||||
reportable.update(results_enabled: false)
|
||||
reportable.update!(results_enabled: false)
|
||||
saved_reportable = described_class.last
|
||||
|
||||
expect(saved_reportable.results_enabled?).to be false
|
||||
@@ -31,7 +31,7 @@ shared_examples "reportable" do
|
||||
it "uses the `has_one` relation instead of the original column" do
|
||||
skip "there's no original column" unless reportable.has_attribute?(:results_enabled)
|
||||
|
||||
reportable.update(results_enabled: true)
|
||||
reportable.update!(results_enabled: true)
|
||||
|
||||
expect(reportable.read_attribute(:results_enabled)).to be false
|
||||
end
|
||||
@@ -51,13 +51,13 @@ shared_examples "reportable" do
|
||||
end
|
||||
|
||||
it "can save the attribute to the database" do
|
||||
reportable.update(stats_enabled: true)
|
||||
reportable.update!(stats_enabled: true)
|
||||
saved_reportable = described_class.last
|
||||
|
||||
expect(saved_reportable.stats_enabled?).to be true
|
||||
expect(saved_reportable.stats_enabled).to be true
|
||||
|
||||
reportable.update(stats_enabled: false)
|
||||
reportable.update!(stats_enabled: false)
|
||||
saved_reportable = described_class.last
|
||||
|
||||
expect(saved_reportable.stats_enabled?).to be false
|
||||
@@ -67,7 +67,7 @@ shared_examples "reportable" do
|
||||
it "uses the `has_one` relation instead of the original column" do
|
||||
skip "there's no original column" unless reportable.has_attribute?(:stats_enabled)
|
||||
|
||||
reportable.update(stats_enabled: true)
|
||||
reportable.update!(stats_enabled: true)
|
||||
|
||||
expect(reportable.read_attribute(:stats_enabled)).to be false
|
||||
end
|
||||
|
||||
@@ -248,32 +248,32 @@ describe Dashboard::Action do
|
||||
|
||||
it "when there are not news actions actived for published proposals" do
|
||||
proposal = create(:proposal)
|
||||
action.update(published_proposal: true)
|
||||
resource.update(published_proposal: true)
|
||||
action.update!(published_proposal: true)
|
||||
resource.update!(published_proposal: true)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq []
|
||||
end
|
||||
|
||||
it "when there are news actions actived for draft_proposal but proposal is published" do
|
||||
proposal = create(:proposal)
|
||||
action.update(published_proposal: false, day_offset: 0)
|
||||
resource.update(published_proposal: false, day_offset: 0)
|
||||
action.update!(published_proposal: false, day_offset: 0)
|
||||
resource.update!(published_proposal: false, day_offset: 0)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq []
|
||||
end
|
||||
|
||||
it "when there are not news actions actived for draft proposals" do
|
||||
proposal = create(:proposal, :draft)
|
||||
action.update(published_proposal: false)
|
||||
resource.update(published_proposal: false)
|
||||
action.update!(published_proposal: false)
|
||||
resource.update!(published_proposal: false)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq []
|
||||
end
|
||||
|
||||
it "when there are news actions actived for published_proposal but proposal is draft" do
|
||||
proposal = create(:proposal, :draft)
|
||||
action.update(published_proposal: true, day_offset: 0)
|
||||
resource.update(published_proposal: true, day_offset: 0)
|
||||
action.update!(published_proposal: true, day_offset: 0)
|
||||
resource.update!(published_proposal: true, day_offset: 0)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq []
|
||||
end
|
||||
@@ -301,9 +301,9 @@ describe Dashboard::Action do
|
||||
end
|
||||
|
||||
it "when proposal has received a new vote today" do
|
||||
proposal.update(created_at: Date.yesterday, published_at: Date.yesterday)
|
||||
action.update(required_supports: 1)
|
||||
resource.update(required_supports: 0)
|
||||
proposal.update!(created_at: Date.yesterday, published_at: Date.yesterday)
|
||||
action.update!(required_supports: 1)
|
||||
resource.update!(required_supports: 0)
|
||||
create(:vote, voter: proposal.author, votable: proposal)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday,
|
||||
@@ -333,9 +333,9 @@ describe Dashboard::Action do
|
||||
end
|
||||
|
||||
it "when proposal has received a new vote today" do
|
||||
proposal.update(created_at: Date.yesterday)
|
||||
action.update(required_supports: 1)
|
||||
resource.update(required_supports: 2)
|
||||
proposal.update!(created_at: Date.yesterday)
|
||||
action.update!(required_supports: 1)
|
||||
resource.update!(required_supports: 2)
|
||||
create(:vote, voter: proposal.author, votable: proposal)
|
||||
|
||||
expect(Dashboard::Action.detect_new_actions_since(Date.yesterday,
|
||||
|
||||
@@ -133,19 +133,19 @@ describe Debate do
|
||||
end
|
||||
|
||||
it "is true for anonymous users if allowed anonymous votes" do
|
||||
debate.update(cached_anonymous_votes_total: 420, cached_votes_total: 1000)
|
||||
debate.update!(cached_anonymous_votes_total: 420, cached_votes_total: 1000)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be true
|
||||
end
|
||||
|
||||
it "is true for anonymous users if less than 100 votes" do
|
||||
debate.update(cached_anonymous_votes_total: 90, cached_votes_total: 92)
|
||||
debate.update!(cached_anonymous_votes_total: 90, cached_votes_total: 92)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be true
|
||||
end
|
||||
|
||||
it "is false for anonymous users if too many anonymous votes" do
|
||||
debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
|
||||
debate.update!(cached_anonymous_votes_total: 520, cached_votes_total: 1000)
|
||||
user = create(:user)
|
||||
expect(debate.votable_by?(user)).to be false
|
||||
end
|
||||
@@ -417,44 +417,44 @@ describe Debate do
|
||||
describe "conflictive debates" do
|
||||
|
||||
it "returns true when it has more than 1 flag for 5 positive votes" do
|
||||
debate.update(cached_votes_up: 4)
|
||||
debate.update(flags_count: 1)
|
||||
debate.update!(cached_votes_up: 4)
|
||||
debate.update!(flags_count: 1)
|
||||
expect(debate).to be_conflictive
|
||||
|
||||
debate.update(cached_votes_up: 9)
|
||||
debate.update(flags_count: 2)
|
||||
debate.update!(cached_votes_up: 9)
|
||||
debate.update!(flags_count: 2)
|
||||
expect(debate).to be_conflictive
|
||||
|
||||
debate.update(cached_votes_up: 14)
|
||||
debate.update(flags_count: 3)
|
||||
debate.update!(cached_votes_up: 14)
|
||||
debate.update!(flags_count: 3)
|
||||
expect(debate).to be_conflictive
|
||||
|
||||
debate.update(cached_votes_up: 2)
|
||||
debate.update(flags_count: 20)
|
||||
debate.update!(cached_votes_up: 2)
|
||||
debate.update!(flags_count: 20)
|
||||
expect(debate).to be_conflictive
|
||||
end
|
||||
|
||||
it "returns false when it has less than or equal to 1 flag for 5 positive votes" do
|
||||
debate.update(cached_votes_up: 5)
|
||||
debate.update(flags_count: 1)
|
||||
debate.update!(cached_votes_up: 5)
|
||||
debate.update!(flags_count: 1)
|
||||
expect(debate).not_to be_conflictive
|
||||
|
||||
debate.update(cached_votes_up: 10)
|
||||
debate.update(flags_count: 2)
|
||||
debate.update!(cached_votes_up: 10)
|
||||
debate.update!(flags_count: 2)
|
||||
expect(debate).not_to be_conflictive
|
||||
|
||||
debate.update(cached_votes_up: 100)
|
||||
debate.update(flags_count: 2)
|
||||
debate.update!(cached_votes_up: 100)
|
||||
debate.update!(flags_count: 2)
|
||||
expect(debate).not_to be_conflictive
|
||||
end
|
||||
|
||||
it "returns false when it has no flags" do
|
||||
debate.update(flags_count: 0)
|
||||
debate.update!(flags_count: 0)
|
||||
expect(debate).not_to be_conflictive
|
||||
end
|
||||
|
||||
it "returns false when it has not votes up" do
|
||||
debate.update(cached_votes_up: 0)
|
||||
debate.update!(cached_votes_up: 0)
|
||||
expect(debate).not_to be_conflictive
|
||||
end
|
||||
|
||||
|
||||
@@ -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_attributes!(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_attributes!(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_attributes!(allegations_phase_enabled: false)
|
||||
expect(process.allegations_phase.enabled?).to be false
|
||||
end
|
||||
end
|
||||
@@ -31,66 +31,66 @@ 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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(allegations_start_date: Date.current - 2.days,
|
||||
allegations_end_date: Date.current - 1.day)
|
||||
expect(process.allegations_phase.started?).to be true
|
||||
end
|
||||
@@ -99,44 +99,44 @@ 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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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
|
||||
@@ -144,22 +144,22 @@ RSpec.describe Legislation::Process::Phase, type: :model do
|
||||
it "checks allegations phase" do
|
||||
|
||||
# future
|
||||
process.update_attributes(allegations_start_date: Date.current + 2.days,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(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,
|
||||
process.update_attributes!(allegations_start_date: Date.current - 2.days,
|
||||
allegations_end_date: Date.current - 1.day)
|
||||
expect(process.allegations_phase.open?).to be false
|
||||
end
|
||||
|
||||
@@ -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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(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_attributes!(result_publication_date: Date.current)
|
||||
expect(process.result_publication.open?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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_attributes!(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_attributes!(end_date: Date.current - 2.days)
|
||||
expect(process.status).to eq(:closed)
|
||||
end
|
||||
|
||||
|
||||
@@ -19,15 +19,15 @@ describe Lock do
|
||||
describe "#lock_time" do
|
||||
it "increases exponentially with number of tries" do
|
||||
lock.tries = 5
|
||||
lock.save
|
||||
lock.save!
|
||||
expect(lock.reload.lock_time).to be_between(30.minutes.from_now, 35.minutes.from_now)
|
||||
|
||||
lock.tries = 10
|
||||
lock.save
|
||||
lock.save!
|
||||
expect(lock.reload.lock_time).to be_between(16.hours.from_now, 18.hours.from_now)
|
||||
|
||||
lock.tries = 15
|
||||
lock.save
|
||||
lock.save!
|
||||
expect(lock.reload.lock_time).to be_between(21.days.from_now, 23.days.from_now)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ describe Newsletter do
|
||||
create(:user, newsletter: true, email: "newsletter_user@consul.dev")
|
||||
create(:user, newsletter: false, email: "no_news_user@consul.dev")
|
||||
create(:user, email: "erased_user@consul.dev").erase
|
||||
newsletter.update(segment_recipient: "all_users")
|
||||
newsletter.update!(segment_recipient: "all_users")
|
||||
end
|
||||
|
||||
it "returns list of recipients excluding users with disabled newsletter" do
|
||||
|
||||
@@ -147,7 +147,7 @@ describe Notification do
|
||||
comment = create(:comment)
|
||||
|
||||
first_notification = Notification.add(user, comment)
|
||||
first_notification.update(read_at: Time.current)
|
||||
first_notification.update!(read_at: Time.current)
|
||||
|
||||
second_notification = Notification.add(user, comment)
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ describe Officing::Residence do
|
||||
describe "save" do
|
||||
|
||||
it "stores document number, document type, geozone, date of birth and gender" do
|
||||
residence.save
|
||||
residence.save!
|
||||
user = residence.user
|
||||
|
||||
expect(user.document_number).to eq("12345678Z")
|
||||
@@ -183,7 +183,7 @@ describe Officing::Residence do
|
||||
document_number: "12345678Z",
|
||||
document_type: "1")
|
||||
|
||||
residence.save
|
||||
residence.save!
|
||||
user = residence.user
|
||||
|
||||
expect(user.document_number).to eq("12345678Z")
|
||||
@@ -201,7 +201,7 @@ describe Officing::Residence do
|
||||
residence = build(:officing_residence, document_number: "12345678Z", year_of_birth: 1980)
|
||||
expect(residence).to be_valid
|
||||
expect(user.reload).to be_unverified
|
||||
residence.save
|
||||
residence.save!
|
||||
expect(user.reload).to be_level_three_verified
|
||||
end
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ describe Poll::BallotSheet do
|
||||
describe "#parsed_ballots" do
|
||||
it "splits ballots by ';' or '\n'" do
|
||||
data = "1,2,3;4,5,6\n7,8,9"
|
||||
ballot_sheet.update(data: data)
|
||||
ballot_sheet.update!(data: data)
|
||||
|
||||
expect(ballot_sheet.parsed_ballots).to eq(["1,2,3", "4,5,6", "7,8,9"])
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ describe Poll::Ballot do
|
||||
investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading)
|
||||
investment4 = create(:budget_investment, :selected, price: 2000000, heading: heading)
|
||||
|
||||
poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.verify
|
||||
|
||||
expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id]
|
||||
@@ -31,7 +31,7 @@ describe Poll::Ballot do
|
||||
investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading)
|
||||
investment4 = create(:budget_investment, :selected, price: 2000000, heading: other_heading)
|
||||
|
||||
poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.verify
|
||||
|
||||
expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id]
|
||||
@@ -42,7 +42,7 @@ describe Poll::Ballot do
|
||||
investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading)
|
||||
investment4 = create(:budget_investment, price: 2000000, heading: heading)
|
||||
|
||||
poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(","))
|
||||
poll_ballot.verify
|
||||
|
||||
expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id]
|
||||
@@ -54,12 +54,12 @@ describe Poll::Ballot do
|
||||
|
||||
describe "Money" do
|
||||
it "is not valid if insufficient funds" do
|
||||
investment.update(price: heading.price + 1)
|
||||
investment.update!(price: heading.price + 1)
|
||||
expect(poll_ballot.add_investment(investment.id)).to be(false)
|
||||
end
|
||||
|
||||
it "is valid if sufficient funds" do
|
||||
investment.update(price: heading.price - 1)
|
||||
investment.update!(price: heading.price - 1)
|
||||
expect(poll_ballot.add_investment(investment.id)).to be(true)
|
||||
end
|
||||
end
|
||||
@@ -85,12 +85,12 @@ describe Poll::Ballot do
|
||||
|
||||
describe "Selectibility" do
|
||||
it "is not valid if investment is unselected" do
|
||||
investment.update(selected: false)
|
||||
investment.update!(selected: false)
|
||||
expect(poll_ballot.add_investment(investment.id)).to be(false)
|
||||
end
|
||||
|
||||
it "is valid if investment is selected" do
|
||||
investment.update(selected: true, price: 20000)
|
||||
investment.update!(selected: true, price: 20000)
|
||||
expect(poll_ballot.add_investment(investment.id)).to be(true)
|
||||
end
|
||||
end
|
||||
@@ -98,7 +98,7 @@ describe Poll::Ballot do
|
||||
describe "Budget" do
|
||||
it "is not valid if investment belongs to a different budget" do
|
||||
other_budget = create(:budget)
|
||||
investment.update(budget: other_budget)
|
||||
investment.update!(budget: other_budget)
|
||||
expect(poll_ballot.add_investment(investment.id)).to be(nil)
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ describe Poll::BoothAssignment do
|
||||
create(:poll_officer_assignment, officer: officer, booth_assignment: assignment)
|
||||
create(:poll_shift, booth: booth, officer: officer)
|
||||
|
||||
assignment.destroy
|
||||
assignment.destroy!
|
||||
|
||||
expect(Poll::Shift.all.count).to eq(0)
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ describe Poll::Officer do
|
||||
end
|
||||
|
||||
it "returns 'User deleted' if user is deleted" do
|
||||
officer.user.destroy
|
||||
officer.user.destroy!
|
||||
|
||||
expect(officer.reload.name).to eq "User deleted"
|
||||
end
|
||||
@@ -24,7 +24,7 @@ describe Poll::Officer do
|
||||
end
|
||||
|
||||
it "returns 'Email deleted' if user is deleted" do
|
||||
officer.user.destroy
|
||||
officer.user.destroy!
|
||||
|
||||
expect(officer.reload.email).to eq "Email deleted"
|
||||
end
|
||||
|
||||
@@ -24,11 +24,11 @@ describe Poll::PartialResult do
|
||||
expect(partial_result.amount_log).to eq("")
|
||||
|
||||
partial_result.amount = 33
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
partial_result.amount = 32
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
partial_result.amount = 34
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
|
||||
expect(partial_result.amount_log).to eq(":33:32")
|
||||
end
|
||||
@@ -41,15 +41,15 @@ describe Poll::PartialResult do
|
||||
|
||||
partial_result.amount = 33
|
||||
partial_result.officer_assignment = create(:poll_officer_assignment, id: 10)
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
|
||||
partial_result.amount = 32
|
||||
partial_result.officer_assignment = create(:poll_officer_assignment, id: 20)
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
|
||||
partial_result.amount = 34
|
||||
partial_result.officer_assignment = create(:poll_officer_assignment, id: 30)
|
||||
partial_result.save
|
||||
partial_result.save!
|
||||
|
||||
expect(partial_result.amount_log).to eq(":33:32")
|
||||
expect(partial_result.officer_assignment_id_log).to eq(":10:20")
|
||||
|
||||
@@ -13,11 +13,11 @@ describe Poll::Recount do
|
||||
expect(poll_recount.white_amount_log).to eq("")
|
||||
|
||||
poll_recount.white_amount = 33
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.white_amount = 32
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.white_amount = 34
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
expect(poll_recount.white_amount_log).to eq(":0:33:32")
|
||||
end
|
||||
@@ -28,11 +28,11 @@ describe Poll::Recount do
|
||||
expect(poll_recount.null_amount_log).to eq("")
|
||||
|
||||
poll_recount.null_amount = 33
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.null_amount = 32
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.null_amount = 34
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
expect(poll_recount.null_amount_log).to eq(":0:33:32")
|
||||
end
|
||||
@@ -43,11 +43,11 @@ describe Poll::Recount do
|
||||
expect(poll_recount.total_amount_log).to eq("")
|
||||
|
||||
poll_recount.total_amount = 33
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.total_amount = 32
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
poll_recount.total_amount = 34
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
expect(poll_recount.total_amount_log).to eq(":0:33:32")
|
||||
end
|
||||
@@ -60,15 +60,15 @@ describe Poll::Recount do
|
||||
|
||||
poll_recount.white_amount = 33
|
||||
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 101)
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
poll_recount.white_amount = 32
|
||||
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 102)
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
poll_recount.white_amount = 34
|
||||
poll_recount.officer_assignment = create(:poll_officer_assignment, id: 103)
|
||||
poll_recount.save
|
||||
poll_recount.save!
|
||||
|
||||
expect(poll_recount.white_amount_log).to eq(":0:33:32")
|
||||
expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102")
|
||||
|
||||
@@ -35,19 +35,19 @@ describe Poll::Shift do
|
||||
end
|
||||
|
||||
it "is not valid with same booth, officer, date and task" do
|
||||
recount_shift.save
|
||||
recount_shift.save!
|
||||
|
||||
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).not_to be_valid
|
||||
end
|
||||
|
||||
it "is valid with same booth, officer and date but different task" do
|
||||
recount_shift.save
|
||||
recount_shift.save!
|
||||
|
||||
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with same booth, officer and task but different date" do
|
||||
recount_shift.save
|
||||
recount_shift.save!
|
||||
|
||||
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid
|
||||
end
|
||||
@@ -83,7 +83,7 @@ describe Poll::Shift do
|
||||
|
||||
it "creates final officer_assignments" do
|
||||
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
|
||||
recount_shift.save
|
||||
recount_shift.save!
|
||||
|
||||
officer_assignments = Poll::OfficerAssignment.all
|
||||
expect(officer_assignments.count).to eq(1)
|
||||
@@ -102,14 +102,14 @@ describe Poll::Shift do
|
||||
let(:shift) { create(:poll_shift, officer: officer, booth: booth) }
|
||||
|
||||
it "maintains officer data after destroying associated user" do
|
||||
shift.officer.user.destroy
|
||||
shift.officer.user.destroy!
|
||||
|
||||
expect(shift.officer_name).to eq "Ana"
|
||||
expect(shift.officer_email).to eq "ana@example.com"
|
||||
end
|
||||
|
||||
it "maintains officer data after destroying officer role" do
|
||||
shift.officer.destroy
|
||||
shift.officer.destroy!
|
||||
|
||||
expect(shift.officer_name).to eq "Ana"
|
||||
expect(shift.officer_email).to eq "ana@example.com"
|
||||
|
||||
@@ -155,13 +155,13 @@ describe Poll::Voter do
|
||||
|
||||
it "sets demographic info" do
|
||||
geozone = create(:geozone)
|
||||
user = create(:user,
|
||||
user = create(:user, :level_two,
|
||||
geozone: geozone,
|
||||
date_of_birth: 30.years.ago,
|
||||
gender: "female")
|
||||
|
||||
voter = build(:poll_voter, user: user)
|
||||
voter.save
|
||||
voter.save!
|
||||
|
||||
expect(voter.geozone).to eq(geozone)
|
||||
expect(voter.age).to eq(30)
|
||||
@@ -171,7 +171,7 @@ describe Poll::Voter do
|
||||
it "sets user info" do
|
||||
user = create(:user, document_number: "1234A", document_type: "1")
|
||||
voter = build(:poll_voter, user: user, token: "1234abcd")
|
||||
voter.save
|
||||
voter.save!
|
||||
|
||||
expect(voter.document_number).to eq("1234A")
|
||||
expect(voter.document_type).to eq("1")
|
||||
|
||||
@@ -70,7 +70,7 @@ describe ProgressBar do
|
||||
end
|
||||
|
||||
it "cannot have another primary progress bar for the same progressable" do
|
||||
progress_bar.save
|
||||
progress_bar.save!
|
||||
duplicate = build(:progress_bar, progressable: progress_bar.progressable)
|
||||
|
||||
expect(duplicate).not_to be_valid
|
||||
@@ -90,7 +90,7 @@ describe ProgressBar do
|
||||
end
|
||||
|
||||
it "can have another secondary progress bar for the same progressable" do
|
||||
progress_bar.save
|
||||
progress_bar.save!
|
||||
duplicate = build(:progress_bar, progressable: progress_bar.progressable)
|
||||
|
||||
expect(duplicate).to be_valid
|
||||
|
||||
@@ -110,7 +110,7 @@ describe ProposalNotification do
|
||||
it "returns false when the proposal is not available" do
|
||||
notification = create(:notification, notifiable: notifiable)
|
||||
|
||||
notifiable.proposal.destroy
|
||||
notifiable.proposal.destroy!
|
||||
|
||||
expect(notification.notifiable_available?).to be(false)
|
||||
end
|
||||
@@ -142,7 +142,7 @@ describe ProposalNotification do
|
||||
it "returns false if the resource is retired" do
|
||||
notification = create(:notification, notifiable: notifiable)
|
||||
|
||||
notifiable.proposal.update(retired_at: Time.current,
|
||||
notifiable.proposal.update!(retired_at: Time.current,
|
||||
retired_explanation: "Unfeasible reason explanation",
|
||||
retired_reason: "unfeasible")
|
||||
expect(notification.check_availability(proposal)).to be(false)
|
||||
|
||||
@@ -100,11 +100,11 @@ describe Proposal do
|
||||
it "is not updated when the author is deleted" do
|
||||
author = create(:user, :level_three, document_number: "12345678Z")
|
||||
proposal.author = author
|
||||
proposal.save
|
||||
proposal.save!
|
||||
|
||||
proposal.author.erase
|
||||
|
||||
proposal.save
|
||||
proposal.save!
|
||||
expect(proposal.responsible_name).to eq "12345678Z"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,64 +19,64 @@ describe Setting do
|
||||
|
||||
describe "#prefix" do
|
||||
it "returns the prefix of its key" do
|
||||
expect(Setting.create(key: "prefix.key_name").prefix).to eq "prefix"
|
||||
expect(Setting.create!(key: "prefix.key_name").prefix).to eq "prefix"
|
||||
end
|
||||
|
||||
it "returns the whole key for a non prefixed key" do
|
||||
expect(Setting.create(key: "key_name").prefix).to eq "key_name"
|
||||
expect(Setting.create!(key: "key_name").prefix).to eq "key_name"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#type" do
|
||||
it "returns the key prefix for 'process' settings" do
|
||||
process_setting = Setting.create(key: "process.whatever")
|
||||
process_setting = Setting.create!(key: "process.whatever")
|
||||
expect(process_setting.type).to eq "process"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'feature' settings" do
|
||||
feature_setting = Setting.create(key: "feature.whatever")
|
||||
feature_setting = Setting.create!(key: "feature.whatever")
|
||||
expect(feature_setting.type).to eq "feature"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'map' settings" do
|
||||
map_setting = Setting.create(key: "map.whatever")
|
||||
map_setting = Setting.create!(key: "map.whatever")
|
||||
expect(map_setting.type).to eq "map"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'html' settings" do
|
||||
html_setting = Setting.create(key: "html.whatever")
|
||||
html_setting = Setting.create!(key: "html.whatever")
|
||||
expect(html_setting.type).to eq "html"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'homepage' settings" do
|
||||
homepage_setting = Setting.create(key: "homepage.whatever")
|
||||
homepage_setting = Setting.create!(key: "homepage.whatever")
|
||||
expect(homepage_setting.type).to eq "homepage"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'remote_census.general' settings" do
|
||||
remote_census_general_setting = Setting.create(key: "remote_census.general.whatever")
|
||||
remote_census_general_setting = Setting.create!(key: "remote_census.general.whatever")
|
||||
expect(remote_census_general_setting.type).to eq "remote_census.general"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'remote_census_request' settings" do
|
||||
remote_census_request_setting = Setting.create(key: "remote_census.request.whatever")
|
||||
remote_census_request_setting = Setting.create!(key: "remote_census.request.whatever")
|
||||
expect(remote_census_request_setting.type).to eq "remote_census.request"
|
||||
end
|
||||
|
||||
it "returns the key prefix for 'remote_census_response' settings" do
|
||||
remote_census_response_setting = Setting.create(key: "remote_census.response.whatever")
|
||||
remote_census_response_setting = Setting.create!(key: "remote_census.response.whatever")
|
||||
expect(remote_census_response_setting.type).to eq "remote_census.response"
|
||||
end
|
||||
|
||||
it "returns 'configuration' for the rest of the settings" do
|
||||
configuration_setting = Setting.create(key: "whatever")
|
||||
configuration_setting = Setting.create!(key: "whatever")
|
||||
expect(configuration_setting.type).to eq "configuration"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#enabled?" do
|
||||
it "is true if value is present" do
|
||||
setting = Setting.create(key: "feature.whatever", value: 1)
|
||||
setting = Setting.create!(key: "feature.whatever", value: 1)
|
||||
expect(setting.enabled?).to eq true
|
||||
|
||||
setting.value = "true"
|
||||
@@ -87,7 +87,7 @@ describe Setting do
|
||||
end
|
||||
|
||||
it "is false if value is blank" do
|
||||
setting = Setting.create(key: "feature.whatever")
|
||||
setting = Setting.create!(key: "feature.whatever")
|
||||
expect(setting.enabled?).to eq false
|
||||
|
||||
setting.value = ""
|
||||
@@ -97,18 +97,18 @@ describe Setting do
|
||||
|
||||
describe "#content_type?" do
|
||||
it "returns true if the last part of the key is content_types" do
|
||||
expect(Setting.create(key: "key_name.content_types").content_type?).to be true
|
||||
expect(Setting.create!(key: "key_name.content_types").content_type?).to be true
|
||||
end
|
||||
|
||||
it "returns false if the last part of the key is not content_types" do
|
||||
expect(Setting.create(key: "key_name.whatever").content_type?).to be false
|
||||
expect(Setting.create!(key: "key_name.whatever").content_type?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#content_type_group" do
|
||||
it "returns the group for content_types settings" do
|
||||
images = Setting.create(key: "update.images.content_types")
|
||||
documents = Setting.create(key: "update.documents.content_types")
|
||||
images = Setting.create!(key: "update.images.content_types")
|
||||
documents = Setting.create!(key: "update.documents.content_types")
|
||||
|
||||
expect(images.content_type_group).to eq "images"
|
||||
expect(documents.content_type_group).to eq "documents"
|
||||
|
||||
@@ -8,7 +8,7 @@ describe Tag do
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
debate.update(hidden_at: Time.current)
|
||||
debate.update!(hidden_at: Time.current)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
@@ -20,7 +20,7 @@ describe Tag do
|
||||
|
||||
expect(tag.taggings_count).to eq(1)
|
||||
|
||||
proposal.update(hidden_at: Time.current)
|
||||
proposal.update!(hidden_at: Time.current)
|
||||
|
||||
tag.reload
|
||||
expect(tag.taggings_count).to eq(0)
|
||||
|
||||
@@ -148,7 +148,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true when the user is an admin" do
|
||||
subject.save
|
||||
subject.save!
|
||||
create(:administrator, user: subject)
|
||||
expect(subject.administrator?).to be true
|
||||
end
|
||||
@@ -160,7 +160,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true when the user is a moderator" do
|
||||
subject.save
|
||||
subject.save!
|
||||
create(:moderator, user: subject)
|
||||
expect(subject.moderator?).to be true
|
||||
end
|
||||
@@ -172,7 +172,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true when the user is a valuator" do
|
||||
subject.save
|
||||
subject.save!
|
||||
create(:valuator, user: subject)
|
||||
expect(subject.valuator?).to be true
|
||||
end
|
||||
@@ -184,7 +184,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true when the user is a manager" do
|
||||
subject.save
|
||||
subject.save!
|
||||
create(:manager, user: subject)
|
||||
expect(subject.manager?).to be true
|
||||
end
|
||||
@@ -196,7 +196,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true when the user is a poll officer" do
|
||||
subject.save
|
||||
subject.save!
|
||||
create(:poll_officer, user: subject)
|
||||
expect(subject.poll_officer?).to be true
|
||||
end
|
||||
@@ -265,14 +265,14 @@ describe User do
|
||||
|
||||
it "is true when the user is an official" do
|
||||
subject.official_level = 3
|
||||
subject.save
|
||||
subject.save!
|
||||
expect(subject.official?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_official_position!" do
|
||||
it "is false when level not valid" do
|
||||
expect(subject.add_official_position!("Boss", 89)).to be false
|
||||
it "raises an exception when level not valid" do
|
||||
expect { subject.add_official_position!("Boss", 89) }.to raise_error ActiveRecord::RecordInvalid
|
||||
end
|
||||
|
||||
it "updates official position fields" do
|
||||
@@ -336,7 +336,7 @@ describe User do
|
||||
expect(user4.has_official_email?).to eq(false)
|
||||
|
||||
# We reset the officials' domain setting
|
||||
Setting.find_by(key: "email_domain_for_officials").update(value: "")
|
||||
Setting.find_by(key: "email_domain_for_officials").update!(value: "")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ describe Verification::Letter do
|
||||
let(:letter) { build(:verification_letter, verify: true) }
|
||||
|
||||
it "incorrect code" do
|
||||
letter.user.update(letter_verification_code: "123456")
|
||||
letter.user.update!(letter_verification_code: "123456")
|
||||
letter.verification_code = "5555"
|
||||
|
||||
expect(letter.valid?).to eq(false)
|
||||
@@ -42,7 +42,7 @@ describe Verification::Letter do
|
||||
end
|
||||
|
||||
it "correct code" do
|
||||
letter.user.update(letter_verification_code: "123456")
|
||||
letter.user.update!(letter_verification_code: "123456")
|
||||
letter.verification_code = "123456"
|
||||
|
||||
expect(letter.valid?).to eq(true)
|
||||
@@ -50,7 +50,7 @@ describe Verification::Letter do
|
||||
end
|
||||
|
||||
it "ignores trailing zeros" do
|
||||
letter.user.update(letter_verification_code: "003456")
|
||||
letter.user.update!(letter_verification_code: "003456")
|
||||
letter.verification_code = "3456"
|
||||
|
||||
expect(letter.valid?).to eq(true)
|
||||
|
||||
@@ -36,7 +36,7 @@ describe Verification::Residence do
|
||||
it "validates uniquness of document_number" do
|
||||
user = create(:user)
|
||||
residence.user = user
|
||||
residence.save
|
||||
residence.save!
|
||||
|
||||
build(:verification_residence)
|
||||
|
||||
@@ -68,7 +68,7 @@ describe Verification::Residence do
|
||||
it "stores document number, document type, geozone, date of birth and gender" do
|
||||
user = create(:user)
|
||||
residence.user = user
|
||||
residence.save
|
||||
residence.save!
|
||||
|
||||
user.reload
|
||||
expect(user.document_number).to eq("12345678Z")
|
||||
|
||||
Reference in New Issue
Block a user