From cb810e58ce7ae0773fbf960fe40186cb0b8176a2 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:29:52 +0200 Subject: [PATCH 1/6] Style/AlignHash fix --- .rubocop.yml | 4 ++++ .../controllers/admin/conferences_controller_spec.rb | 8 ++++---- spec/models/campaign_spec.rb | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dbd68f69..216f1c0a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -80,6 +80,10 @@ Lint/UselessAssignment: Lint/Void: Enabled: true +# Align the elements of a hash literal if they span more than one line +Style/AlignHash: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 86523fc1..7865e2f2 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::ConferenceController do it 'changes conference attributes' do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con', - short_title: 'ExCon') + short_title: 'ExCon') conference.reload expect(conference.title).to eq('Example Con') @@ -67,7 +67,7 @@ describe Admin::ConferenceController do it 'does not change conference attributes' do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con', - short_title: nil) + short_title: nil) conference.reload expect(flash[:alert]). @@ -79,7 +79,7 @@ describe Admin::ConferenceController do it 're-renders the #show template' do patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con', - short_title: nil) + short_title: nil) expect(flash[:alert]). to eq("Updating conference failed. Short title can't be blank.") @@ -266,7 +266,7 @@ describe Admin::ConferenceController do describe 'PATCH #update' do it 'requires admin privileges' do patch :update, id: conference.short_title, - conference: attributes_for(:conference, + conference: attributes_for(:conference, short_title: 'ExCon') expect(response).to redirect_to(send(success_path)) end diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb index e836d3ba..0bf30aa5 100644 --- a/spec/models/campaign_spec.rb +++ b/spec/models/campaign_spec.rb @@ -15,7 +15,7 @@ describe Campaign do describe '#url_parameters' do it 'returns the parameters in the correct format' do campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') campaign.conference = create(:conference) result = '?utm_source=google+&utm_medium=advertisement&utm_term=opensource&utm_content=content&utm_campaign=20percent' @@ -32,17 +32,17 @@ describe Campaign do describe '#visits' do it 'returns one if there is one visit' do campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') campaign.conference = build(:conference) create(:visit, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent', started_at: Time.now) + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent', started_at: Time.now) expect(campaign.visits_count).to eq(1) end it 'returns zero if there are no visits' do campaign = create(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') campaign.conference = create(:conference) expect(campaign.visits_count).to eq(0) @@ -52,7 +52,7 @@ describe Campaign do describe '#registrations' do it 'returns zero if there are no registration' do campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') campaign.conference = build(:conference) expect(campaign.registrations_count).to eq(0) @@ -62,7 +62,7 @@ describe Campaign do describe '#submissions' do it 'returns zero if there are no submissions' do campaign = build(:campaign, utm_source: 'google+', utm_medium: 'advertisement', - utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') + utm_term: 'opensource', utm_content: 'content', utm_campaign: '20percent') campaign.conference = build(:conference) expect(campaign.submissions_count).to eq(0) From f8784fdcd8e2f2a55eb852df531362d9d9028046 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:32:29 +0200 Subject: [PATCH 2/6] rubocop style fix Style/AlignParameters --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 11 +---------- app/controllers/admin/stats_controller.rb | 2 +- app/models/event.rb | 2 +- spec/controllers/admin/conferences_controller_spec.rb | 5 ++--- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 216f1c0a..1205d53b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -84,6 +84,10 @@ Lint/Void: Style/AlignHash: Enabled: true +# Align the parameters of a method call if they span more than one line +Style/AlignParameters: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 318072cf..1685d43c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,17 +5,8 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. -Style/AlignHash: - Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AlignParameters: - Enabled: false + # Offense count: 2 # Cop supports --auto-correct. diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index b5685bff..c98b9892 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -128,7 +128,7 @@ module Admin day_ticket_count = @tickets.where('supporter_registrations.created_at LIKE ? AND supporter_levels.title LIKE ?', - "%#{day}%", "%#{level.title}%").count + "%#{day}%", "%#{level.title}%").count index = @tickets_time.index { |v| v['key'] == "#{level.title}" } @tickets_time[index]['values'] << { 'label' => "#{day}", 'value' => day_ticket_count } diff --git a/app/models/event.rb b/app/models/event.rb index 70306615..08d5d1b4 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -195,7 +195,7 @@ class Event < ActiveRecord::Base begin if mail self.send(transition, - send_mail: send_mail_param) + send_mail: send_mail_param) else self.send(transition) end diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 7865e2f2..e3286fa0 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -19,8 +19,7 @@ describe Admin::ConferenceController do context 'valid attributes' do it 'locates the requested conference' do - patch :update, id: conference.short_title, conference: - attributes_for(:conference, title: 'Example Con') + patch :update, id: conference.short_title, conference: attributes_for(:conference, title: 'Example Con') expect(assigns(:conference)).to eq(conference) end @@ -267,7 +266,7 @@ describe Admin::ConferenceController do it 'requires admin privileges' do patch :update, id: conference.short_title, conference: attributes_for(:conference, - short_title: 'ExCon') + short_title: 'ExCon') expect(response).to redirect_to(send(success_path)) end end From 4aa1f0bf3abba4c0aebfed2c650cf81bf11e9d6d Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:34:09 +0200 Subject: [PATCH 3/6] rubocop Style/AndOr style enabled --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 6 ------ app/controllers/application_controller.rb | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1205d53b..decec640 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -88,6 +88,10 @@ Style/AlignHash: Style/AlignParameters: Enabled: true +# Use && instead of and, use || instead of or +Style/AndOr: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1685d43c..0a24cae6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -7,12 +7,6 @@ - -# Offense count: 2 -# Cop supports --auto-correct. -Style/AndOr: - Enabled: false - # Offense count: 1 Style/BlockNesting: Max: 4 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a27b803..0219a4ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base helper_method :date_string def store_location - session[:return_to] = request.fullpath if request.get? and controller_name != "user_sessions" and controller_name != "sessions" + session[:return_to] = request.fullpath if request.get? && controller_name != "user_sessions" && controller_name != "sessions" end def after_sign_in_path_for(resource) From 99f773a04036c6eddd1a34308394436a49ba7c76 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:36:32 +0200 Subject: [PATCH 4/6] Style/Blocks Style/BlockNesting cops enabled --- .rubocop.yml | 8 ++++++++ .rubocop_todo.yml | 11 ----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index decec640..82c8d3e4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -92,6 +92,14 @@ Style/AlignParameters: Style/AndOr: Enabled: true +# avoid deep blocks nesting +Style/BlockNesting: + Max: 4 + +# use do instead of {...} in multiline blocks +Style/Blocks: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0a24cae6..4b51e808 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,17 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - - -# Offense count: 1 -Style/BlockNesting: - Max: 4 - -# Offense count: 2 -# Cop supports --auto-correct. -Style/Blocks: - Enabled: false - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. From 6e7e0c2cd36f5e914e2119eed839aeab466bb855 Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:37:50 +0200 Subject: [PATCH 5/6] Style/BracesAroundHashParameters enabled --- .rubocop.yml | 4 ++++ app/controllers/schedule_controller.rb | 2 +- config/initializers/devise.rb | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 82c8d3e4..a76eda33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -100,6 +100,10 @@ Style/BlockNesting: Style/Blocks: Enabled: true +# avoid redundunt curly braces when it is obvious that hash is used +Style/BracesAroundHashParameters: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/app/controllers/schedule_controller.rb b/app/controllers/schedule_controller.rb index 365d8bf2..2e3bc96e 100644 --- a/app/controllers/schedule_controller.rb +++ b/app/controllers/schedule_controller.rb @@ -2,7 +2,7 @@ class ScheduleController < ApplicationController layout "application" def index - @conference = Conference.includes(:rooms, {events: [:speakers, :track, :event_type]}).where("conferences.short_title" => params[:conference_id]).first + @conference = Conference.includes(:rooms, events: [:speakers, :track, :event_type]).where("conferences.short_title" => params[:conference_id]).first @rooms = @conference.rooms @events = @conference.events @dates = @conference.start_date..@conference.end_date diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index a71d3cdd..99546161 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -10,9 +10,9 @@ Devise.setup do |config| # Pass each provider to User model in :omniauth_providers (for open_id providers use their name) config.omniauth :open_id, name: 'novell', identifier: 'http://www.opensuse.org/openid/user' - config.omniauth :google_oauth2, Rails.application.secrets.google_key, Rails.application.secrets.google_secret, { - name: 'google', - scope: 'email' } + config.omniauth :google_oauth2, Rails.application.secrets.google_key, Rails.application.secrets.google_secret, + name: 'google', + scope: 'email' config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret # ==> Mailer Configuration From eb127b4f8c4f58558efc7471f53636bcdd3fd62c Mon Sep 17 00:00:00 2001 From: Artem Chernikov Date: Wed, 30 Jul 2014 23:43:00 +0200 Subject: [PATCH 6/6] Add new styles to be checked --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 10 ---------- app/controllers/event_attachments_controller.rb | 4 ++-- app/controllers/schedule_controller.rb | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a76eda33..235aa49a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -104,6 +104,10 @@ Style/Blocks: Style/BracesAroundHashParameters: Enabled: true +# +Style/CaseEquality: + Enabled: true + AllCops: Include: - '**/Rakefile' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4b51e808..e453a5a8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,16 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Enabled: false - -# Offense count: 1 -Style/CaseEquality: - Enabled: false - # Offense count: 20 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/ClassAndModuleChildren: diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index a54fc2a4..9c366eb5 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -66,11 +66,11 @@ class EventAttachmentsController < ApplicationController respond_to do |format| if @upload.save - format.html { + format.html do render json: [@upload.to_jq_upload].to_json, content_type: 'text/html', layout: false - } + end format.json do render json: [@upload.to_jq_upload].to_json, status: :created, location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) diff --git a/app/controllers/schedule_controller.rb b/app/controllers/schedule_controller.rb index 2e3bc96e..84a861b8 100644 --- a/app/controllers/schedule_controller.rb +++ b/app/controllers/schedule_controller.rb @@ -7,7 +7,7 @@ class ScheduleController < ApplicationController @events = @conference.events @dates = @conference.start_date..@conference.end_date - if @dates === Date.current + if @dates == Date.current @today = Date.current.strftime("%Y-%m-%d") else @today = @conference.start_date.strftime("%Y-%m-%d")