Skip to content

Commit

Permalink
Directly assign valuator groups in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
javierm committed Sep 30, 2019
1 parent 7d5b0e9 commit 427cec1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
12 changes: 4 additions & 8 deletions spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@
admin = create(:administrator, user: create(:user, username: "Gema"))

budget_investment1 = create(:budget_investment, budget: budget, valuators: [valuator1])
budget_investment2 = create(:budget_investment, budget: budget, valuators: [valuator1, valuator2])
budget_investment2 = create(:budget_investment, budget: budget, valuators: [valuator1, valuator2],
valuator_groups: [valuator_group])
budget_investment3 = create(:budget_investment, budget: budget)

budget_investment2.valuator_groups << valuator_group

visit admin_budget_budget_investments_path(budget_id: budget.id)

within("#budget_investment_#{budget_investment1.id}") do
Expand Down Expand Up @@ -241,11 +240,8 @@
health_group = create(:valuator_group, name: "Health")
culture_group = create(:valuator_group, name: "Culture")

budget_investment1 = create(:budget_investment, title: "Build a hospital", budget: budget)
budget_investment1.valuator_groups << health_group

budget_investment2 = create(:budget_investment, title: "Build a theatre", budget: budget)
budget_investment2.valuator_groups << culture_group
create(:budget_investment, title: "Build a hospital", budget: budget, valuator_groups: [health_group])
create(:budget_investment, title: "Build a theatre", budget: budget, valuator_groups: [culture_group])

visit admin_budget_budget_investments_path(budget_id: budget)
expect(page).to have_link("Build a hospital")
Expand Down
2 changes: 1 addition & 1 deletion spec/features/valuation/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
create(:budget_investment, :unfeasible, budget: budget, price: 1234,
unfeasibility_explanation: "It is impossible",
administrator: administrator,
valuators: [valuator, second_valuator] )
valuators: [valuator, second_valuator])
end

scenario "visible for assigned valuators" do
Expand Down
9 changes: 2 additions & 7 deletions spec/models/abilities/valuator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
subject(:ability) { Ability.new(user) }

let(:user) { valuator.user }
let(:valuator) { create(:valuator) }
let(:group) { create(:valuator_group) }
let(:valuator) { create(:valuator, valuator_group: group) }
let(:non_assigned_investment) { create(:budget_investment) }
let(:assigned_investment) { create(:budget_investment, budget: create(:budget, :valuating), valuators: [valuator]) }
let(:group_assigned_investment) { create(:budget_investment, budget: create(:budget, :valuating)) }
let(:group_assigned_investment) { create(:budget_investment, budget: create(:budget, :valuating), valuator_groups: [group]) }
let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, :finished), valuators: [valuator]) }

before do
group_assigned_investment.valuator_groups << group
valuator.update(valuator_group: group)
end

it "cannot valuate an assigned investment with a finished valuation" do
assigned_investment.update(valuation_finished: true)

Expand Down
7 changes: 2 additions & 5 deletions spec/models/budget/investment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,8 @@

it "returns all investments with assigned valuator groups but valuation not finished" do
investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment3 = create(:budget_investment, :finished)

investment2.valuator_groups << create(:valuator_group)
investment3.valuator_groups << create(:valuator_group)
investment2 = create(:budget_investment, valuator_groups: [create(:valuator_group)])
investment3 = create(:budget_investment, :finished, valuator_groups: [create(:valuator_group)])

valuating = Budget::Investment.valuating

Expand Down
7 changes: 2 additions & 5 deletions spec/models/valuator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
group = create(:valuator_group)
valuator = create(:valuator, valuator_group: group)

investment1 = create(:budget_investment)
investment2 = create(:budget_investment)
investment1 = create(:budget_investment, valuator_groups: [group])
investment2 = create(:budget_investment, valuator_groups: [group])
investment3 = create(:budget_investment)

investment1.valuator_groups << group
investment2.valuator_groups << group

assigned_investment_ids = valuator.assigned_investment_ids

expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
Expand Down

0 comments on commit 427cec1

Please sign in to comment.