Rubocop autocorrections

This commit is contained in:
Bertocq
2017-11-13 02:22:00 +01:00
parent 57f8aacdd7
commit cd66ba5d54
9 changed files with 63 additions and 65 deletions

View File

@@ -22,8 +22,10 @@ class Legislation::ProposalsController < Legislation::BaseController
super super
set_legislation_proposal_votes(@process.proposals) set_legislation_proposal_votes(@process.proposals)
@document = Document.new(documentable: @proposal) @document = Document.new(documentable: @proposal)
redirect_to legislation_process_proposal_path(params[:process_id], @proposal), if request.path != legislation_process_proposal_path(params[:process_id], @proposal)
status: :moved_permanently 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 end
def create def create
@@ -50,9 +52,9 @@ class Legislation::ProposalsController < Legislation::BaseController
def proposal_params def proposal_params
params.require(:legislation_proposal).permit(:legislation_process_id, :title, 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, :terms_of_service, :geozone_id,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] ) documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
end end
def resource_model def resource_model

View File

@@ -29,7 +29,7 @@ module AdminHelper
end end
def menu_profiles? 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 end
def menu_banners? def menu_banners?

View File

@@ -57,8 +57,7 @@ class Legislation::Proposal < ActiveRecord::Base
tag_list.join(' ') => 'B', tag_list.join(' ') => 'B',
geozone.try(:name) => 'B', geozone.try(:name) => 'B',
summary => 'C', summary => 'C',
description => 'D' description => 'D'}
}
end end
def self.search(terms) def self.search(terms)
@@ -69,7 +68,7 @@ class Legislation::Proposal < ActiveRecord::Base
def self.search_by_code(terms) def self.search_by_code(terms)
matched_code = match_code(terms) matched_code = match_code(terms)
results = where(id: matched_code[1]) if matched_code 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 end
def self.match_code(terms) def self.match_code(terms)
@@ -105,9 +104,7 @@ class Legislation::Proposal < ActiveRecord::Base
end end
def register_vote(user, vote_value) def register_vote(user, vote_value)
if votable_by?(user) vote_by(voter: user, vote: vote_value) if votable_by?(user)
vote_by(voter: user, vote: vote_value)
end
end end
def code def code

View File

@@ -37,7 +37,7 @@ class Poll::Question::Answer < ActiveRecord::Base
end end
def most_voted? def most_voted?
self.most_voted most_voted
end end
def total_votes_percentage def total_votes_percentage
@@ -46,9 +46,9 @@ class Poll::Question::Answer < ActiveRecord::Base
def set_most_voted def set_most_voted
answers = question.question_answers answers = question.question_answers
.map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count }
is_most_voted = !answers.any?{ |a| a > self.total_votes } is_most_voted = answers.none?{ |a| a > total_votes }
self.update(most_voted: is_most_voted) update(most_voted: is_most_voted)
end end
end end

View File

@@ -7,11 +7,11 @@ class Poll
def generate def generate
stats = %w[total_participants total_participants_web total_web_valid total_web_white total_web_null 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_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_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 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 null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage
total_participants_booth_percentage] total_participants_booth_percentage]
stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h
end end
@@ -26,9 +26,9 @@ class Poll
end end
def total_participants_web_percentage def total_participants_web_percentage
stats_cache('total_participants_web_percentage') { stats_cache('total_participants_web_percentage') do
(total_participants) == 0 ? 0 : total_participants_web * 100 / total_participants total_participants == 0 ? 0 : total_participants_web * 100 / total_participants
} end
end end
def total_participants_booth def total_participants_booth
@@ -36,9 +36,9 @@ class Poll
end end
def total_participants_booth_percentage def total_participants_booth_percentage
stats_cache('total_participants_booth_percentage') { stats_cache('total_participants_booth_percentage') do
(total_participants) == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f total_participants == 0 ? 0 : total_participants_booth * 100 / total_participants.to_f
} end
end end
def total_web_valid def total_web_valid
@@ -46,9 +46,9 @@ class Poll
end end
def valid_percentage_web def valid_percentage_web
stats_cache('valid_percentage_web') { stats_cache('valid_percentage_web') do
(total_valid_votes) == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f total_valid_votes == 0 ? 0 : total_web_valid * 100 / total_valid_votes.to_f
} end
end end
def total_web_white def total_web_white
@@ -72,9 +72,9 @@ class Poll
end end
def valid_percentage_booth def valid_percentage_booth
stats_cache('valid_percentage_booth') { stats_cache('valid_percentage_booth') do
(total_valid_votes) == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f total_valid_votes == 0 ? 0 : total_booth_valid * 100 / total_valid_votes.to_f
} end
end end
def total_booth_white def total_booth_white
@@ -82,9 +82,9 @@ class Poll
end end
def white_percentage_booth def white_percentage_booth
stats_cache('white_percentage_booth') { stats_cache('white_percentage_booth') do
(total_white_votes) == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f total_white_votes == 0 ? 0 : total_booth_white * 100 / total_white_votes.to_f
} end
end end
def total_booth_null def total_booth_null
@@ -92,9 +92,9 @@ class Poll
end end
def null_percentage_booth def null_percentage_booth
stats_cache('null_percentage_booth') { stats_cache('null_percentage_booth') do
(total_null_votes == 0) ? 0 : total_booth_null * 100 / total_null_votes.to_f total_null_votes == 0 ? 0 : total_booth_null * 100 / total_null_votes.to_f
} end
end end
def total_valid_votes def total_valid_votes
@@ -102,9 +102,9 @@ class Poll
end end
def total_valid_percentage def total_valid_percentage
stats_cache('total_valid_percentage'){ stats_cache('total_valid_percentage') do
(total_participants) == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f total_participants == 0 ? 0 : total_valid_votes * 100 / total_participants.to_f
} end
end end
def total_white_votes def total_white_votes
@@ -112,9 +112,9 @@ class Poll
end end
def total_white_percentage def total_white_percentage
stats_cache('total_white_percentage') { stats_cache('total_white_percentage') do
(total_participants) == 0 ? 0 : total_white_votes * 100 / total_participants.to_f total_participants == 0 ? 0 : total_white_votes * 100 / total_participants.to_f
} end
end end
def total_null_votes def total_null_votes
@@ -122,9 +122,9 @@ class Poll
end end
def total_null_percentage def total_null_percentage
stats_cache('total_null_percentage') { stats_cache('total_null_percentage') do
(total_participants) == 0 ? 0 : total_null_votes * 100 / total_participants.to_f total_participants == 0 ? 0 : total_null_votes * 100 / total_participants.to_f
} end
end end
def voters def voters

View File

@@ -102,7 +102,6 @@ class User < ActiveRecord::Base
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }
end end
def spending_proposal_votes(spending_proposals) def spending_proposal_votes(spending_proposals)
voted = votes.for_spending_proposals(spending_proposals) voted = votes.for_spending_proposals(spending_proposals)
voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value } voted.each_with_object({}) { |v, h| h[v.votable_id] = v.value }

View File

@@ -14,11 +14,11 @@ feature "Notifications" do
let(:legislation_question) { create(:legislation_question, process: process, author: administrator) } let(:legislation_question) { create(:legislation_question, process: process, author: administrator) }
let(:legislation_annotation) { create(:legislation_annotation, author: author) } let(:legislation_annotation) { create(:legislation_annotation, author: author) }
let(:topic) { let(:topic) do
proposal = create(:proposal) proposal = create(:proposal)
community = proposal.community community = proposal.community
create(:topic, community: community, author: author) create(:topic, community: community, author: author)
} end
scenario "User commented on my debate", :js do scenario "User commented on my debate", :js do
create(:notification, notifiable: debate, user: author) create(:notification, notifiable: debate, user: author)

View File

@@ -1,9 +1,9 @@
require 'rails_helper' require 'rails_helper'
describe Poll::Stats do describe Poll::Stats do
describe "Calculate stats" do describe "Calculate stats" do
it "Generate the correct stats" do it "Generate the correct stats" do
poll = create(:poll) poll = create(:poll)
booth = create(:poll_booth) booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: 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_voter, poll: poll)
create(:poll_recount, origin: 'booth', white_amount: 1, null_amount: 0, total_amount: 2, booth_assignment_id: booth_assignment.id) 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 stats = Poll::Stats.new(poll).generate
expect(stats[:total_participants]).to eq(5) expect(stats[:total_participants]).to eq(5)
expect(stats[:total_participants_web]).to eq(2) expect(stats[:total_participants_web]).to eq(2)
expect(stats[:total_participants_booth]).to eq(3) expect(stats[:total_participants_booth]).to eq(3)
expect(stats[:total_valid_votes]).to eq(4) expect(stats[:total_valid_votes]).to eq(4)
expect(stats[:total_white_votes]).to eq(1) expect(stats[:total_white_votes]).to eq(1)
expect(stats[:total_null_votes]).to eq(0) expect(stats[:total_null_votes]).to eq(0)
expect(stats[:total_web_valid]).to eq(2) expect(stats[:total_web_valid]).to eq(2)
expect(stats[:total_web_white]).to eq(0) expect(stats[:total_web_white]).to eq(0)
expect(stats[:total_web_null]).to eq(0) expect(stats[:total_web_null]).to eq(0)
expect(stats[:total_booth_valid]).to eq(2) expect(stats[:total_booth_valid]).to eq(2)
expect(stats[:total_booth_white]).to eq(1) expect(stats[:total_booth_white]).to eq(1)
expect(stats[:total_booth_null]).to eq(0) expect(stats[:total_booth_null]).to eq(0)
expect(stats[:total_participants_web_percentage]).to eq(40) expect(stats[:total_participants_web_percentage]).to eq(40)
expect(stats[:total_participants_booth_percentage]).to eq(60) expect(stats[:total_participants_booth_percentage]).to eq(60)
expect(stats[:valid_percentage_web]).to eq(50) 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_valid_percentage]).to eq(80)
expect(stats[:total_white_percentage]).to eq(20) expect(stats[:total_white_percentage]).to eq(20)
expect(stats[:total_null_percentage]).to eq(0) expect(stats[:total_null_percentage]).to eq(0)
end end
end end
end end

View File

@@ -303,8 +303,8 @@ module CommonActions
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_answers") do
click_link "#{answer}" click_link answer.to_s
expect(page).to_not have_link("#{answer}") expect(page).to_not have_link(answer.to_s)
end end
end end