From 3f1d3f3443bf8350d74d03f550175af99553da92 Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 19 Mar 2019 18:24:49 +0100 Subject: [PATCH] Fix hound warnings --- app/models/dashboard/action.rb | 8 +-- spec/features/dashboard/dashboard_spec.rb | 87 ++++++++++++----------- spec/models/dashboard/action_spec.rb | 73 ++++++++++--------- 3 files changed, 86 insertions(+), 82 deletions(-) diff --git a/app/models/dashboard/action.rb b/app/models/dashboard/action.rb index 357bb1412..d0199acd1 100644 --- a/app/models/dashboard/action.rb +++ b/app/models/dashboard/action.rb @@ -13,7 +13,7 @@ class Dashboard::Action < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - has_many :executed_actions, dependent: :restrict_with_error, class_name: 'Dashboard::ExecutedAction' + has_many :executed_actions, dependent: :restrict_with_error, class_name: "Dashboard::ExecutedAction" has_many :proposals, through: :executed_actions enum action_type: [:proposed_action, :resource] @@ -50,15 +50,15 @@ class Dashboard::Action < ActiveRecord::Base def self.active_for(proposal) published_at = proposal.published_at&.to_date || Date.today - active.where('required_supports <= ?', proposal.cached_votes_up) - .where('day_offset <= ?', (Date.today - published_at).to_i) + active.where("required_supports <= ?", proposal.cached_votes_up) + .where("day_offset <= ?", (Date.today - published_at).to_i) .by_proposal(proposal) end def self.course_for(proposal) active .resources - .where('required_supports > ?', proposal.cached_votes_up) + .where("required_supports > ?", proposal.cached_votes_up) .order(required_supports: :asc) end diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 85bd04aaf..5c5aec5eb 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" feature "Proposal's dashboard" do let!(:proposal) { create(:proposal, :draft) } @@ -8,45 +8,47 @@ feature "Proposal's dashboard" do visit proposal_dashboard_path(proposal) end - scenario 'Dashboard has a link to my proposal' do - expect(page).to have_link('My proposal') + scenario "Dashboard has a link to my proposal" do + expect(page).to have_link("My proposal") end - scenario 'My proposal has a link to edit the proposal' do - expect(page).to have_link('Edit proposal') + scenario "My proposal has a link to edit the proposal" do + expect(page).to have_link("Edit proposal") end - scenario 'My proposal has a link to retire the proposal' do - expect(page).to have_link('Retire proposal') + scenario "My proposal has a link to retire the proposal" do + expect(page).to have_link("Retire proposal") end - scenario 'My proposal has a link to publish the proposal' do - expect(page).to have_link('Publish proposal') + scenario "My proposal has a link to publish the proposal" do + expect(page).to have_link("Publish proposal") end scenario "Publish link dissapears after proposal's publication" do - click_link 'Publish proposal' - expect(page).not_to have_link('Publish proposal') + click_link "Publish proposal" + expect(page).not_to have_link("Publish proposal") end - scenario 'Dashboard progress shows current goal', js: true do - goal = create(:dashboard_action, :resource, :active, required_supports: proposal.votes_for.size + 1_000) - future_goal = create(:dashboard_action, :resource, :active, required_supports: proposal.votes_for.size + 2_000) + scenario "Dashboard progress shows current goal", js: true do + goal = create(:dashboard_action, :resource, :active, + required_supports: proposal.votes_for.size + 1_000) + future_goal = create(:dashboard_action, :resource, :active, + required_supports: proposal.votes_for.size + 2_000) visit progress_proposal_dashboard_path(proposal) - within 'div#goals-section' do + within "div#goals-section" do expect(page).to have_content(goal.title) expect(page).not_to have_content(future_goal.title) - find(:css, '#see_complete_course_link').click + find(:css, "#see_complete_course_link").click expect(page).to have_content(goal.title) expect(page).to have_content(future_goal.title) end end - scenario 'Dashboard progress show proposed actions' do + scenario "Dashboard progress show proposed actions" do action = create(:dashboard_action, :proposed_action, :active) visit progress_proposal_dashboard_path(proposal) @@ -110,8 +112,7 @@ feature "Proposal's dashboard" do end end - scenario "Dashboard progress display contains no results text when there are not - proposed_actions pending" do + scenario "Display no results text when there are not proposed_actions done" do visit progress_proposal_dashboard_path(proposal) expect(page).to have_content("No recommended actions done") @@ -241,36 +242,36 @@ feature "Proposal's dashboard" do end end - scenario 'Dashboard has a link to polls feature' do - expect(page).to have_link('Polls') + scenario "Dashboard has a link to polls feature" do + expect(page).to have_link("Polls") end - scenario 'Dashboard has a link to e-mail feature' do - expect(page).to have_link('E-mail') + scenario "Dashboard has a link to e-mail feature" do + expect(page).to have_link("E-mail") end - scenario 'Dashboard has a link to poster feature' do - expect(page).to have_link('Poster') + scenario "Dashboard has a link to poster feature" do + expect(page).to have_link("Poster") end - scenario 'Dashboard has a link to resources on main menu' do + scenario "Dashboard has a link to resources on main menu" do feature = create(:dashboard_action, :resource, :active) visit proposal_dashboard_path(proposal) expect(page).to have_link(feature.title) end - scenario 'Request resource with admin request', js: true do + scenario "Request resource with admin request", js: true do feature = create(:dashboard_action, :resource, :active, :admin_request) visit proposal_dashboard_path(proposal) click_link(feature.title) - click_button 'Request' - expect(page).to have_content('The request for the administrator has been successfully sent.') + click_button "Request" + expect(page).to have_content("The request for the administrator has been successfully sent.") end - scenario 'Request already requested resource with admin request', js: true do + scenario "Request already requested resource with admin request", js: true do feature = create(:dashboard_action, :resource, :active, :admin_request) visit proposal_dashboard_path(proposal) @@ -278,27 +279,27 @@ feature "Proposal's dashboard" do create(:dashboard_executed_action, action: feature, proposal: proposal) - click_button 'Request' - expect(page).to have_content('Proposal has already been taken') + click_button "Request" + expect(page).to have_content("Proposal has already been taken") end - scenario 'Resource without admin request do not have a request link', js: true do + scenario "Resource without admin request do not have a request link", js: true do feature = create(:dashboard_action, :resource, :active) visit proposal_dashboard_path(proposal) click_link(feature.title) - expect(page).not_to have_button('Request') + expect(page).not_to have_button("Request") end - scenario 'Dashboard has a link to dashboard community', js: true do - expect(page).to have_link('Community') - click_link 'Community' + scenario "Dashboard has a link to dashboard community", js: true do + expect(page).to have_link("Community") + click_link "Community" - expect(page).to have_content('Participants') - expect(page).to have_content('Debates') - expect(page).to have_content('Comments') - expect(page).to have_link('Access the community') + expect(page).to have_content("Participants") + expect(page).to have_content("Debates") + expect(page).to have_content("Comments") + expect(page).to have_link("Access the community") end scenario "Dashboard has a link to recommended_actions", js: true do @@ -321,7 +322,7 @@ feature "Proposal's dashboard" do expect(page).to have_content(action_5.title) end - scenario "On recommended actions section do not display from the fourth proposed actions", js: true do + scenario "On recommended actions section display four proposed actions", js: true do create_list(:dashboard_action, 4, :proposed_action, :active) action_5 = create(:dashboard_action, :proposed_action, :active) @@ -359,7 +360,7 @@ feature "Proposal's dashboard" do end end - scenario "On recommended actions section contains no_results_text when there are + scenario "On recommended actions section contains no results text when there are not proposed_actions pending" do visit recommended_actions_proposal_dashboard_path(proposal.to_param) diff --git a/spec/models/dashboard/action_spec.rb b/spec/models/dashboard/action_spec.rb index 738282992..294e7ef99 100644 --- a/spec/models/dashboard/action_spec.rb +++ b/spec/models/dashboard/action_spec.rb @@ -16,88 +16,88 @@ describe Dashboard::Action do let(:day_offset) { 0 } let(:required_supports) { 0 } let(:request_to_administrators) { true } - let(:action_type) { 'resource' } + let(:action_type) { "resource" } - it 'is invalid when title is blank' do - action = build(:dashboard_action, title: '') + it "is invalid when title is blank" do + action = build(:dashboard_action, title: "") expect(action).not_to be_valid end - it 'is invalid when title is too short' do - action = build(:dashboard_action, title: 'abc') + it "is invalid when title is too short" do + action = build(:dashboard_action, title: "abc") expect(action).not_to be_valid end - it 'is invalid when title is too long' do - action = build(:dashboard_action, title: 'a' * 81) + it "is invalid when title is too long" do + action = build(:dashboard_action, title: "a" * 81) expect(action).not_to be_valid end - it 'is invalid when day_offset is not defined' do + it "is invalid when day_offset is not defined" do action = build(:dashboard_action, day_offset: nil) expect(action).not_to be_valid end - it 'is invalid when day_offset is negative' do + it "is invalid when day_offset is negative" do action = build(:dashboard_action, day_offset: -1) expect(action).not_to be_valid end - it 'is invalid when day_offset not an integer' do + it "is invalid when day_offset not an integer" do action = build(:dashboard_action, day_offset: 1.23) expect(action).not_to be_valid end - it 'is invalid when required_supports is nil' do + it "is invalid when required_supports is nil" do action = build(:dashboard_action, required_supports: nil) expect(action).not_to be_valid end - it 'is invalid when required_supports is negative' do + it "is invalid when required_supports is negative" do action = build(:dashboard_action, required_supports: -1) expect(action).not_to be_valid end - it 'is invalid when required_supports is not an integer' do + it "is invalid when required_supports is not an integer" do action = build(:dashboard_action, required_supports: 1.23) expect(action).not_to be_valid end - it 'is invalid when action_type is nil' do + it "is invalid when action_type is nil" do action = build(:dashboard_action, action_type: nil) expect(action).not_to be_valid end - context '#active_for?' do - it 'is active when required supports is 0 and day_offset is 0' do + context "#active_for?" do + it "is active when required supports is 0 and day_offset is 0" do action = build(:dashboard_action, required_supports: 0, day_offset: 0) proposal = build(:proposal) expect(action).to be_active_for(proposal) end - it 'is active when published after day_offset' do + it "is active when published after day_offset" do action = build(:dashboard_action, required_supports: 0, day_offset: 10) proposal = build(:proposal, published_at: Time.current - 10.days) expect(action).to be_active_for(proposal) end - it 'is active when have enough supports' do + it "is active when have enough supports" do action = build(:dashboard_action, required_supports: 10, day_offset: 0) proposal = build(:proposal, cached_votes_up: 10) expect(action).to be_active_for(proposal) end - it 'is not active when not enough time published' do + it "is not active when not enough time published" do action = build(:dashboard_action, required_supports: 0, day_offset: 10) proposal = build(:proposal, published_at: Time.current - 9.days) expect(action).not_to be_active_for(proposal) end - it 'is not active when not enough supports' do + it "is not active when not enough supports" do action = build(:dashboard_action, required_supports: 10, day_offset: 0) proposal = build(:proposal, cached_votes_up: 9) @@ -105,15 +105,15 @@ describe Dashboard::Action do end end - context '#requested_for?' do - it 'is not requested when no administrator task' do + context "#requested_for?" do + it "is not requested when no administrator task" do proposal = create(:proposal) action = create(:dashboard_action, :active, :admin_request, :resource) expect(action).not_to be_requested_for(proposal) end - it 'is requested when administrator task' do + it "is requested when administrator task" do proposal = create(:proposal) action = create(:dashboard_action, :active, :admin_request, :resource) executed_action = create(:dashboard_executed_action, proposal: proposal, action: action) @@ -123,15 +123,15 @@ describe Dashboard::Action do end end - context '#executed_for?' do - it 'is not executed when no administrator task' do + context "#executed_for?" do + it "is not executed when no administrator task" do proposal = create(:proposal) action = create(:dashboard_action, :active, :admin_request, :resource) expect(action).not_to be_executed_for(proposal) end - it 'is not executed when pending administrator task' do + it "is not executed when pending administrator task" do proposal = create(:proposal) action = create(:dashboard_action, :active, :admin_request, :resource) executed_action = create(:dashboard_executed_action, proposal: proposal, action: action) @@ -140,7 +140,7 @@ describe Dashboard::Action do expect(action).not_to be_executed_for(proposal) end - it 'is executed when done administrator task' do + it "is executed when done administrator task" do proposal = create(:proposal) action = create(:dashboard_action, :active, :admin_request, :resource) executed_action = create(:dashboard_executed_action, proposal: proposal, action: action) @@ -150,12 +150,14 @@ describe Dashboard::Action do end end - context '#active_for' do + context "#active_for" do let!(:active_action) { create :dashboard_action, :active, day_offset: 0, required_supports: 0 } - let!(:not_enough_supports_action) { create :dashboard_action, :active, day_offset: 0, required_supports: 10_000 } + let!(:not_enough_supports_action) { create :dashboard_action, :active, day_offset: 0, + required_supports: 10_000 } let!(:inactive_action) { create :dashboard_action, :inactive } - let!(:future_action) { create :dashboard_action, :active, day_offset: 300, required_supports: 0 } - let!(:action_for_published_proposal) { create :dashboard_action, + let!(:future_action) { create :dashboard_action, :active, day_offset: 300, + required_supports: 0 } + let!(:action_published_proposal) { create :dashboard_action, :active, day_offset: 0, required_supports: 0, @@ -185,11 +187,11 @@ describe Dashboard::Action do end it "actions with published_proposal: true, are not included on draft proposal" do - expect(described_class.active_for(draft_proposal)).not_to include(action_for_published_proposal) + expect(described_class.active_for(draft_proposal)).not_to include(action_published_proposal) end it "actions with published_proposal: true, are included on published proposal" do - expect(described_class.active_for(proposal)).to include(action_for_published_proposal) + expect(described_class.active_for(proposal)).to include(action_published_proposal) end it "actions with published_proposal: false, are included on draft proposal" do @@ -201,9 +203,10 @@ describe Dashboard::Action do end end - context '#course_for' do + context "#course_for" do let!(:proposed_action) { create :dashboard_action, :active, required_supports: 0 } - let!(:inactive_resource) { create :dashboard_action, :inactive, :resource, required_supports: 0 } + let!(:inactive_resource) { create :dashboard_action, :inactive, :resource, + required_supports: 0 } let!(:resource) { create :dashboard_action, :active, :resource, required_supports: 10_000 } let!(:achieved_resource) { create :dashboard_action, :active, :resource, required_supports: 0 } let(:proposal) { create :proposal }