diff --git a/app/controllers/legislation/proposals_controller.rb b/app/controllers/legislation/proposals_controller.rb index 6aec36057..70fdbea33 100644 --- a/app/controllers/legislation/proposals_controller.rb +++ b/app/controllers/legislation/proposals_controller.rb @@ -22,8 +22,10 @@ class Legislation::ProposalsController < Legislation::BaseController super set_legislation_proposal_votes(@process.proposals) @document = Document.new(documentable: @proposal) - redirect_to legislation_process_proposal_path(params[:process_id], @proposal), - status: :moved_permanently if request.path != legislation_process_proposal_path(params[:process_id], @proposal) + if request.path != legislation_process_proposal_path(params[:process_id], @proposal) + redirect_to legislation_process_proposal_path(params[:process_id], @proposal), + status: :moved_permanently + end end def create @@ -50,9 +52,9 @@ class Legislation::ProposalsController < Legislation::BaseController def proposal_params params.require(:legislation_proposal).permit(:legislation_process_id, :title, - :question, :summary, :description, :video_url, :tag_list, + :question, :summary, :description, :video_url, :tag_list, :terms_of_service, :geozone_id, - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id]) end def resource_model diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index d71173060..88f10935f 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -29,7 +29,7 @@ module AdminHelper end def menu_profiles? - ["administrators", "organizations", "officials", "moderators", "valuators", "managers", "users", "activity"].include? controller_name + %w[administrators organizations officials moderators valuators managers users activity].include? controller_name end def menu_banners? diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index ec3dc6410..56eaac24b 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -57,8 +57,7 @@ class Legislation::Proposal < ActiveRecord::Base tag_list.join(' ') => 'B', geozone.try(:name) => 'B', summary => 'C', - description => 'D' - } + description => 'D'} end def self.search(terms) @@ -69,7 +68,7 @@ class Legislation::Proposal < ActiveRecord::Base def self.search_by_code(terms) matched_code = match_code(terms) results = where(id: matched_code[1]) if matched_code - return results if (results.present? && results.first.code == terms) + return results if results.present? && results.first.code == terms end def self.match_code(terms) @@ -105,9 +104,7 @@ class Legislation::Proposal < ActiveRecord::Base end def register_vote(user, vote_value) - if votable_by?(user) - vote_by(voter: user, vote: vote_value) - end + vote_by(voter: user, vote: vote_value) if votable_by?(user) end def code diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index dbf2f2139..5641b39f5 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -37,7 +37,7 @@ class Poll::Question::Answer < ActiveRecord::Base end def most_voted? - self.most_voted + most_voted end def total_votes_percentage @@ -46,9 +46,9 @@ class Poll::Question::Answer < ActiveRecord::Base def set_most_voted answers = question.question_answers - .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } - is_most_voted = !answers.any?{ |a| a > self.total_votes } + .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } + is_most_voted = answers.none?{ |a| a > total_votes } - self.update(most_voted: is_most_voted) + update(most_voted: is_most_voted) end end diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index ac45a2aae..03d870f69 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -7,11 +7,11 @@ class Poll def generate stats = %w[total_participants total_participants_web total_web_valid total_web_white total_web_null - total_participants_booth total_booth_valid total_booth_white total_booth_null - total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth - total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage - null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage - total_participants_booth_percentage] + total_participants_booth total_booth_valid total_booth_white total_booth_null + total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth + total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage + null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage + total_participants_booth_percentage] stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h end @@ -26,9 +26,9 @@ class Poll end def total_participants_web_percentage - stats_cache('total_participants_web_percentage') { - (total_participants) == 0 ? 0 : total_participants_web * 100 / total_participants - } + stats_cache('total_participants_web_percentage') do + total_participants == 0 ? 0 : total_participants_web * 100 / total_participants + end end def total_participants_booth @@ -36,9 +36,9 @@ class Poll end def total_participants_booth_percentage - stats_cache('total_participants_booth_percentage') { - (total_participants) == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f - } + stats_cache('total_participants_booth_percentage') do + total_participants == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f + end end def total_web_valid @@ -46,9 +46,9 @@ class Poll end def valid_percentage_web - stats_cache('valid_percentage_web') { - (total_valid_votes) == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f - } + stats_cache('valid_percentage_web') do + total_valid_votes == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f + end end def total_web_white @@ -72,9 +72,9 @@ class Poll end def valid_percentage_booth - stats_cache('valid_percentage_booth') { - (total_valid_votes) == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f - } + stats_cache('valid_percentage_booth') do + total_valid_votes == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f + end end def total_booth_white @@ -82,9 +82,9 @@ class Poll end def white_percentage_booth - stats_cache('white_percentage_booth') { - (total_white_votes) == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f - } + stats_cache('white_percentage_booth') do + total_white_votes == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f + end end def total_booth_null @@ -92,9 +92,9 @@ class Poll end def null_percentage_booth - stats_cache('null_percentage_booth') { - (total_null_votes == 0) ? 0 : total_booth_null * 100 / total_null_votes.to_f - } + stats_cache('null_percentage_booth') do + total_null_votes == 0 ? 0 : total_booth_null * 100 / total_null_votes.to_f + end end def total_valid_votes @@ -102,9 +102,9 @@ class Poll end def total_valid_percentage - stats_cache('total_valid_percentage'){ - (total_participants) == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f - } + stats_cache('total_valid_percentage') do + total_participants == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f + end end def total_white_votes @@ -112,9 +112,9 @@ class Poll end def total_white_percentage - stats_cache('total_white_percentage') { - (total_participants) == 0 ? 0 : total_white_votes * 100 / total_participants.to_f - } + stats_cache('total_white_percentage') do + total_participants == 0 ? 0 : total_white_votes * 100 / total_participants.to_f + end end def total_null_votes @@ -122,9 +122,9 @@ class Poll end def total_null_percentage - stats_cache('total_null_percentage') { - (total_participants) == 0 ? 0 : total_null_votes * 100 / total_participants.to_f - } + stats_cache('total_null_percentage') do + total_participants == 0 ? 0 : total_null_votes * 100 / total_participants.to_f + end end def voters diff --git a/app/models/user.rb b/app/models/user.rb index a212c1b5c..527ae3abc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -102,7 +102,6 @@ class User < ActiveRecord::Base voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } end - def spending_proposal_votes(spending_proposals) voted = votes.for_spending_proposals(spending_proposals) voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 75ed91857..fee0da813 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -14,11 +14,11 @@ feature "Notifications" do let(:legislation_question) { create(:legislation_question, process: process, author: administrator) } let(:legislation_annotation) { create(:legislation_annotation, author: author) } - let(:topic) { + let(:topic) do proposal = create(:proposal) community = proposal.community create(:topic, community: community, author: author) - } + end scenario "User commented on my debate", :js do create(:notification, notifiable: debate, user: author) diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb index ee431fa97..16f055d36 100644 --- a/spec/models/poll/stats_spec.rb +++ b/spec/models/poll/stats_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' describe Poll::Stats do - - describe "Calculate stats" do - it "Generate the correct stats" do + + describe "Calculate stats" do + it "Generate the correct stats" do poll = create(:poll) booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) @@ -12,22 +12,22 @@ describe Poll::Stats do create(:poll_voter, poll: poll) create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id) stats = Poll::Stats.new(poll).generate - + expect(stats[:total_participants]).to eq(5) expect(stats[:total_participants_web]).to eq(2) - expect(stats[:total_participants_booth]).to eq(3) - expect(stats[:total_valid_votes]).to eq(4) - expect(stats[:total_white_votes]).to eq(1) - expect(stats[:total_null_votes]).to eq(0) - + expect(stats[:total_participants_booth]).to eq(3) + expect(stats[:total_valid_votes]).to eq(4) + expect(stats[:total_white_votes]).to eq(1) + expect(stats[:total_null_votes]).to eq(0) + expect(stats[:total_web_valid]).to eq(2) expect(stats[:total_web_white]).to eq(0) expect(stats[:total_web_null]).to eq(0) - + expect(stats[:total_booth_valid]).to eq(2) expect(stats[:total_booth_white]).to eq(1) expect(stats[:total_booth_null]).to eq(0) - + expect(stats[:total_participants_web_percentage]).to eq(40) expect(stats[:total_participants_booth_percentage]).to eq(60) expect(stats[:valid_percentage_web]).to eq(50) @@ -39,7 +39,7 @@ describe Poll::Stats do expect(stats[:total_valid_percentage]).to eq(80) expect(stats[:total_white_percentage]).to eq(20) expect(stats[:total_null_percentage]).to eq(0) - end + end end - + end \ No newline at end of file diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 5023c1952..c1c7bfd2a 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -303,8 +303,8 @@ module CommonActions visit poll_path(poll) within("#poll_question_#{question.id}_answers") do - click_link "#{answer}" - expect(page).to_not have_link("#{answer}") + click_link answer.to_s + expect(page).to_not have_link(answer.to_s) end end