From d2e08d1a0cc21ca31ab6ceb2e22f5266af6b8c08 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:43:07 +0200 Subject: [PATCH 1/8] Remove unused param on both method and call, using class variable instead --- app/controllers/users/omniauth_callbacks_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index cbe43390b..ef1ef31de 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -30,7 +30,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController identity = Identity.first_or_create_from_oauth(auth) @user = current_user || identity.user || User.first_or_initialize_for_oauth(auth) - if save_user(@user) + if save_user identity.update(user: @user) sign_in_and_redirect @user, event: :authentication set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format? @@ -40,8 +40,8 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController end end - def save_user(user) + def save_user @user.save || @user.save_requiring_finish_signup end -end \ No newline at end of file +end From 47648aa32a7326b3d5df6112a35bb20bee0f5d1a Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:44:04 +0200 Subject: [PATCH 2/8] Remove rubocop Rails/Date from rubocop_todo list since offenses where solved --- .rubocop_todo.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 19e3a59a6..29bc78d7e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -86,14 +86,6 @@ Performance/RedundantMatch: - 'app/controllers/valuation/spending_proposals_controller.rb' - 'app/helpers/embed_videos_helper.rb' -# Offense count: 2 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: strict, flexible -Rails/Date: - Exclude: - - 'app/controllers/concerns/commentable_actions.rb' - - 'app/models/direct_message.rb' - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: Whitelist. From 6529e37ae8f552280e95ae5d427d14e4f41de4ce Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:44:24 +0200 Subject: [PATCH 3/8] Fix all rubocop Rails/PluralizationGrammar issues and remove the file list form rubocop_todo file --- .rubocop_todo.yml | 9 --------- spec/controllers/comments_controller_spec.rb | 2 +- .../legislation/annotations_controller_spec.rb | 2 +- spec/controllers/legislation/answers_controller_spec.rb | 2 +- spec/factories.rb | 6 +++--- spec/features/admin/banners_spec.rb | 2 +- spec/features/comments/legislation_questions_spec.rb | 2 +- spec/features/debates_spec.rb | 4 ++-- spec/features/legislation/questions_spec.rb | 2 +- spec/features/proposals_spec.rb | 4 ++-- spec/models/legislation/process_spec.rb | 2 +- spec/models/poll/officer_spec.rb | 4 ++-- spec/models/residence_spec.rb | 2 +- 13 files changed, 17 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 29bc78d7e..c27549feb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,15 +130,6 @@ Rails/OutputSafety: - 'app/helpers/users_helper.rb' - 'app/helpers/valuation_helper.rb' -# Offense count: 6 -# Cop supports --auto-correct. -Rails/PluralizationGrammar: - Exclude: - - 'spec/features/admin/banners_spec.rb' - - 'spec/features/debates_spec.rb' - - 'spec/features/proposals_spec.rb' - - 'spec/models/residence_spec.rb' - # Offense count: 11 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: strict, flexible diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index abd2577c2..d06e1900f 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -4,7 +4,7 @@ describe CommentsController do describe 'POST create' do before(:each) do - @process = create(:legislation_process, debate_start_date: Date.current - 3.day, debate_end_date: Date.current + 2.days) + @process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days) @question = create(:legislation_question, process: @process, title: "Question 1") @user = create(:user, :level_two) @unverified_user = create(:user) diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb index 5b1fd3d39..51425a1f2 100644 --- a/spec/controllers/legislation/annotations_controller_spec.rb +++ b/spec/controllers/legislation/annotations_controller_spec.rb @@ -4,7 +4,7 @@ describe Legislation::AnnotationsController do describe 'POST create' do before(:each) do - @process = create(:legislation_process, allegations_start_date: Date.current - 3.day, allegations_end_date: Date.current + 2.days) + @process = create(:legislation_process, allegations_start_date: Date.current - 3.days, allegations_end_date: Date.current + 2.days) @draft_version = create(:legislation_draft_version, :published, process: @process, title: "Version 1") @final_version = create(:legislation_draft_version, :published, :final_version, process: @process, title: "Final version") @user = create(:user, :level_two) diff --git a/spec/controllers/legislation/answers_controller_spec.rb b/spec/controllers/legislation/answers_controller_spec.rb index 77d037478..569ea2879 100644 --- a/spec/controllers/legislation/answers_controller_spec.rb +++ b/spec/controllers/legislation/answers_controller_spec.rb @@ -4,7 +4,7 @@ describe Legislation::AnswersController do describe 'POST create' do before(:each) do - @process = create(:legislation_process, debate_start_date: Date.current - 3.day, debate_end_date: Date.current + 2.days) + @process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days) @question = create(:legislation_question, process: @process, title: "Question 1") @question_option = create(:legislation_question_option, question: @question, value: "Yes") @user = create(:user, :level_two) diff --git a/spec/factories.rb b/spec/factories.rb index 42c8dbfc5..987c53ca9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -632,7 +632,7 @@ FactoryGirl.define do end_date Date.current + 8.days debate_start_date Date.current + 2.days debate_end_date Date.current + 4.days - draft_publication_date Date.current + 5.day + draft_publication_date Date.current + 5.days allegations_start_date Date.current + 5.days allegations_end_date Date.current + 7.days result_publication_date Date.current + 8.days @@ -643,7 +643,7 @@ FactoryGirl.define do end_date Date.current - 2.days debate_start_date Date.current - 12.days debate_end_date Date.current - 9.days - draft_publication_date Date.current - 8.day + draft_publication_date Date.current - 8.days allegations_start_date Date.current - 8.days allegations_end_date Date.current - 4.days result_publication_date Date.current - 2.days @@ -653,7 +653,7 @@ FactoryGirl.define do start_date Date.current - 5.days end_date Date.current + 5.days debate_start_date Date.current - 5.days - debate_end_date Date.current + 1.days + debate_end_date Date.current + 1.day draft_publication_date Date.current + 1.day allegations_start_date Date.current + 2.days allegations_end_date Date.current + 3.days diff --git a/spec/features/admin/banners_spec.rb b/spec/features/admin/banners_spec.rb index 70d9f7621..28a105bed 100644 --- a/spec/features/admin/banners_spec.rb +++ b/spec/features/admin/banners_spec.rb @@ -29,7 +29,7 @@ feature 'Admin banners magement' do target_url: "http://www.url.com", style: "banner-style.banner-three", image: "banner-img.banner-three", - post_started_at: (Time.current - 1.days), + post_started_at: (Time.current - 1.day), post_ended_at: (Time.current + 10.days)) @banner4 = create(:banner, title: "Banner number four", diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb index 35521e89b..c10b12f55 100644 --- a/spec/features/comments/legislation_questions_spec.rb +++ b/spec/features/comments/legislation_questions_spec.rb @@ -192,7 +192,7 @@ feature 'Commenting legislation questions' do end scenario "Can't create comments if debate phase is not open", :js do - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.days) + process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 6914a55f7..4d48508f2 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -629,7 +629,7 @@ feature 'Debates' do click_link "Advanced search" select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago - fill_in "advanced_search_date_max", with: 1.days.ago + fill_in "advanced_search_date_max", with: 1.day.ago click_button "Filter" within("#debates") do @@ -709,7 +709,7 @@ feature 'Debates' do select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago - fill_in "advanced_search_date_max", with: 1.days.ago + fill_in "advanced_search_date_max", with: 1.day.ago click_button "Filter" within "#js-advanced-search" do diff --git a/spec/features/legislation/questions_spec.rb b/spec/features/legislation/questions_spec.rb index 77503b5a9..17d55c16c 100644 --- a/spec/features/legislation/questions_spec.rb +++ b/spec/features/legislation/questions_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature 'Legislation' do context 'process debate page' do before(:each) do - @process = create(:legislation_process, debate_start_date: Date.current - 3.day, debate_end_date: Date.current + 2.days) + @process = create(:legislation_process, debate_start_date: Date.current - 3.days, debate_end_date: Date.current + 2.days) create(:legislation_question, process: @process, title: "Question 1") create(:legislation_question, process: @process, title: "Question 2") create(:legislation_question, process: @process, title: "Question 3") diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 16d928f4e..9d8584839 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1025,7 +1025,7 @@ feature 'Proposals' do click_link "Advanced search" select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago - fill_in "advanced_search_date_max", with: 1.days.ago + fill_in "advanced_search_date_max", with: 1.day.ago click_button "Filter" expect(page).to have_content("There are 2 citizen proposals") @@ -1108,7 +1108,7 @@ feature 'Proposals' do select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago.to_date - fill_in "advanced_search_date_max", with: 1.days.ago.to_date + fill_in "advanced_search_date_max", with: 1.day.ago.to_date click_button "Filter" expect(page).to have_content("citizen proposals cannot be found") diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index f14e81c8e..33460832b 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -71,7 +71,7 @@ RSpec.describe Legislation::Process, type: :model do describe "filter scopes" do before(:each) do @process_1 = create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day) - @process_2 = create(:legislation_process, start_date: Date.current + 1.days, end_date: Date.current + 3.days) + @process_2 = create(:legislation_process, start_date: Date.current + 1.day, end_date: Date.current + 3.days) @process_3 = create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days) end diff --git a/spec/models/poll/officer_spec.rb b/spec/models/poll/officer_spec.rb index 83bdbecc2..1764f7200 100644 --- a/spec/models/poll/officer_spec.rb +++ b/spec/models/poll/officer_spec.rb @@ -48,7 +48,7 @@ describe :officer do poll_1 = create(:poll, ends_at: 1.day.ago) poll_2 = create(:poll, ends_at: 10.days.from_now) - poll_3 = create(:poll, ends_at: 10.day.ago) + poll_3 = create(:poll, ends_at: 10.days.ago) [poll_1, poll_2, poll_3].each do |p| create(:poll_officer_assignment, officer: officer, booth_assignment: create(:poll_booth_assignment, poll: p)) @@ -108,7 +108,7 @@ describe :officer do poll_1 = create(:poll, ends_at: 1.day.ago) poll_2 = create(:poll, ends_at: 10.days.from_now) - poll_3 = create(:poll, ends_at: 10.day.ago) + poll_3 = create(:poll, ends_at: 10.days.ago) [poll_1, poll_2, poll_3].each do |p| create(:poll_officer_assignment, officer: officer, booth_assignment: create(:poll_booth_assignment, poll: p), final: true) diff --git a/spec/models/residence_spec.rb b/spec/models/residence_spec.rb index 6841f636b..98b939084 100644 --- a/spec/models/residence_spec.rb +++ b/spec/models/residence_spec.rb @@ -25,7 +25,7 @@ describe Verification::Residence do end it "should validate user has allowed age" do - residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"#{5.year.ago.year}"}) + residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"#{5.years.ago.year}"}) expect(residence).to_not be_valid expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate") end From d759aca522b1174dffbfb8d843ee3a3fc8281f13 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:47:53 +0200 Subject: [PATCH 4/8] Fix all Rails/TimeZone rubocop issues and remove files from rubocop_todo list --- .rubocop_todo.yml | 9 --------- lib/score_calculator.rb | 2 +- .../admin/api/stats_controller_spec.rb | 18 +++++++++--------- spec/lib/graphql_spec.rb | 10 +++++----- spec/models/ahoy/data_source_spec.rb | 6 +++--- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c27549feb..c9a834849 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,15 +130,6 @@ Rails/OutputSafety: - 'app/helpers/users_helper.rb' - 'app/helpers/valuation_helper.rb' -# Offense count: 11 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Exclude: - - 'lib/score_calculator.rb' - - 'spec/controllers/admin/api/stats_controller_spec.rb' - - 'spec/models/ahoy/data_source_spec.rb' - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: Include. diff --git a/lib/score_calculator.rb b/lib/score_calculator.rb index 32086392a..0b68c025a 100644 --- a/lib/score_calculator.rb +++ b/lib/score_calculator.rb @@ -1,6 +1,6 @@ module ScoreCalculator - EPOC = Time.new(2015, 6, 15) + EPOC = Time.new(2015, 6, 15).in_time_zone COMMENT_WEIGHT = 1.0/5 # 1 positive vote / x comments TIME_UNIT = 24.hours.to_f diff --git a/spec/controllers/admin/api/stats_controller_spec.rb b/spec/controllers/admin/api/stats_controller_spec.rb index 7ba63ffb3..e032014d7 100644 --- a/spec/controllers/admin/api/stats_controller_spec.rb +++ b/spec/controllers/admin/api/stats_controller_spec.rb @@ -17,9 +17,9 @@ describe Admin::Api::StatsController do context 'events present' do before :each do - time_1 = DateTime.parse("2015-01-01") - time_2 = DateTime.parse("2015-01-02") - time_3 = DateTime.parse("2015-01-03") + time_1 = DateTime.parse("2015-01-01").in_time_zone + time_2 = DateTime.parse("2015-01-02").in_time_zone + time_3 = DateTime.parse("2015-01-03").in_time_zone create :ahoy_event, name: 'foo', time: time_1 create :ahoy_event, name: 'foo', time: time_1 @@ -52,8 +52,8 @@ describe Admin::Api::StatsController do context 'visits present' do it 'should return visits formated for working with c3.js' do - time_1 = DateTime.parse("2015-01-01") - time_2 = DateTime.parse("2015-01-02") + time_1 = DateTime.parse("2015-01-01").in_time_zone + time_2 = DateTime.parse("2015-01-02").in_time_zone create :visit, started_at: time_1 create :visit, started_at: time_1 @@ -71,8 +71,8 @@ describe Admin::Api::StatsController do context 'visits and events present' do it 'should return combined events and visits formated for working with c3.js' do - time_1 = DateTime.parse("2015-01-01") - time_2 = DateTime.parse("2015-01-02") + time_1 = DateTime.parse("2015-01-01").in_time_zone + time_2 = DateTime.parse("2015-01-02").in_time_zone create :ahoy_event, name: 'foo', time: time_1 create :ahoy_event, name: 'foo', time: time_2 @@ -94,8 +94,8 @@ describe Admin::Api::StatsController do context 'budget investments present' do it 'should return budget investments formated for working with c3.js' do - time_1 = DateTime.parse("2017-04-01") - time_2 = DateTime.parse("2017-04-02") + time_1 = DateTime.parse("2017-04-01").in_time_zone + time_2 = DateTime.parse("2017-04-02").in_time_zone budget_investment1 = create(:budget_investment, budget: @budget, created_at: time_1) budget_investment2 = create(:budget_investment, budget: @budget, created_at: time_2) diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index 725cc109a..b3b8b377f 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -321,7 +321,7 @@ describe 'ConsulSchema' do it 'does not include hidden comments' do visible_comment = create(:comment) - hidden_comment = create(:comment, hidden_at: Time.now) + hidden_comment = create(:comment, hidden_at: Time.current) response = execute('{ comments { edges { node { body } } } }') received_comments = extract_fields(response, 'comments', 'body') @@ -331,7 +331,7 @@ describe 'ConsulSchema' do it 'does not include comments from hidden proposals' do visible_proposal = create(:proposal) - hidden_proposal = create(:proposal, hidden_at: Time.now) + hidden_proposal = create(:proposal, hidden_at: Time.current) visible_proposal_comment = create(:comment, commentable: visible_proposal) hidden_proposal_comment = create(:comment, commentable: hidden_proposal) @@ -344,7 +344,7 @@ describe 'ConsulSchema' do it 'does not include comments from hidden debates' do visible_debate = create(:debate) - hidden_debate = create(:debate, hidden_at: Time.now) + hidden_debate = create(:debate, hidden_at: Time.current) visible_debate_comment = create(:comment, commentable: visible_debate) hidden_debate_comment = create(:comment, commentable: hidden_debate) @@ -567,7 +567,7 @@ describe 'ConsulSchema' do it 'does not include votes of hidden proposals' do visible_proposal = create(:proposal) - hidden_proposal = create(:proposal, hidden_at: Time.now) + hidden_proposal = create(:proposal, hidden_at: Time.current) visible_proposal_vote = create(:vote, votable: visible_proposal) hidden_proposal_vote = create(:vote, votable: hidden_proposal) @@ -580,7 +580,7 @@ describe 'ConsulSchema' do it 'does not include votes of hidden comments' do visible_comment = create(:comment) - hidden_comment = create(:comment, hidden_at: Time.now) + hidden_comment = create(:comment, hidden_at: Time.current) visible_comment_vote = create(:vote, votable: visible_comment) hidden_comment_vote = create(:vote, votable: hidden_comment) diff --git a/spec/models/ahoy/data_source_spec.rb b/spec/models/ahoy/data_source_spec.rb index deb1fd056..cea416498 100644 --- a/spec/models/ahoy/data_source_spec.rb +++ b/spec/models/ahoy/data_source_spec.rb @@ -3,9 +3,9 @@ require 'rails_helper' describe Ahoy::DataSource do describe '#build' do before :each do - time_1 = DateTime.parse("2015-01-01") - time_2 = DateTime.parse("2015-01-02") - time_3 = DateTime.parse("2015-01-03") + time_1 = DateTime.parse("2015-01-01").in_time_zone + time_2 = DateTime.parse("2015-01-02").in_time_zone + time_3 = DateTime.parse("2015-01-03").in_time_zone create :ahoy_event, name: 'foo', time: time_1 create :ahoy_event, name: 'foo', time: time_1 From 8d84ed712a748bd4e44154d8af0bcfe25a11339b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:49:44 +0200 Subject: [PATCH 5/8] Fix all Rails/Validation rubocop issues and remove files from rubocop_todo list --- .rubocop_todo.yml | 11 ----------- app/models/budget/investment.rb | 4 ++-- app/models/comment.rb | 2 +- app/models/officing/residence.rb | 6 +++--- app/models/spending_proposal.rb | 2 +- app/models/verification/residence.rb | 8 ++++---- app/models/verification/sms.rb | 2 +- 7 files changed, 12 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c9a834849..654a80644 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -130,17 +130,6 @@ Rails/OutputSafety: - 'app/helpers/users_helper.rb' - 'app/helpers/valuation_helper.rb' -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/Validation: - Exclude: - - 'app/models/comment.rb' - - 'app/models/spending_proposal.rb' - - 'app/models/verification/residence.rb' - - 'app/models/verification/sms.rb' - # Offense count: 9 Style/AccessorMethodName: Exclude: diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index b3b51996c..9d38d06d3 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -25,8 +25,8 @@ class Budget validates :author, presence: true validates :description, presence: true validates :heading_id, presence: true - validates_presence_of :unfeasibility_explanation, if: :unfeasibility_explanation_required? - validates_presence_of :price, if: :price_required? + validates :unfeasibility_explanation, presence: { if: :unfeasibility_explanation_required? } + validates :price, presence: { if: :price_required? } validates :title, length: { in: 4..Budget::Investment.title_max_length } validates :description, length: { maximum: Budget::Investment.description_max_length } diff --git a/app/models/comment.rb b/app/models/comment.rb index ffa02d09c..522b7324b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -13,7 +13,7 @@ class Comment < ActiveRecord::Base validates :body, presence: true validates :user, presence: true - validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Budget::Investment", "Poll::Question", "Legislation::Question", "Legislation::Annotation"] + validates :commentable_type, inclusion: { in: ["Debate", "Proposal", "Budget::Investment", "Poll::Question", "Legislation::Question", "Legislation::Annotation"] } validate :validate_body_length diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index 92333cc80..1714bbf0e 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -6,9 +6,9 @@ class Officing::Residence before_validation :call_census_api - validates_presence_of :document_number - validates_presence_of :document_type - validates_presence_of :year_of_birth + validates :document_number, presence: true + validates :document_type, presence: true + validates :year_of_birth, presence: true validate :allowed_age validate :residence_in_madrid diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 223e9adfe..a37446117 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -15,7 +15,7 @@ class SpendingProposal < ActiveRecord::Base validates :title, presence: true validates :author, presence: true validates :description, presence: true - validates_presence_of :feasible_explanation, if: :feasible_explanation_required? + validates :feasible_explanation, presence: { if: :feasible_explanation_required? } validates :title, length: { in: 4..SpendingProposal.title_max_length } validates :description, length: { maximum: SpendingProposal.description_max_length } diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index bafff129b..e1b2f6363 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -7,10 +7,10 @@ class Verification::Residence before_validation :call_census_api - validates_presence_of :document_number - validates_presence_of :document_type - validates_presence_of :date_of_birth - validates_presence_of :postal_code + validates :document_number, presence: true + validates :document_type, presence: true + validates :date_of_birth, presence: true + validates :postal_code, presence: true validates :terms_of_service, acceptance: { allow_nil: false } validates :postal_code, length: { is: 5 } diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index 1a013f1d8..7c1a1bfa6 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -3,7 +3,7 @@ class Verification::Sms attr_accessor :user, :phone, :confirmation_code - validates_presence_of :phone + validates :phone, presence: true validates :phone, format: { with: /\A[\d \+]+\z/ } validate :uniqness_phone From 391b32e1659e3e845f3d160a14c148e431b49486 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:50:41 +0200 Subject: [PATCH 6/8] Remove all Layout/BlockEndNewline rubocop issues and files from rubocop_todo list --- .rubocop_todo.yml | 7 ------- app/models/banner.rb | 5 ++--- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 654a80644..34e62f027 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -165,13 +165,6 @@ Layout/AlignParameters: - 'spec/models/user_spec.rb' - 'spec/rails_helper.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Layout/BlockEndNewline: - Exclude: - - 'app/models/banner.rb' - - 'spec/features/users_auth_spec.rb' - # Offense count: 19 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/app/models/banner.rb b/app/models/banner.rb index c4f2295e6..2764785d1 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -12,9 +12,8 @@ class Banner < ActiveRecord::Base validates :post_started_at, presence: true validates :post_ended_at, presence: true - scope :with_active, -> {where("post_started_at <= ?", Time.current). - where("post_ended_at >= ?", Time.current) } + scope :with_active, -> { where("post_started_at <= ?", Time.current).where("post_ended_at >= ?", Time.current) } - scope :with_inactive,-> {where("post_started_at > ? or post_ended_at < ?", Time.current, Time.current) } + scope :with_inactive, -> { where("post_started_at > ? or post_ended_at < ?", Time.current, Time.current) } end From 78efccc19729ac580a513b9f174f1895e97dbdae Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 21 Jun 2017 20:51:58 +0200 Subject: [PATCH 7/8] Fix all Layout/EmptyLinesAroundAccessModifier rubocop issues and remove files from rubocop_todo list --- .rubocop_todo.yml | 6 ------ app/controllers/admin/poll/polls_controller.rb | 1 + app/controllers/legislation/answers_controller.rb | 1 + app/controllers/officing/final_recounts_controller.rb | 1 + app/controllers/officing/recounts_controller.rb | 1 + app/controllers/users_controller.rb | 1 + 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 34e62f027..fefe65c66 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -246,12 +246,6 @@ Layout/EmptyLines: - 'spec/features/verification/verified_user_spec.rb' - 'spec/support/verifiable.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLinesAroundAccessModifier: - Exclude: - - 'app/controllers/users_controller.rb' - # Offense count: 29 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index eda5736b0..6046ffb48 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -67,6 +67,7 @@ class Admin::Poll::PollsController < Admin::BaseController end private + def load_geozones @geozones = Geozone.all.order(:name) end diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index 6d3c33580..02946013b 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -26,6 +26,7 @@ class Legislation::AnswersController < Legislation::BaseController end private + def answer_params params.require(:legislation_answer).permit( :legislation_question_option_id, diff --git a/app/controllers/officing/final_recounts_controller.rb b/app/controllers/officing/final_recounts_controller.rb index e381240e7..8be6e1a91 100644 --- a/app/controllers/officing/final_recounts_controller.rb +++ b/app/controllers/officing/final_recounts_controller.rb @@ -28,6 +28,7 @@ class Officing::FinalRecountsController < Officing::BaseController end private + def load_poll @poll = Poll.expired.find(params[:poll_id]) end diff --git a/app/controllers/officing/recounts_controller.rb b/app/controllers/officing/recounts_controller.rb index 1c66e57fd..9e3989c05 100644 --- a/app/controllers/officing/recounts_controller.rb +++ b/app/controllers/officing/recounts_controller.rb @@ -27,6 +27,7 @@ class Officing::RecountsController < Officing::BaseController end private + def load_poll @poll = Poll.find(params[:poll_id]) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9bd98aedd..07ff645e6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -10,6 +10,7 @@ class UsersController < ApplicationController end private + def set_activity_counts @activity_counts = HashWithIndifferentAccess.new( proposals: Proposal.where(author_id: @user.id).count, From 9504958a0804deb3cc48474024bd03bc4929726f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 26 Jun 2017 11:10:30 +0200 Subject: [PATCH 8/8] Disable Style/SymbolArray rubocop cop after core discussion about it --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 58cf10d34..cbb1bd0fb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -31,6 +31,9 @@ Style/FrozenStringLiteralComment: Style/PercentLiteralDelimiters: Enabled: false +Style/SymbolArray: + Enabled: false + Layout/EmptyLinesAroundClassBody: Enabled: false