diff --git a/.rubocop.yml b/.rubocop.yml index da59ef22..9c4550a3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,31 +11,79 @@ Lint/DeprecatedClassMethods: Style/NilComparison: Enabled: true +# Use one empty line between method definitions Style/EmptyLineBetweenDefs: Enabled: true -# Offense count: 4 -# Cop supports --auto-correct. +# There should be only one empty line in designated place Style/EmptyLines: + Enabled: true + +# Keep a blank line before and after private. +Style/EmptyLinesAroundAccessModifier: + Enabled: true + +# Do not insert empty line after class definition and before closing class +Style/EmptyLinesAroundBody: + Enabled: true + +# Use hash literal {} instead of Hash.new +Style/EmptyLiteral: + Enabled: true + +# Prefer `each` over `for i` +Style/For: + Enabled: true + +# Wrap your assignment in condition if you mean it, otherwise it is most likely equality check +Lint/AssignmentInCondition: + Enabled: true + +# Align blocks of code properly +Lint/BlockAlignment: + Enabled: true + +# Do not use literal in conditions. We have it enabled for now +Lint/LiteralInCondition: Enabled: false +# Prefer `Kernel#loop -> break` over `begin -> while` +Lint/Loop: + Enabled: true + +# do not put space before arguments when they are in parentheses +Lint/ParenthesesAsGroupedExpression: + Enabled: true + +# Offense count: 13 +# Cop supports --auto-correct. +Lint/RescueException: + Enabled: true + # Offense count: 1 -Style/EmptyLinesAroundAccessModifier: +Lint/ShadowingOuterLocalVariable: Enabled: false -# Offense count: 21 +# Offense count: 5 # Cop supports --auto-correct. -Style/EmptyLinesAroundBody: +Lint/UnusedBlockArgument: Enabled: false # Offense count: 2 # Cop supports --auto-correct. -Style/EmptyLiteral: +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 6 +Lint/UselessAssignment: Enabled: false # Offense count: 1 -# Configuration parameters: Exclude. -Style/FileName: +Lint/Void: + Enabled: false + +# Offense count: 17 +Style/AccessorMethodName: Enabled: false AllCops: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0b6e7d2b..2839ff76 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,58 +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: 3 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - -# Offense count: 4 -Lint/BlockAlignment: - Enabled: false - -# Offense count: 1 -Lint/LiteralInCondition: - Enabled: false - -# Offense count: 2 -Lint/Loop: - Enabled: false - -# Offense count: 3 -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -# Offense count: 13 -# Cop supports --auto-correct. -Lint/RescueException: - Enabled: false - -# Offense count: 1 -Lint/ShadowingOuterLocalVariable: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - -# Offense count: 6 -Lint/UselessAssignment: - Enabled: false - -# Offense count: 1 -Lint/Void: - Enabled: false - -# Offense count: 17 -Style/AccessorMethodName: - Enabled: false - # Offense count: 10 # Cop supports --auto-correct. # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. @@ -156,41 +104,11 @@ Style/DotPosition: Style/DoubleNegation: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs. -Style/EmptyLineBetweenDefs: - Enabled: false - -# Offense count: 4 -# Cop supports --auto-correct. -Style/EmptyLines: - Enabled: false - -# Offense count: 1 -Style/EmptyLinesAroundAccessModifier: - Enabled: false - -# Offense count: 21 -# Cop supports --auto-correct. -Style/EmptyLinesAroundBody: - Enabled: false - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Enabled: false - # Offense count: 1 # Configuration parameters: Exclude. Style/FileName: Enabled: false -# Offense count: 1 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/For: - Enabled: false - # Offense count: 8 # Configuration parameters: MinBodyLength. Style/GuardClause: diff --git a/Gemfile b/Gemfile index 6720b8db..0de00755 100644 --- a/Gemfile +++ b/Gemfile @@ -128,3 +128,7 @@ group :test do # Extracted from RSpec 3 stub_model and mock_model gem 'rspec-activemodel-mocks' end + +group :development, :test do + gem 'debugger' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6f8468e9..e5ead004 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,7 @@ GEM coffee-script-source execjs coffee-script-source (1.7.0) + columnize (0.8.9) coveralls (0.7.0) multi_json (~> 1.3) rest-client @@ -99,6 +100,12 @@ GEM d3_rails (3.4.6) railties (>= 3.1.0) database_cleaner (1.3.0) + debugger (1.6.8) + columnize (>= 0.3.1) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.3.5) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.3.5) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -399,6 +406,7 @@ DEPENDENCIES coveralls d3_rails database_cleaner + debugger devise factory_girl_rails font-awesome-rails diff --git a/app/controllers/admin/difficulty_levels_controller.rb b/app/controllers/admin/difficulty_levels_controller.rb index 17335117..a52cefcf 100644 --- a/app/controllers/admin/difficulty_levels_controller.rb +++ b/app/controllers/admin/difficulty_levels_controller.rb @@ -25,6 +25,5 @@ class Admin::DifficultyLevelsController < ApplicationController flash[:error] = "Difficulty Levels update failed." redirect_to(admin_conference_difficulty_levels_path(:conference_id => @conference.short_title)) end - end end diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 6b664ec6..ffabf501 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -18,7 +18,7 @@ module Admin @mystates = [] @mytypes = [] - @eventstats = Hash.new + @eventstats = {} @totallength = 0 @machine_states.each do |mystate| @@ -50,7 +50,7 @@ module Admin @totallength += myevent.event_type.length end - if @eventstats[mytype.title] == nil + if @eventstats[mytype.title].nil? @eventstats[mytype.title] = { 'count' => events_mytype.count, 'length' => events_mytype.count * mytype.length } end @@ -150,7 +150,7 @@ module Admin @event = Event.find(params[:id]) @ratings = @event.votes.includes(:user) - if votes = current_user.votes.find_by_event_id(params[:id]) + if (votes = current_user.votes.find_by_event_id(params[:id])) votes.update_attributes(rating: params[:rating]) else @myvote = @event.votes.build diff --git a/app/controllers/admin/questions_controller.rb b/app/controllers/admin/questions_controller.rb index d23e8da7..838f587e 100644 --- a/app/controllers/admin/questions_controller.rb +++ b/app/controllers/admin/questions_controller.rb @@ -79,7 +79,7 @@ class Admin::QuestionsController < ApplicationController a.delete end flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}" - end + end rescue ActiveRecord::RecordInvalid flash[:error] = "Could not delete question." end @@ -91,6 +91,6 @@ class Admin::QuestionsController < ApplicationController end @questions = Question.where(:global => true).all | Question.where(:conference_id => @conference.id) - @questions_conference = @conference.questions + @questions_conference = @conference.questions end end diff --git a/app/controllers/admin/social_events_controller.rb b/app/controllers/admin/social_events_controller.rb index 3411fc44..336e7cef 100644 --- a/app/controllers/admin/social_events_controller.rb +++ b/app/controllers/admin/social_events_controller.rb @@ -11,7 +11,5 @@ class Admin::SocialEventsController < ApplicationController else redirect_to(admin_conference_social_events_path(:conference_id => @conference.short_title), :notice => 'Social events update failed.') end - end - end diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index feee3a34..758c46f9 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -48,7 +48,7 @@ module Admin if @events.count > 0 start_date = @events.minimum('created_at').strftime('%Y-%m-%d') end_date = @events.maximum('created_at').strftime('%Y-%m-%d') - unless start_date == nil || end_date == nil + unless start_date.nil? || end_date.nil? @events_time = var_time(start_date, end_date, @events, 'created_at') end end @@ -87,7 +87,7 @@ module Admin typelength += myevent.event_type.length @totallength += myevent.event_type.length end - if @eventstats[mytype.title] == nil + if @eventstats[mytype.title].nil? @eventstats[mytype.title] = { 'count' => events_mytype.count, 'length' => events_mytype.count * mytype.length } end diff --git a/app/controllers/admin/venue_controller.rb b/app/controllers/admin/venue_controller.rb index 4c8696d6..ccef1259 100644 --- a/app/controllers/admin/venue_controller.rb +++ b/app/controllers/admin/venue_controller.rb @@ -19,5 +19,4 @@ class Admin::VenueController < ApplicationController @venue = @conference.venue render :venue_info end - end diff --git a/app/controllers/event_attachments_controller.rb b/app/controllers/event_attachments_controller.rb index a7e63b47..7a7c1514 100644 --- a/app/controllers/event_attachments_controller.rb +++ b/app/controllers/event_attachments_controller.rb @@ -71,8 +71,10 @@ class EventAttachmentsController < ApplicationController :content_type => 'text/html', :layout => false } - format.json { render json: [@upload.to_jq_upload].to_json, status: :created, - location: conference_proposal_event_attachment_path(@upload.event.conference.short_title, @upload.event, @upload) } + 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) + end else format.html { render action: "new" } format.json { render json: @upload.errors, status: :unprocessable_entity } diff --git a/app/controllers/schedule_controller.rb b/app/controllers/schedule_controller.rb index 2a00ae7c..de984489 100644 --- a/app/controllers/schedule_controller.rb +++ b/app/controllers/schedule_controller.rb @@ -1,5 +1,4 @@ class ScheduleController < ApplicationController - layout "application" def index @@ -14,5 +13,4 @@ class ScheduleController < ApplicationController @today = @conference.start_date.strftime("%Y-%m-%d") end end - end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 61b4088f..4fa0341c 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -13,7 +13,7 @@ module Users openid = Openid.find_for_oauth(auth_hash) # Get or create openid # If openid exists and is associated with a user, sign in with associated user, # even if the email of the associated user and the email of the provided openid are different - unless user = openid.user + unless (user = openid.user) user = User.find_for_auth(auth_hash, current_user) # Get or create users end diff --git a/app/mailers/mailbot.rb b/app/mailers/mailbot.rb index a7bd0807..ea40fa12 100644 --- a/app/mailers/mailbot.rb +++ b/app/mailers/mailbot.rb @@ -6,7 +6,6 @@ class Mailbot < ActionMailer::Base person.email, conference.email_settings.registration_subject, conference.email_settings.generate_registration_email(conference, person)) - end def acceptance_mail(event) @@ -16,7 +15,6 @@ class Mailbot < ActionMailer::Base person.email, conference.email_settings.accepted_subject, conference.email_settings.generate_accepted_email(event)) - end def rejection_mail(event) @@ -63,5 +61,4 @@ class Mailbot < ActionMailer::Base :subject => subject, :body => body) end - end diff --git a/app/models/conference.rb b/app/models/conference.rb index 543f64d0..fae89ad8 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -102,7 +102,6 @@ class Conference < ActiveRecord::Base return media_types end - ## # Checks if the user is registered to the conference # diff --git a/app/models/datatable.rb b/app/models/datatable.rb index 922e85b6..339d4897 100644 --- a/app/models/datatable.rb +++ b/app/models/datatable.rb @@ -18,7 +18,6 @@ class Datatable } end - def data [] end diff --git a/app/models/dietary_choice.rb b/app/models/dietary_choice.rb index ffe896b7..961346b8 100644 --- a/app/models/dietary_choice.rb +++ b/app/models/dietary_choice.rb @@ -3,5 +3,4 @@ class DietaryChoice < ActiveRecord::Base belongs_to :conference has_many :registrations - end diff --git a/app/models/event.rb b/app/models/event.rb index ae2830e7..53d696e0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -197,11 +197,15 @@ class Event < ActiveRecord::Base errors.add(:user_biography, 'must be filled out') if submitter.biography_word_count == 0 end + # TODO: create a module to be mixed into model to perform same operation + # venue.rb has same functionality which can be shared + # TODO: rename guid to UUID as guid is specifically Microsoft term def generate_guid - begin - guid = SecureRandom.urlsafe_base64 - end while self.class.where(guid: guid).exists? - self.guid = guid + loop do + @guid = SecureRandom.urlsafe_base64 + break if !self.class.where(guid: guid).any? + end + self.guid = @guid end def set_week diff --git a/app/models/event_attachment.rb b/app/models/event_attachment.rb index e90e0f23..98d3c547 100644 --- a/app/models/event_attachment.rb +++ b/app/models/event_attachment.rb @@ -18,12 +18,9 @@ class EventAttachment < ActiveRecord::Base "delete_url" => conference_proposal_event_attachment_path(self.event.conference.short_title, self.event_id, self.id), "delete_type" => "DELETE" } - end #:path => ":rails_root/public/system/:attachment/:id/:style/:filename", # :url => "/system/:attachment/:id/:style/:filename" #has_paper_trail :meta => {:associated_id => :event_id, :associated_type => "Event"} - - end diff --git a/app/models/openid.rb b/app/models/openid.rb index 2795cd44..2fc1c245 100644 --- a/app/models/openid.rb +++ b/app/models/openid.rb @@ -11,7 +11,7 @@ class Openid < ActiveRecord::Base if openid.new_record? openid.email = auth.info.email - if existing_openid = Openid.where(email: openid.email).first + if (existing_openid = Openid.where(email: openid.email).first) openid.user_id = existing_openid.user_id end end diff --git a/app/models/room.rb b/app/models/room.rb index 6ce73d1e..f4611a7d 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -15,5 +15,4 @@ class Room < ActiveRecord::Base # end while Person.where(:guid => guid).exists? self.guid = guid end - end diff --git a/app/models/track.rb b/app/models/track.rb index 94201a73..beb033c9 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -14,5 +14,4 @@ class Track < ActiveRecord::Base # end while Person.where(:guid => guid).exists? self.guid = guid end - end diff --git a/app/models/venue.rb b/app/models/venue.rb index abf6e22d..21934332 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -11,13 +11,17 @@ class Venue < ActiveRecord::Base content_type: [/jpg/, /jpeg/, /png/, /gif/], size: { in: 0..500.kilobytes } accepts_nested_attributes_for :lodgings, allow_destroy: true + private + # TODO: create a module to be mixed into model to perform same operation + # event.rb has same functionality which can be shared + # TODO: rename guid to UUID as guid is specifically Microsoft term def generate_guid - begin - guid = SecureRandom.urlsafe_base64 - end while Venue.where(:guid => guid).exists? - self.guid = guid + loop do + @guid = SecureRandom.urlsafe_base64 + break if !Venue.where(:guid => guid).any? + end + self.guid = @guid end - end diff --git a/app/models/vote.rb b/app/models/vote.rb index 9d174ba6..2ef9729f 100644 --- a/app/models/vote.rb +++ b/app/models/vote.rb @@ -4,5 +4,4 @@ class Vote < ActiveRecord::Base belongs_to :user belongs_to :event delegate :name, to: :user - end diff --git a/config/boot.rb b/config/boot.rb index 4489e586..f2830ae3 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -3,4 +3,4 @@ require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) diff --git a/config/environment.rb b/config/environment.rb index 6b0a63d2..760642c1 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,7 +7,7 @@ begin CONFIG = YAML.load_file(path)[Rails.env] rescue Exception puts "Error while parsing config file #{path}" - CONFIG = Hash.new + CONFIG = {} end # Initialize the rails application diff --git a/db/migrate/20121223122842_create_venue_table.rb b/db/migrate/20121223122842_create_venue_table.rb index 0c7c0c57..38e7115f 100644 --- a/db/migrate/20121223122842_create_venue_table.rb +++ b/db/migrate/20121223122842_create_venue_table.rb @@ -15,5 +15,4 @@ class CreateVenueTable < ActiveRecord::Migration def down drop_table :venues end - end diff --git a/db/migrate/20130113105652_create_email_table.rb b/db/migrate/20130113105652_create_email_table.rb index ba6bf60e..0d566bcd 100644 --- a/db/migrate/20130113105652_create_email_table.rb +++ b/db/migrate/20130113105652_create_email_table.rb @@ -12,7 +12,6 @@ class CreateEmailTable < ActiveRecord::Migration t.text :confirmed_email_template t.timestamps end - end def down diff --git a/db/migrate/20130515125823_change_attachment_default.rb b/db/migrate/20130515125823_change_attachment_default.rb index f2acc537..89701f12 100644 --- a/db/migrate/20130515125823_change_attachment_default.rb +++ b/db/migrate/20130515125823_change_attachment_default.rb @@ -2,6 +2,7 @@ class ChangeAttachmentDefault < ActiveRecord::Migration def up change_column_default(:event_attachments, :public, true) end + def down change_column_default(:event_attachments, :public, nil) end diff --git a/db/migrate/20131229072532_registrations_vchoices.rb b/db/migrate/20131229072532_registrations_vchoices.rb index 76f430e4..ae1d824e 100644 --- a/db/migrate/20131229072532_registrations_vchoices.rb +++ b/db/migrate/20131229072532_registrations_vchoices.rb @@ -1,6 +1,6 @@ class RegistrationsVchoices < ActiveRecord::Migration def up - create_table :registrations_vchoices, :id => false do |t| + create_table :registrations_vchoices, :id => false do |t| t.references :registration, :vchoice end end diff --git a/db/migrate/20140610163947_create_event_users.rb b/db/migrate/20140610163947_create_event_users.rb index 91043d20..7d0fdbe3 100644 --- a/db/migrate/20140610163947_create_event_users.rb +++ b/db/migrate/20140610163947_create_event_users.rb @@ -30,6 +30,5 @@ class CreateEventUsers < ActiveRecord::Migration record.comment = ep.comment record.save! end - end end diff --git a/db/migrate/20140701123203_add_events_per_week_to_conference.rb b/db/migrate/20140701123203_add_events_per_week_to_conference.rb index 70110d24..04163176 100644 --- a/db/migrate/20140701123203_add_events_per_week_to_conference.rb +++ b/db/migrate/20140701123203_add_events_per_week_to_conference.rb @@ -65,10 +65,9 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration conference.save end - # Cumulate the previous weeks to get a snapshot TempConference.all.each do |conference| - hash = conference.events_per_week.sort.to_h + hash = conference.events_per_week.sort.to_hash previous = nil hash.each do |week, values| diff --git a/db/seeds.rb b/db/seeds.rb index 5d04058d..8c47da2c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,7 +18,7 @@ answer_no = Answer.create(:title => "No") questions_yes_no = ["Do you need handicapped access to the venue?", "Are you attending with partner?", "Will you attend the social event(s)?", "Will you stay at suggested hotel?"] -for i in questions_yes_no do +questions_yes_no.each do |i| q = Question.create(:title => i, :question_type_id => qtype_yesno.id, :global => true) Qanswer.create(:question_id => q.id, :answer_id => answer_no.id) diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index af30caa0..9c63e291 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -406,7 +406,7 @@ describe Conference do end describe '#difficulty_levels' do - before (:each) do + before do subject.email_settings = create(:email_settings) @easy = create(:difficulty_level, title: 'Easy', color: '#000000') @hard = create(:difficulty_level, title: 'Hard', color: '#ffffff') @@ -503,7 +503,7 @@ describe Conference do end describe 'event type distribution' do - before (:each) do + before do subject.email_settings = create(:email_settings) @workshop = create(:event_type, title: 'Workshop', color: '#000000') @lecture = create(:event_type, title: 'Lecture', color: '#ffffff') @@ -599,7 +599,7 @@ describe Conference do end describe 'tracks_distribution' do - before (:each) do + before do subject.email_settings = create(:email_settings) @track_one = create(:track, name: 'Track One', color: '#000000') @track_two = create(:track, name: 'Track Two', color: '#ffffff') diff --git a/spec/support/login_macros.rb b/spec/support/login_macros.rb index e8f22147..716cbbbe 100644 --- a/spec/support/login_macros.rb +++ b/spec/support/login_macros.rb @@ -1,5 +1,4 @@ module LoginMacros - include Warden::Test::Helpers Warden.test_mode! @@ -10,5 +9,4 @@ module LoginMacros def sign_out logout(:user) end - end diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/home/index.html.haml_spec.rb index 32599a2a..6affa8d8 100644 --- a/spec/views/home/index.html.haml_spec.rb +++ b/spec/views/home/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'home/index' do - it "renders _conference partial for each conference" do + it "renders _conference partial for each conference" do allow(view).to receive(:date_string).and_return("January 17 - 21 2014") assign(:current, [create(:conference), create(:conference)]) render