Assigning a variable to each budget we declare results in useless assignments. We could just delete the three useless assignments and leave the fourth one, but I find the code easier to read if we use the name of the budgets to differenciate between them. This way we also keep the code vertically aligned.
20 lines
573 B
Ruby
20 lines
573 B
Ruby
require "rails_helper"
|
|
|
|
describe ApplicationController do
|
|
|
|
describe "#current_budget" do
|
|
|
|
it "returns the last budget that is not in draft phase" do
|
|
create(:budget, :finished, created_at: 2.years.ago, name: "Old")
|
|
create(:budget, :accepting, created_at: 1.year.ago, name: "Previous")
|
|
create(:budget, :accepting, created_at: 1.month.ago, name: "Current")
|
|
create(:budget, :drafting, created_at: 1.week.ago, name: "Next")
|
|
|
|
budget = subject.instance_eval { current_budget }
|
|
expect(budget.name).to eq("Current")
|
|
end
|
|
|
|
end
|
|
|
|
end
|