diff --git a/.rubocop.yml b/.rubocop.yml index 820308375..3adbb08eb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -117,4 +117,7 @@ RSpec/LeadingSubject: Enabled: true RSpec/LetBeforeExamples: + Enabled: true + +RSpec/LetSetup: Enabled: true \ No newline at end of file diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index 62b74d321..224566f20 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -11,7 +11,9 @@ feature 'Results' do let!(:investment3) { create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) } let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 600, ballot_lines_count: 600) } - let!(:results) { Budget::Result.new(budget, heading).calculate_winners } + background do + Budget::Result.new(budget, heading).calculate_winners + end scenario "Diplays winner investments" do create(:budget_heading, group: group) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index 7e530c620..1792f1058 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -375,7 +375,7 @@ feature 'Emails' do login_as(author) visit new_budget_investment_path(budget_id: budget.id) - select 'Health: More hospitals', from: 'budget_investment_heading_id' + select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id' fill_in 'budget_investment_title', with: 'Build a hospital' fill_in 'budget_investment_description', with: 'We have lots of people that require medical attention' fill_in 'budget_investment_external_url', with: 'http://http://hospitalsforallthepeople.com/' diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index aee0ff522..2f062df7d 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -5,8 +5,11 @@ feature "Voter" do context "Origin" do let(:poll) { create(:poll, :current) } + let(:question) { create(:poll_question, poll: poll) } let(:booth) { create(:poll_booth) } let(:officer) { create(:poll_officer) } + let!(:answer_yes) { create(:poll_question_answer, question: question, title: 'Yes') } + let!(:answer_no) { create(:poll_question_answer, question: question, title: 'No') } background do create(:geozone, :in_census) @@ -16,20 +19,14 @@ feature "Voter" do end scenario "Voting via web - Standard", :js do - poll = create(:poll) - - question = create(:poll_question, poll: poll) - answer1 = create(:poll_question_answer, question: question, title: 'Yes') - answer2 = create(:poll_question_answer, question: question, title: 'No') - user = create(:user, :level_two) login_as user visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - click_link 'Yes' - expect(page).to_not have_link('Yes') + click_link answer_yes.title + expect(page).to_not have_link(answer_yes.title) end find(:css, ".js-token-message").should be_visible @@ -42,20 +39,14 @@ feature "Voter" do end scenario "Voting via web as unverified user", :js do - poll = create(:poll) - - question = create(:poll_question, poll: poll) - answer1 = create(:poll_question_answer, question: question, title: 'Yes') - answer2 = create(:poll_question_answer, question: question, title: 'No') - user = create(:user, :incomplete_verification) login_as user visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - expect(page).to_not have_link('Yes', href: "/questions/#{question.id}/answer?answer=Yes&token=") - expect(page).to_not have_link('No', href: "/questions/#{question.id}/answer?answer=No&token=") + expect(page).to_not have_link(answer_yes.title, href: "/questions/#{question.id}/answer?answer=#{answer_yes.title}&token=") + expect(page).to_not have_link(answer_no.title, href: "/questions/#{question.id}/answer?answer=#{answer_no.title}&token=") end expect(page).to have_content("You must verify your account in order to answer") @@ -85,17 +76,14 @@ feature "Voter" do context "Trying to vote the same poll in booth and web" do - let(:poll) { create(:poll) } - - let(:question) { create(:poll_question, poll: poll) } - let!(:answer1) { create(:poll_question_answer, question: question, title: 'Yes') } - let!(:answer2) { create(:poll_question_answer, question: question, title: 'No') } - let!(:user) { create(:user, :in_census) } + background do + end + scenario "Trying to vote in web and then in booth", :js do login_as user - vote_for_poll_via_web(poll, question, 'Yes') + vote_for_poll_via_web(poll, question, answer_yes.title) expect(Poll::Voter.count).to eq(1) click_link "Sign out" @@ -121,14 +109,14 @@ feature "Voter" do login_as user visit poll_path(poll) - expect(page).to_not have_link('Yes') + expect(page).to_not have_link(answer_yes.title) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) end scenario "Trying to vote in web again", :js do login_as user - vote_for_poll_via_web(poll, question, 'Yes') + vote_for_poll_via_web(poll, question, answer_yes.title) expect(Poll::Voter.count).to eq(1) visit poll_path(poll) @@ -137,7 +125,7 @@ feature "Voter" do expect(page).to have_content "You have already participated in this poll. If you vote again it will be overwritten." within("#poll_question_#{question.id}_answers") do - expect(page).to_not have_link('Yes') + expect(page).to_not have_link(answer_yes.title) end click_link "Sign out" @@ -146,8 +134,8 @@ feature "Voter" do visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - expect(page).to have_link('Yes') - expect(page).to have_link('No') + expect(page).to have_link(answer_yes.title) + expect(page).to have_link(answer_no.title) end end end @@ -155,10 +143,6 @@ feature "Voter" do scenario "Voting in poll and then verifiying account", :js do user = create(:user) - question = create(:poll_question, poll: poll) - answer1 = create(:poll_question_answer, question: question, title: 'Yes') - answer2 = create(:poll_question_answer, question: question, title: 'No') - login_through_form_as_officer(officer.user) vote_for_poll_via_booth @@ -174,7 +158,7 @@ feature "Voter" do visit poll_path(poll) - expect(page).to_not have_link('Yes') + expect(page).to_not have_link(answer_yes.title) expect(page).to have_content "You have already participated in a physical booth. You can not participate again." expect(Poll::Voter.count).to eq(1) end diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index fe1eed0e1..43edc9c36 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -6,19 +6,21 @@ feature 'Tags' do let(:budget) { create(:budget, name: "Big Budget") } let(:group) { create(:budget_group, name: "Health", budget: budget) } let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) } + let!(:tag_medio_ambiente) { create(:tag, :category, name: 'Medio Ambiente') } + let!(:tag_economia) { create(:tag, :category, name: 'Economía') } scenario 'Index' do - earth = create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') - money = create(:budget_investment, heading: heading, tag_list: 'Economía') + earth = create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) + money = create(:budget_investment, heading: heading, tag_list: tag_economia.name) visit budget_investments_path(budget, heading_id: heading.id) within "#budget_investment_#{earth.id}" do - expect(page).to have_content "Medio Ambiente" + expect(page).to have_content(tag_medio_ambiente.name) end within "#budget_investment_#{money.id}" do - expect(page).to have_content "Economía" + expect(page).to have_content(tag_economia.name) end end @@ -49,12 +51,12 @@ feature 'Tags' do end scenario 'Show' do - investment = create(:budget_investment, heading: heading, tag_list: 'Hacienda, Economía') + investment = create(:budget_investment, heading: heading, tag_list: "#{tag_medio_ambiente.name}, #{tag_economia.name}") visit budget_investment_path(budget, investment) - expect(page).to have_content "Economía" - expect(page).to have_content "Hacienda" + expect(page).to have_content(tag_medio_ambiente.name) + expect(page).to have_content(tag_economia.name) end scenario 'Create with custom tags' do @@ -62,41 +64,38 @@ feature 'Tags' do visit new_budget_investment_path(budget_id: budget.id) - select 'Health: More hospitals', from: 'budget_investment_heading_id' + select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id' fill_in 'budget_investment_title', with: 'Build a skyscraper' fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds' check 'budget_investment_terms_of_service' - fill_in 'budget_investment_tag_list', with: 'Economía, Hacienda' + fill_in 'budget_investment_tag_list', with: "#{tag_medio_ambiente.name}, #{tag_economia.name}" click_button 'Create Investment' expect(page).to have_content 'Investment created successfully.' - expect(page).to have_content 'Economía' - expect(page).to have_content 'Hacienda' + expect(page).to have_content tag_economia.name + expect(page).to have_content tag_medio_ambiente.name end scenario 'Category with category tags', :js do login_as(author) - education = create(:tag, :category, name: 'Education') - health = create(:tag, :category, name: 'Health') - visit new_budget_investment_path(budget_id: budget.id) - select 'Health: More hospitals', from: 'budget_investment_heading_id' + select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id' fill_in 'budget_investment_title', with: 'Build a skyscraper' fill_in_ckeditor 'budget_investment_description', with: 'If I had a gym near my place I could go do Zumba' check 'budget_investment_terms_of_service' - find('.js-add-tag-link', text: 'Education').click + find('.js-add-tag-link', text: tag_economia.name).click click_button 'Create Investment' expect(page).to have_content 'Investment created successfully.' within "#tags_budget_investment_#{Budget::Investment.last.id}" do - expect(page).to have_content 'Education' - expect(page).to_not have_content 'Health' + expect(page).to have_content tag_economia.name + expect(page).to_not have_content tag_medio_ambiente.name end end @@ -105,7 +104,7 @@ feature 'Tags' do visit new_budget_investment_path(budget_id: budget.id) - select 'Health: More hospitals', from: 'budget_investment_heading_id' + select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id' fill_in 'budget_investment_title', with: 'Build a skyscraper' fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds' check 'budget_investment_terms_of_service' @@ -123,7 +122,7 @@ feature 'Tags' do visit new_budget_investment_path(budget_id: budget.id) - select 'Health: More hospitals', from: 'budget_investment_heading_id' + select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id' fill_in 'budget_investment_title', with: 'Build a skyscraper' fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds' check 'budget_investment_terms_of_service' @@ -143,13 +142,13 @@ feature 'Tags' do scenario "From index" do - investment1 = create(:budget_investment, heading: heading, tag_list: 'Education') + investment1 = create(:budget_investment, heading: heading, tag_list: tag_economia.name) investment2 = create(:budget_investment, heading: heading, tag_list: 'Health') visit budget_investments_path(budget, heading_id: heading.id) within "#budget_investment_#{investment1.id}" do - click_link "Education" + click_link tag_economia.name end within("#budget-investments") do @@ -159,12 +158,12 @@ feature 'Tags' do end scenario "From show" do - investment1 = create(:budget_investment, heading: heading, tag_list: 'Education') + investment1 = create(:budget_investment, heading: heading, tag_list: tag_economia.name) investment2 = create(:budget_investment, heading: heading, tag_list: 'Health') visit budget_investment_path(budget, investment1) - click_link "Education" + click_link tag_economia.name within("#budget-investments") do expect(page).to have_css('.budget-investment', count: 1) @@ -176,9 +175,11 @@ feature 'Tags' do context 'Tag cloud' do - let!(:investment1) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } - let!(:investment2) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } - let!(:investment3) { create(:budget_investment, heading: heading, tag_list: 'Economía') } + let(:new_tag) { "New Tag" } + let(:newer_tag) { "Newer" } + let!(:investment1) { create(:budget_investment, heading: heading, tag_list: new_tag) } + let!(:investment2) { create(:budget_investment, heading: heading, tag_list: new_tag) } + let!(:investment3) { create(:budget_investment, heading: heading, tag_list: newer_tag) } scenario 'Display user tags' do Budget::PHASES.each do |phase| @@ -187,8 +188,8 @@ feature 'Tags' do visit budget_investments_path(budget, heading_id: heading.id) within "#tag-cloud" do - expect(page).to have_content "Medio Ambiente" - expect(page).to have_content "Economía" + expect(page).to have_content(new_tag) + expect(page).to have_content(newer_tag) end end end @@ -207,7 +208,7 @@ feature 'Tags' do click_link group.name within "#tag-cloud" do - click_link "Medio Ambiente" + click_link new_tag end expect(page).to have_css ".budget-investment", count: 2 @@ -221,12 +222,9 @@ feature 'Tags' do context "Categories" do - let!(:tag1) { create(:tag, :category, name: 'Medio Ambiente') } - let!(:tag2) { create(:tag, :category, name: 'Economía') } - - let!(:investment1) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } - let!(:investment2) { create(:budget_investment, heading: heading, tag_list: 'Medio Ambiente') } - let!(:investment3) { create(:budget_investment, heading: heading, tag_list: 'Economía') } + let!(:investment1) { create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) } + let!(:investment2) { create(:budget_investment, heading: heading, tag_list: tag_medio_ambiente.name) } + let!(:investment3) { create(:budget_investment, heading: heading, tag_list: tag_economia.name) } scenario 'Display category tags' do Budget::PHASES.each do |phase| @@ -235,8 +233,8 @@ feature 'Tags' do visit budget_investments_path(budget, heading_id: heading.id) within "#categories" do - expect(page).to have_content "Medio Ambiente" - expect(page).to have_content "Economía" + expect(page).to have_content(tag_medio_ambiente.name) + expect(page).to have_content(tag_economia.name) end end end @@ -255,7 +253,7 @@ feature 'Tags' do click_link group.name within "#categories" do - click_link "Medio Ambiente" + click_link tag_medio_ambiente.name end expect(page).to have_css ".budget-investment", count: 2 @@ -295,4 +293,4 @@ feature 'Tags' do end end -end \ No newline at end of file +end diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb index 7e797eac6..424b09b60 100644 --- a/spec/shared/features/documentable.rb +++ b/spec/shared/features/documentable.rb @@ -1,10 +1,11 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, documentable_path_arguments| include ActionView::Helpers - let!(:administrator) { create(:user) } - let!(:user) { create(:user) } - let!(:arguments) { {} } - let!(:documentable) { create(documentable_factory_name, author: user) } + let(:administrator) { create(:user) } + let(:user) { create(:user) } + let(:arguments) { {} } + let(:documentable) { create(documentable_factory_name, author: user) } + let!(:document) { create(:document, documentable: documentable, user: documentable.author) } before do create(:administrator, user: administrator) @@ -16,8 +17,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, context "Show documents tab" do - let!(:document) { create(:document, documentable: documentable, user: documentable.author)} - scenario "Download action should be able to anyone" do visit send(documentable_path, arguments) @@ -76,8 +75,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, context "Destroy" do - let!(:document) { create(:document, documentable: documentable, user: documentable.author) } - scenario "Should show success notice after successfull document upload" do login_as documentable.author diff --git a/spec/shared/features/imageable.rb b/spec/shared/features/imageable.rb index 418d971c2..b9f5bf7d8 100644 --- a/spec/shared/features/imageable.rb +++ b/spec/shared/features/imageable.rb @@ -40,7 +40,9 @@ shared_examples "imageable" do |imageable_factory_name, imageable_path, imageabl context "Destroy" do - let!(:image) { create(:image, imageable: imageable, user: imageable.author) } + background do + create(:image, imageable: imageable, user: imageable.author) + end scenario "Should show success notice after successfull deletion by an admin" do login_as administrator diff --git a/spec/shared/features/mappable.rb b/spec/shared/features/mappable.rb index 77da67145..6e1cca64b 100644 --- a/spec/shared/features/mappable.rb +++ b/spec/shared/features/mappable.rb @@ -2,7 +2,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, include ActionView::Helpers - let!(:user) { create(:user, :level_two) } + let!(:user) { create(:user, :level_two) } + let!(:arguments) { {} } + let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } + let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } before do Setting['feature.map'] = true @@ -10,10 +13,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_new_path}" do - let!(:arguments) { {} } - let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } - let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } - before { set_arguments(arguments, mappable, mappable_path_arguments) } scenario "Should not show marker by default on create #{mappable_factory_name}", :js do @@ -113,9 +112,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_edit_path}" do - let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } - let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } - before { skip } if mappable_edit_path.blank? scenario "Should edit map on #{mappable_factory_name} and contain default values", :js do @@ -200,10 +196,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name, describe "At #{mappable_show_path}" do - let!(:arguments) { {} } - let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } - let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } - before { set_arguments(arguments, mappable, mappable_path_arguments) } scenario "Should display map on #{mappable_factory_name} show page", :js do