We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
36 lines
1.0 KiB
Ruby
36 lines
1.0 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Budget do
|
|
let(:run_rake_task) do
|
|
Rake::Task["budgets:set_original_heading_id"].reenable
|
|
Rake.application.invoke_task("budgets:set_original_heading_id")
|
|
end
|
|
|
|
it "sets attribute original_heading_id for existing investments" do
|
|
heading = create(:budget_heading)
|
|
investment = create(:budget_investment, heading: heading)
|
|
investment.update!(original_heading_id: nil)
|
|
|
|
expect(investment.original_heading_id).to equal(nil)
|
|
|
|
run_rake_task
|
|
investment.reload
|
|
|
|
expect(investment.original_heading_id).to equal(heading.id)
|
|
end
|
|
|
|
it "does not overwrite original_heading_id when already present" do
|
|
original_heading = create(:budget_heading)
|
|
new_heading = create(:budget_heading)
|
|
investment = create(:budget_investment, heading: original_heading)
|
|
investment.update!(heading: new_heading)
|
|
|
|
expect(investment.original_heading_id).to eq original_heading.id
|
|
|
|
run_rake_task
|
|
investment.reload
|
|
|
|
expect(investment.original_heading_id).to eq original_heading.id
|
|
end
|
|
end
|