From e4e78c8f166f92c3dd8671ffb2a93c8172117c00 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 14 Sep 2017 13:18:37 +0200 Subject: [PATCH] Rubocop autocorrections --- Gemfile | 2 +- app/controllers/admin/poll/shifts_controller.rb | 2 +- app/controllers/communities_controller.rb | 2 +- app/controllers/documents_controller.rb | 6 +++--- app/controllers/proposals_controller.rb | 2 +- app/helpers/documentables_helper.rb | 4 ++-- app/helpers/documents_helper.rb | 8 ++++---- app/models/community.rb | 2 +- app/models/concerns/documentable.rb | 2 +- app/models/document.rb | 4 ++-- app/models/poll/booth.rb | 2 +- app/models/poll/shift.rb | 8 ++++---- app/models/topic.rb | 2 +- app/models/user.rb | 6 +++--- spec/features/admin/poll/booths_spec.rb | 6 +++--- spec/features/admin/poll/shifts_spec.rb | 14 +++++++------- spec/features/budgets/investments_spec.rb | 2 +- spec/features/comments/debates_spec.rb | 2 +- spec/features/proposals_spec.rb | 2 +- spec/lib/tasks/communities_spec.rb | 2 +- spec/models/poll/booth_spec.rb | 8 ++++---- spec/models/poll/shift_spec.rb | 12 ++++++------ spec/models/topic_spec.rb | 1 - spec/shared/features/documentable.rb | 2 +- spec/shared/features/nested_documentable.rb | 6 ++---- 25 files changed, 53 insertions(+), 56 deletions(-) diff --git a/Gemfile b/Gemfile index 3f17d753b..a6c1dc71e 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem 'graphql', '~> 1.6.3' gem 'groupdate', '~> 3.2.0' gem 'initialjs-rails', '~> 0.2.0.5' gem 'invisible_captcha', '~> 0.9.2' +gem 'jquery-fileupload-rails' gem 'jquery-rails', '~> 4.3.1' gem 'jquery-ui-rails', '~> 6.0.1' gem 'kaminari', '~> 1.0.1' @@ -33,7 +34,6 @@ gem 'omniauth-facebook', '~> 4.0.0' gem 'omniauth-google-oauth2', '~> 0.4.0' gem 'omniauth-twitter', '~> 1.4.0' gem 'paperclip', '~> 5.1.0' -gem 'jquery-fileupload-rails' gem 'paranoia', '~> 2.3.1' gem 'pg', '~> 0.21.0' gem 'pg_search', '~> 2.0.1' diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 168284474..4294045e5 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -1,5 +1,5 @@ class Admin::Poll::ShiftsController < Admin::BaseController - + before_action :load_booth before_action :load_polls before_action :load_officer diff --git a/app/controllers/communities_controller.rb b/app/controllers/communities_controller.rb index ff74f208b..f6f1e4816 100644 --- a/app/controllers/communities_controller.rb +++ b/app/controllers/communities_controller.rb @@ -7,7 +7,7 @@ class CommunitiesController < ApplicationController skip_authorization_check def show - redirect_to root_path unless Setting['feature.community'].present? + redirect_to root_path if Setting['feature.community'].blank? end private diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index ceb7d191f..a48f182ab 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,8 +1,8 @@ class DocumentsController < ApplicationController before_action :authenticate_user! - before_filter :find_documentable, except: :destroy - before_filter :prepare_new_document, only: [:new, :new_nested] - before_filter :prepare_document_for_creation, only: :create + before_action :find_documentable, except: :destroy + before_action :prepare_new_document, only: [:new, :new_nested] + before_action :prepare_document_for_creation, only: :create load_and_authorize_resource except: :upload skip_authorization_check only: :upload diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index cedc4e8ef..06e170ee2 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -78,7 +78,7 @@ class ProposalsController < ApplicationController def proposal_params params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url, :responsible_name, :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 retired_params diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index 4fd737908..a4a840785 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -18,8 +18,8 @@ module DocumentablesHelper def accepted_content_types_extensions(documentable_class) documentable_class.accepted_content_types - .collect{ |content_type| ".#{content_type.split("/").last}" } - .join(",") + .collect{ |content_type| ".#{content_type.split('/').last}" } + .join(",") end def humanized_accepted_content_types(documentable) diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index 17d70068b..a8ae6c973 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -80,10 +80,10 @@ module DocumentsHelper def document_direct_upload_url(document) upload_documents_url( - documentable_type: document.documentable_type, - documentable_id: document.documentable_id, - format: :js - ) + documentable_type: document.documentable_type, + documentable_id: document.documentable_id, + format: :js + ) end end diff --git a/app/models/community.rb b/app/models/community.rb index 3fa1cebaa..7d7073412 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -11,7 +11,7 @@ class Community < ActiveRecord::Base end def from_proposal? - self.proposal.present? + proposal.present? end private diff --git a/app/models/concerns/documentable.rb b/app/models/concerns/documentable.rb index 4aeaf6eab..729a0b0f8 100644 --- a/app/models/concerns/documentable.rb +++ b/app/models/concerns/documentable.rb @@ -10,7 +10,7 @@ module Documentable private - def documentable(options= {}) + def documentable(options = {}) @max_documents_allowed = options[:max_documents_allowed] @max_file_size = options[:max_file_size] @accepted_content_types = options[:accepted_content_types] diff --git a/app/models/document.rb b/app/models/document.rb index 7fd82ea33..3556d4c0a 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -40,7 +40,7 @@ class Document < ActiveRecord::Base attachment.instance.prefix(attachment, style) end - def prefix(attachment, style) + def prefix(attachment, _style) if !attachment.instance.persisted? "cached_attachments/user/#{attachment.instance.user_id}" else @@ -75,7 +75,7 @@ class Document < ActiveRecord::Base end def remove_cached_document - File.delete(cached_attachment) if File.exists?(cached_attachment) + File.delete(cached_attachment) if File.exist?(cached_attachment) end end diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index 0aca6eecb..04f9d3dea 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -5,7 +5,7 @@ class Poll has_many :shifts validates :name, presence: true, uniqueness: true - + def self.search(terms) return Booth.none if terms.blank? Booth.where("name ILIKE ? OR location ILIKE ?", "%#{terms}%", "%#{terms}%") diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index cc6a43425..37a8658f3 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -1,13 +1,13 @@ class Poll class Shift < ActiveRecord::Base - belongs_to :booth - belongs_to :officer + belongs_to :booth + belongs_to :officer validates :booth_id, presence: true validates :officer_id, presence: true validates :date, presence: true validates :date, uniqueness: { scope: [:officer_id, :booth_id] } - + before_create :persist_data after_create :create_officer_assignments @@ -20,7 +20,7 @@ class Poll end end - def persist_data + def persist_data self.officer_name = officer.name self.officer_email = officer.email end diff --git a/app/models/topic.rb b/app/models/topic.rb index 34abed0e3..e0a73d58b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -13,6 +13,6 @@ class Topic < ActiveRecord::Base scope :sort_by_newest, -> { order(created_at: :desc) } scope :sort_by_oldest, -> { order(created_at: :asc) } - scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } + scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } end diff --git a/app/models/user.rb b/app/models/user.rb index ef6ab7832..006d1a09e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -57,13 +57,13 @@ class User < ActiveRecord::Base scope :officials, -> { where("official_level > 0") } scope :newsletter, -> { where(newsletter: true) } scope :for_render, -> { includes(:organization) } - scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) } + scope :by_document, ->(document_type, document_number) { where(document_type: document_type, document_number: document_number) } scope :email_digest, -> { where(email_digest: true) } scope :active, -> { where(erased_at: nil) } scope :erased, -> { where.not(erased_at: nil) } scope :public_for_api, -> { all } - scope :by_comments, -> (query, topics_ids) { joins(:comments).where(query, topics_ids).uniq } - scope :by_authors, -> (author_ids) { where("users.id IN (?)", author_ids) } + scope :by_comments, ->(query, topics_ids) { joins(:comments).where(query, topics_ids).uniq } + scope :by_authors, ->(author_ids) { where("users.id IN (?)", author_ids) } before_validation :clean_document_number diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index fd8fb9e84..13f3af2ff 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -44,13 +44,13 @@ feature 'Admin booths' do current_poll = create(:poll, :current) incoming_poll = create(:poll, :incoming) expired_poll = create(:poll, :expired) - + create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll) create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) - + visit admin_root_path - + within('#side_menu') do click_link "Manage shifts" end diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 761a79536..65396267b 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -8,13 +8,13 @@ feature 'Admin shifts' do end scenario "Show" do - poll = create(:poll) + poll = create(:poll) officer = create(:poll_officer) booth1 = create(:poll_booth) booth2 = create(:poll_booth) - - shift1 = create(:poll_shift, officer: officer, booth: booth1, date: Date.today) + + shift1 = create(:poll_shift, officer: officer, booth: booth1, date: Date.today) shift2 = create(:poll_shift, officer: officer, booth: booth2, date: Date.tomorrow) visit new_admin_booth_shift_path(booth1) @@ -36,7 +36,7 @@ feature 'Admin shifts' do officer = create(:poll_officer) visit admin_booths_path - + within("#booth_#{booth.id}") do click_link "Manage shifts" end @@ -47,7 +47,7 @@ feature 'Admin shifts' do select I18n.l(poll.starts_at.to_date, format: :long), from: 'shift_date' click_button "Add shift" - + expect(page).to have_content "Shift added" within("#shifts") do @@ -63,7 +63,7 @@ feature 'Admin shifts' do officer = create(:poll_officer) visit admin_booths_path - + within("#booth_#{booth.id}") do click_link "Manage shifts" end @@ -84,7 +84,7 @@ feature 'Admin shifts' do shift = create(:poll_shift, officer: officer, booth: booth) visit admin_booths_path - + within("#booth_#{booth.id}") do click_link "Manage shifts" end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 4040717f1..820ebb520 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -341,7 +341,7 @@ feature 'Budget Investments' do scenario 'Can not access the community' do Setting['feature.community'] = false - + investment = create(:budget_investment, heading: heading) visit budget_investment_path(budget_id: budget.id, id: investment.id) expect(page).not_to have_content "Access the community" diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index 28166784a..77cab01d9 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -33,7 +33,7 @@ feature 'Commenting debates' do expect(page).to have_content second_child.body expect(page).to have_link "Go back to #{debate.title}", href: debate_path(debate) - + expect(page).to have_selector("ul#comment_#{parent_comment.id}>li", count: 2) expect(page).to have_selector("ul#comment_#{first_child.id}>li", count: 1) expect(page).to have_selector("ul#comment_#{second_child.id}>li", count: 1) diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index f9bef400c..a7c7880a8 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -102,7 +102,7 @@ feature 'Proposals' do scenario 'Can not access the community' do Setting['feature.community'] = false - + proposal = create(:proposal) visit proposal_path(proposal) expect(page).not_to have_content "Access the community" diff --git a/spec/lib/tasks/communities_spec.rb b/spec/lib/tasks/communities_spec.rb index 20c1af841..3a8819147 100644 --- a/spec/lib/tasks/communities_spec.rb +++ b/spec/lib/tasks/communities_spec.rb @@ -41,7 +41,7 @@ describe 'Communities Rake' do expect(investment.community).to be_present end - + end end diff --git a/spec/models/poll/booth_spec.rb b/spec/models/poll/booth_spec.rb index d340d8197..8c2729c79 100644 --- a/spec/models/poll/booth_spec.rb +++ b/spec/models/poll/booth_spec.rb @@ -25,20 +25,20 @@ describe :booth do end describe "#available" do - + it "returns booths associated to current or incoming polls" do booth_for_current_poll = create(:poll_booth) booth_for_incoming_poll = create(:poll_booth) booth_for_expired_poll = create(:poll_booth) - + current_poll = create(:poll, :current) incoming_poll = create(:poll, :incoming) expired_poll = create(:poll, :expired) - + create(:poll_booth_assignment, poll: current_poll, booth: booth_for_current_poll) create(:poll_booth_assignment, poll: incoming_poll, booth: booth_for_incoming_poll) create(:poll_booth_assignment, poll: expired_poll, booth: booth_for_expired_poll) - + expect(Poll::Booth.available).to include(booth_for_current_poll) expect(Poll::Booth.available).to include(booth_for_incoming_poll) expect(Poll::Booth.available).to_not include(booth_for_expired_poll) diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 409e38f93..b7918b95c 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -43,7 +43,7 @@ describe :shift do officer_assignments = Poll::OfficerAssignment.all expect(officer_assignments.count).to eq(2) - + oa1 = officer_assignments.first oa2 = officer_assignments.second @@ -59,10 +59,10 @@ describe :shift do end describe "#persist_data" do - - let(:user) { create(:user, username: "Ana", email: "ana@example.com") } - let(:officer) { create(:poll_officer, user: user) } - let(:shift) { create(:poll_shift, officer: officer) } + + let(:user) { create(:user, username: "Ana", email: "ana@example.com") } + let(:officer) { create(:poll_officer, user: user) } + let(:shift) { create(:poll_shift, officer: officer) } it "should maintain officer data after destroying associated user" do shift.officer.user.destroy @@ -79,5 +79,5 @@ describe :shift do end end - + end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 9acc47633..5071439fa 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -71,5 +71,4 @@ describe Topic do end - end diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb index b8b5ebe1c..e9a82c63c 100644 --- a/spec/shared/features/documentable.rb +++ b/spec/shared/features/documentable.rb @@ -60,7 +60,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, login_as(user) visit send(documentable_path, arguments) - click_link "Upload document" + click_link "Upload document" expect(page).to have_selector("h1", text: "Upload document") end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index d03841d36..253deacda 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -11,10 +11,8 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum before do create(:administrator, user: administrator) - if documentable_path_arguments - documentable_path_arguments.each do |argument_name, path_to_value| + documentable_path_arguments&.each do |argument_name, path_to_value| arguments.merge!("#{argument_name}": documentable.send(path_to_value)) - end end end @@ -222,7 +220,7 @@ shared_examples "nested documentable" do |documentable_factory_name, path, docum send(fill_resource_method_name) if fill_resource_method_name documentable.class.max_documents_allowed.times.each do |index| - attach_new_file(documentable_factory_name, index , "spec/fixtures/files/empty.pdf") + attach_new_file(documentable_factory_name, index, "spec/fixtures/files/empty.pdf") end click_on submit_button