From 3471cbb97977e0a65a894256db11ef089bd04445 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 12 Feb 2019 11:17:57 +0100 Subject: [PATCH] Fix hound warnings --- spec/features/budgets/votes_spec.rb | 112 ++++++++++++++++------------ spec/models/user_spec.rb | 59 +++++++-------- 2 files changed, 92 insertions(+), 79 deletions(-) diff --git a/spec/features/budgets/votes_spec.rb b/spec/features/budgets/votes_spec.rb index d91ad1aa7..8513ec420 100644 --- a/spec/features/budgets/votes_spec.rb +++ b/spec/features/budgets/votes_spec.rb @@ -1,72 +1,70 @@ -require 'rails_helper' +require "rails_helper" -feature 'Votes' do - - background do - @manuela = create(:user, verified_at: Time.current) - end - - feature 'Investments' do +feature "Votes" do + feature "Investments" do + let(:manuela) { create(:user, verified_at: Time.current) } let(:budget) { create(:budget, phase: "selecting") } let(:group) { create(:budget_group, budget: budget) } let(:heading) { create(:budget_heading, group: group) } - background { login_as(@manuela) } + background { login_as(manuela) } - feature 'Index' do + feature "Index" do scenario "Index shows user votes on proposals" do investment1 = create(:budget_investment, heading: heading) investment2 = create(:budget_investment, heading: heading) investment3 = create(:budget_investment, heading: heading) - create(:vote, voter: @manuela, votable: investment1, vote_flag: true) + create(:vote, voter: manuela, votable: investment1, vote_flag: true) visit budget_investments_path(budget, heading_id: heading.id) within("#budget-investments") do within("#budget_investment_#{investment1.id}_votes") do - expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "You have already supported this investment project. "\ + "Share it!" end within("#budget_investment_#{investment2.id}_votes") do - expect(page).not_to have_content "You have already supported this investment project. Share it!" + expect(page).not_to have_content "You have already supported this investment project. "\ + "Share it!" end within("#budget_investment_#{investment3.id}_votes") do - expect(page).not_to have_content "You have already supported this investment project. Share it!" + expect(page).not_to have_content "You have already supported this investment project. "\ + "Share it!" end end end - scenario 'Create from spending proposal index', :js do - investment = create(:budget_investment, heading: heading, budget: budget) + scenario "Create from spending proposal index", :js do + create(:budget_investment, heading: heading, budget: budget) visit budget_investments_path(budget, heading_id: heading.id) - within('.supports') do + within(".supports") do find(".in-favor a").click expect(page).to have_content "1 support" - expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "You have already supported this investment project. "\ + "Share it!" end end end - feature 'Single spending proposal' do - background do - @investment = create(:budget_investment, budget: budget, heading: heading) - end + feature "Single spending proposal" do + let(:investment) { create(:budget_investment, budget: budget, heading: heading)} - scenario 'Show no votes' do - visit budget_investment_path(budget, @investment) + scenario "Show no votes" do + visit budget_investment_path(budget, investment) expect(page).to have_content "No supports" end - scenario 'Trying to vote multiple times', :js do - visit budget_investment_path(budget, @investment) + scenario "Trying to vote multiple times", :js do + visit budget_investment_path(budget, investment) - within('.supports') do + within(".supports") do find(".in-favor a").click expect(page).to have_content "1 support" @@ -74,20 +72,24 @@ feature 'Votes' do end end - scenario 'Create from proposal show', :js do - visit budget_investment_path(budget, @investment) + scenario "Create from proposal show", :js do + visit budget_investment_path(budget, investment) - within('.supports') do + within(".supports") do find(".in-favor a").click expect(page).to have_content "1 support" - expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "You have already supported this investment project. "\ + "Share it!" end end end - scenario 'Disable voting on spending proposals', :js do - login_as(@manuela) + scenario "Disable voting on spending proposals", :js do + manuela = create(:user, verified_at: Time.current) + + login_as(manuela) + budget.update(phase: "reviewing") investment = create(:budget_investment, budget: budget, heading: heading) @@ -122,59 +124,71 @@ feature 'Votes' do visit budget_investments_path(budget, heading_id: new_york.id) within("#budget_investment_#{new_york_investment.id}") do - accept_confirm { find('.in-favor a').click } + accept_confirm { find(".in-favor a").click } expect(page).to have_content "1 support" - expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "You have already supported this investment project. "\ + "Share it!" end visit budget_investments_path(budget, heading_id: san_francisco.id) within("#budget_investment_#{san_francisco_investment.id}") do - find('.in-favor a').click + find(".in-favor a").click expect(page).to have_content "1 support" - expect(page).to have_content "You have already supported this investment project. Share it!" + expect(page).to have_content "You have already supported this investment project. "\ + "Share it!" end visit budget_investments_path(budget, heading_id: third_heading.id) within("#budget_investment_#{third_heading_investment.id}") do - find('.in-favor a').click + find(".in-favor a").click - expect(page).to have_content "You can only support investment projects in 2 districts. You have already supported investments in" + expect(page).to have_content "You can only support investment projects in 2 districts. "\ + "You have already supported investments in" - heading_names = find('.participation-not-allowed').text.match(/You have already supported investments in (.+) and (.+)\./)&.captures - expect(heading_names).to match_array [new_york.name, san_francisco.name] + participation = find(".participation-not-allowed") + headings = participation.text + .match(/You have already supported investments in (.+) and (.+)\./)&.captures + + expect(headings).to match_array [new_york.name, san_francisco.name] expect(page).not_to have_content "1 support" - expect(page).not_to have_content "You have already supported this investment project. Share it!" + expect(page).not_to have_content "You have already supported this investment project. "\ + "Share it!" end end scenario "From show", :js do visit budget_investment_path(budget, new_york_investment) - accept_confirm { find('.in-favor a').click } + accept_confirm { find(".in-favor a").click } expect(page).to have_content "1 support" expect(page).to have_content "You have already supported this investment project. Share it!" visit budget_investment_path(budget, san_francisco_investment) - find('.in-favor a').click + find(".in-favor a").click expect(page).to have_content "1 support" expect(page).to have_content "You have already supported this investment project. Share it!" visit budget_investment_path(budget, third_heading_investment) - find('.in-favor a').click - expect(page).to have_content "You can only support investment projects in 2 districts. You have already supported investments in" + find(".in-favor a").click + expect(page).to have_content "You can only support investment projects in 2 districts. "\ + "You have already supported investments in" - heading_names = find('.participation-not-allowed').text.match(/You have already supported investments in (.+) and (.+)\./)&.captures - expect(heading_names).to match_array [new_york.name, san_francisco.name] + participation = find(".participation-not-allowed") + headings = participation.text + .match(/You have already supported investments in (.+) and (.+)\./)&.captures + + expect(headings).to match_array [new_york.name, san_francisco.name] expect(page).not_to have_content "1 support" - expect(page).not_to have_content "You have already supported this investment project. Share it!" + expect(page).not_to have_content "You have already supported this investment project. "\ + "Share it!" end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d32b8fa17..3e835de7e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,8 +1,8 @@ -require 'rails_helper' +require "rails_helper" describe User do - describe '#headings_voted_within_group' do + describe "#headings_voted_within_group" do it "returns the headings voted by a user" do user1 = create(:user) user2 = create(:user) @@ -16,18 +16,17 @@ describe User do new_york_investment = create(:budget_investment, heading: new_york) san_franciso_investment = create(:budget_investment, heading: san_franciso) - another_investment = create(:budget_investment, heading: san_franciso) create(:vote, votable: new_york_investment, voter: user1) create(:vote, votable: san_franciso_investment, voter: user1) expect(user1.headings_voted_within_group(group)).to include(new_york) expect(user1.headings_voted_within_group(group)).to include(san_franciso) - expect(user1.headings_voted_within_group(group)).to_not include(another_heading) + expect(user1.headings_voted_within_group(group)).not_to include(another_heading) - expect(user2.headings_voted_within_group(group)).to_not include(new_york) - expect(user2.headings_voted_within_group(group)).to_not include(san_franciso) - expect(user2.headings_voted_within_group(group)).to_not include(another_heading) + expect(user2.headings_voted_within_group(group)).not_to include(new_york) + expect(user2.headings_voted_within_group(group)).not_to include(san_franciso) + expect(user2.headings_voted_within_group(group)).not_to include(another_heading) end end @@ -101,39 +100,39 @@ describe User do end end - describe 'preferences' do - describe 'email_on_comment' do - it 'is false by default' do + describe "preferences" do + describe "email_on_comment" do + it "is false by default" do expect(subject.email_on_comment).to eq(false) end end - describe 'email_on_comment_reply' do - it 'is false by default' do + describe "email_on_comment_reply" do + it "is false by default" do expect(subject.email_on_comment_reply).to eq(false) end end - describe 'subscription_to_website_newsletter' do - it 'is true by default' do + describe "subscription_to_website_newsletter" do + it "is true by default" do expect(subject.newsletter).to eq(true) end end - describe 'email_digest' do - it 'is true by default' do + describe "email_digest" do + it "is true by default" do expect(subject.email_digest).to eq(true) end end - describe 'email_on_direct_message' do - it 'is true by default' do + describe "email_on_direct_message" do + it "is true by default" do expect(subject.email_on_direct_message).to eq(true) end end - describe 'official_position_badge' do - it 'is false by default' do + describe "official_position_badge" do + it "is false by default" do expect(subject.official_position_badge).to eq(false) end end @@ -204,7 +203,7 @@ describe User do expect(subject.organization?).to be false end - describe 'when it is an organization' do + describe "when it is an organization" do before { create(:organization, user: subject) } it "is true when the user is an organization" do @@ -222,7 +221,7 @@ describe User do expect(subject).not_to be_verified_organization end - describe 'when it is an organization' do + describe "when it is an organization" do before { create(:organization, user: subject) } it "is false when the user is not a verified organization" do @@ -237,12 +236,12 @@ describe User do end describe "organization_attributes" do - before { subject.organization_attributes = {name: 'org', responsible_name: 'julia'} } + before { subject.organization_attributes = {name: "org", responsible_name: "julia"} } it "triggers the creation of an associated organization" do expect(subject.organization).to be - expect(subject.organization.name).to eq('org') - expect(subject.organization.responsible_name).to eq('julia') + expect(subject.organization.name).to eq("org") + expect(subject.organization.responsible_name).to eq("julia") end it "deactivates the validation of username, and activates the validation of organization" do @@ -321,7 +320,7 @@ describe User do # We will use empleados.madrid.es as the officials' domain # Subdomains are also accepted - Setting['email_domain_for_officials'] = 'officials.madrid.es' + Setting["email_domain_for_officials"] = "officials.madrid.es" user1 = create(:user, email: "john@officials.madrid.es", confirmed_at: Time.current) user2 = create(:user, email: "john@yes.officials.madrid.es", confirmed_at: Time.current) user3 = create(:user, email: "john@unofficials.madrid.es", confirmed_at: Time.current) @@ -333,7 +332,7 @@ describe User do expect(user4.has_official_email?).to eq(false) # We reset the officials' domain setting - Setting.find_by(key: 'email_domain_for_officials').update(value: '') + Setting.find_by(key: "email_domain_for_officials").update(value: "") end end @@ -490,10 +489,10 @@ describe User do reset_password_token: "token2", email_verification_token: "token3") - user.erase('a test') + user.erase("a test") user.reload - expect(user.erase_reason).to eq('a test') + expect(user.erase_reason).to eq("a test") expect(user.erased_at).to be expect(user.username).to be_nil @@ -524,7 +523,7 @@ describe User do user = create(:user) identity = create(:identity, user: user) - user.erase('an identity test') + user.erase("an identity test") expect(Identity.exists?(identity.id)).not_to be end