Swap @investment instance variable for a let

Why:

Avoid instance variables as we agreed upon with RSpec/InstanceVariable

How:

Using a let(:invsetment) and replacing all `@investment` with
`investment`, as well as adding a let(:admin) for the administrator.
This commit is contained in:
Bertocq
2018-03-06 11:11:16 +01:00
parent 9abf9bd87d
commit 400b3b1201

View File

@@ -220,17 +220,19 @@ feature 'Valuation budget investments' do
end end
feature 'Valuate' do feature 'Valuate' do
let(:admin) { create(:administrator) }
let(:investment) do
create(:budget_investment, budget: budget, price: nil,
administrator: admin)
end
background do background do
@investment = create(:budget_investment, investment.valuators << valuator
budget: budget,
price: nil,
administrator: create(:administrator))
@investment.valuators << valuator
end end
scenario 'Dossier empty by default' do scenario 'Dossier empty by default' do
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
click_link @investment.title click_link investment.title
within('#price') { expect(page).to have_content('Undefined') } within('#price') { expect(page).to have_content('Undefined') }
within('#price_first_year') { expect(page).to have_content('Undefined') } within('#price_first_year') { expect(page).to have_content('Undefined') }
@@ -241,7 +243,7 @@ feature 'Valuation budget investments' do
scenario 'Edit dossier' do scenario 'Edit dossier' do
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
within("#budget_investment_#{@investment.id}") do within("#budget_investment_#{investment.id}") do
click_link "Edit dossier" click_link "Edit dossier"
end end
@@ -255,7 +257,7 @@ feature 'Valuation budget investments' do
expect(page).to have_content "Dossier updated" expect(page).to have_content "Dossier updated"
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
click_link @investment.title click_link investment.title
within('#price') { expect(page).to have_content('12345') } within('#price') { expect(page).to have_content('12345') }
within('#price_first_year') { expect(page).to have_content('9876') } within('#price_first_year') { expect(page).to have_content('9876') }
@@ -266,14 +268,14 @@ feature 'Valuation budget investments' do
end end
scenario 'Feasibility can be marked as pending' do scenario 'Feasibility can be marked as pending' do
visit valuation_budget_budget_investment_path(budget, @investment) visit valuation_budget_budget_investment_path(budget, investment)
click_link 'Edit dossier' click_link 'Edit dossier'
expect(find("#budget_investment_feasibility_undecided")).to be_checked expect(find("#budget_investment_feasibility_undecided")).to be_checked
choose 'budget_investment_feasibility_feasible' choose 'budget_investment_feasibility_feasible'
click_button 'Save changes' click_button 'Save changes'
visit edit_valuation_budget_budget_investment_path(budget, @investment) visit edit_valuation_budget_budget_investment_path(budget, investment)
expect(find("#budget_investment_feasibility_undecided")).not_to be_checked expect(find("#budget_investment_feasibility_undecided")).not_to be_checked
expect(find("#budget_investment_feasibility_feasible")).to be_checked expect(find("#budget_investment_feasibility_feasible")).to be_checked
@@ -281,7 +283,7 @@ feature 'Valuation budget investments' do
choose 'budget_investment_feasibility_undecided' choose 'budget_investment_feasibility_undecided'
click_button 'Save changes' click_button 'Save changes'
visit edit_valuation_budget_budget_investment_path(budget, @investment) visit edit_valuation_budget_budget_investment_path(budget, investment)
expect(find("#budget_investment_feasibility_undecided")).to be_checked expect(find("#budget_investment_feasibility_undecided")).to be_checked
end end
@@ -291,7 +293,7 @@ feature 'Valuation budget investments' do
any_feasibility_fields = ['Valuation finished'] any_feasibility_fields = ['Valuation finished']
undecided_fields = feasible_fields + unfeasible_fields + any_feasibility_fields undecided_fields = feasible_fields + unfeasible_fields + any_feasibility_fields
visit edit_valuation_budget_budget_investment_path(budget, @investment) visit edit_valuation_budget_budget_investment_path(budget, investment)
expect(find("#budget_investment_feasibility_undecided")).to be_checked expect(find("#budget_investment_feasibility_undecided")).to be_checked
@@ -321,7 +323,7 @@ feature 'Valuation budget investments' do
click_button 'Save changes' click_button 'Save changes'
visit edit_valuation_budget_budget_investment_path(budget, @investment) visit edit_valuation_budget_budget_investment_path(budget, investment)
expect(find("#budget_investment_feasibility_unfeasible")).to be_checked expect(find("#budget_investment_feasibility_unfeasible")).to be_checked
feasible_fields.each do |field| feasible_fields.each do |field|
@@ -340,24 +342,24 @@ feature 'Valuation budget investments' do
end end
scenario 'Finish valuation' do scenario 'Finish valuation' do
visit valuation_budget_budget_investment_path(budget, @investment) visit valuation_budget_budget_investment_path(budget, investment)
click_link 'Edit dossier' click_link 'Edit dossier'
find_field('budget_investment[valuation_finished]').click find_field('budget_investment[valuation_finished]').click
click_button 'Save changes' click_button 'Save changes'
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_content @investment.title expect(page).not_to have_content investment.title
click_link 'Valuation finished' click_link 'Valuation finished'
expect(page).to have_content @investment.title expect(page).to have_content investment.title
click_link @investment.title click_link investment.title
expect(page).to have_content('Valuation finished') expect(page).to have_content('Valuation finished')
end end
scenario 'Validates price formats' do scenario 'Validates price formats' do
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
within("#budget_investment_#{@investment.id}") do within("#budget_investment_#{investment.id}") do
click_link "Edit dossier" click_link "Edit dossier"
end end