From 6cb11ff2f3dc02dd30dbbaadbe4f94d4ad63a123 Mon Sep 17 00:00:00 2001 From: nasia Date: Sat, 3 Jun 2017 13:48:49 +0300 Subject: [PATCH 1/4] Add Style/WordArray at rubocop.yml #1463 --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 8 -------- app/models/event_user.rb | 2 +- lib/tasks/version.rake | 2 +- spec/helpers/users_helper_spec.rb | 2 +- spec/models/user_spec.rb | 2 +- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c333e43a..de234a2a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -104,6 +104,10 @@ Style/TrailingBlankLines: Style/TrailingWhitespace: Enabled: true +# Check for array literals made up of word-like strings, that are not using the %w() syntax +Style/WordArray: + Enabled: true + # This cop checks for numeric comparisons that can be replaced by a predicate method. Style/ZeroLengthPredicate: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bc17a090..a7ea415b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -928,11 +928,3 @@ Style/UnneededInterpolation: Style/VariableNumber: Exclude: - 'spec/models/ticket_purchase_spec.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 3 diff --git a/app/models/event_user.rb b/app/models/event_user.rb index 64952a28..58adadad 100644 --- a/app/models/event_user.rb +++ b/app/models/event_user.rb @@ -1,6 +1,6 @@ class EventUser < ActiveRecord::Base # TODO Do we need these roles? - ROLES = [['Speaker', 'speaker'], ['Submitter', 'submitter'], ['Moderator', 'moderator']] + ROLES = [%w[Speaker speaker], %w[Submitter submitter], %w[Moderator moderator]] belongs_to :event belongs_to :user diff --git a/lib/tasks/version.rake b/lib/tasks/version.rake index 084ff181..e4005c15 100644 --- a/lib/tasks/version.rake +++ b/lib/tasks/version.rake @@ -2,7 +2,7 @@ namespace :data do desc 'Sets conference_id in all pre-existing PaperTrail::Version objects' task set_conference_in_versions: :environment do - PaperTrail::Version.where(conference_id: nil, item_type: ['Conference', 'Event']).each do |version| + PaperTrail::Version.where(conference_id: nil, item_type: %w[Conference Event]).each do |version| # All pre-existing versions are either of Conference or Event if version.item_type == 'Conference' version.update_attributes(conference_id: version.item_id) diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index dfc337e6..e0c2d3fd 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -4,7 +4,7 @@ describe UsersHelper, type: :helper do describe 'show_roles' do it 'formats the hash passed' do - roles = { 'organizer' => ['oSC16', 'oSC15'], 'cfp' => ['oSC16'] } + roles = { 'organizer' => %w[oSC16 oSC15], 'cfp' => ['oSC16'] } expect(show_roles(roles)).to eq 'Organizer (oSC16, oSC15), Cfp (oSC16)' end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d0517212..e742b993 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -282,7 +282,7 @@ describe User do it 'returns hash of role and conference' do expected_hash = { - 'organizer' => ['oSC16', 'oSC15'], + 'organizer' => %w[oSC16 oSC15], 'cfp' => ['oSC16'] } From 7a7fcced487de914c9bd2bfc9e4e51839413aa8e Mon Sep 17 00:00:00 2001 From: AEtherC0r3 Date: Tue, 6 Jun 2017 19:03:23 +0300 Subject: [PATCH 2/4] Replace .today with .current in program spec The cfp_open? method uses Date.current, so it should also be tested with Date.current and not Date.today Also, build was replaced with create to fix a false negative This is a partial fix for #1522 --- spec/models/program_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/program_spec.rb b/spec/models/program_spec.rb index ac720def..a2106791 100644 --- a/spec/models/program_spec.rb +++ b/spec/models/program_spec.rb @@ -141,7 +141,7 @@ describe Program do describe '#cfp_open?' do describe 'returns true' do it 'when there is an open Call for Papers for the conference' do - create(:cfp, start_date: Date.today - 2, end_date: Date.today, program_id: program.id) + create(:cfp, start_date: Date.current - 2, end_date: Date.current, program_id: program.id) expect(program.cfp_open?).to be true end end @@ -152,7 +152,7 @@ describe Program do end it 'when the Call for Papers period is over' do - build(:cfp, start_date: Date.today - 2, end_date: Date.today - 1, program_id: program.id) + create(:cfp, start_date: Date.current - 2, end_date: Date.current - 1, program_id: program.id) expect(program.cfp_open?).to be false end end From 5acb4a93392c613f3a43bbec04b5aae2e849d957 Mon Sep 17 00:00:00 2001 From: mdeniz Date: Fri, 9 Jun 2017 14:41:44 +0200 Subject: [PATCH 3/4] Split in 2 jobs Travis build --- .travis.yml | 9 ++++++--- travis_script.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 travis_script.sh diff --git a/.travis.yml b/.travis.yml index 0be912e1..6c83258b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,9 @@ before_script: - mysql -u root -e 'create database osem_test;' - RAILS_ENV=test bundle exec rake db:migrate --trace script: - - 'bundle exec rubocop -Dc .rubocop.yml' - - 'bundle exec haml-lint app/views' - - 'bundle exec rspec --color --format documentation' + - "./travis_script.sh $TEST_SUITE" +env: + - TEST_SUITE=rspec + - TEST_SUITE=linters +matrix: + fast_finish: true diff --git a/travis_script.sh b/travis_script.sh new file mode 100755 index 00000000..77ca2329 --- /dev/null +++ b/travis_script.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# This script runs the test suites for the CI build + +# Be verbose and fail script on the first error +set -xe + +# By default: all test runs +if [ -z $1 ]; then + TEST_SUITE="all" +else + TEST_SUITE="$1" +fi + +case $TEST_SUITE in + linters) + bundle exec rubocop -Dc .rubocop.yml + bundle exec haml-lint app/views + ;; + rspec) + bundle exec rspec --color --format documentation + ;; + *) + bundle exec rubocop -Dc .rubocop.yml + bundle exec haml-lint app/views + bundle exec rspec --color --format documentation + ;; +esac From ebe1ca374da3366e29efe1e63a65d618cdfe9fe5 Mon Sep 17 00:00:00 2001 From: mdeniz Date: Fri, 9 Jun 2017 14:41:51 +0200 Subject: [PATCH 4/4] Fix the Travis failure in the last PR about axlsx dependencies --- Gemfile | 3 ++- Gemfile.lock | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 497c56b1..76c49ce3 100644 --- a/Gemfile +++ b/Gemfile @@ -128,6 +128,7 @@ gem 'country_select' gem 'prawn_rails' # to render XLS spreadsheets +gem 'axlsx', git: 'https://github.com/randym/axlsx.git' gem 'axlsx_rails' # as error catcher @@ -178,7 +179,7 @@ gem 'cloudinary' # for setting app configuration in the environment gem 'dotenv-rails' -# For countable.js +# For countable.js gem "countable-rails", "~> 0.0.1" # Both are not in a group as we use it also for rake data:demo diff --git a/Gemfile.lock b/Gemfile.lock index 90ae82f0..e1c8218f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,13 @@ +GIT + remote: https://github.com/randym/axlsx.git + revision: c8ac844572b25fda358cc01d2104720c4c42f450 + specs: + axlsx (2.1.0.pre) + htmlentities (~> 4.3.4) + mimemagic (~> 0.3) + nokogiri (>= 1.6.6) + rubyzip (>= 1.2.1) + GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ @@ -65,10 +75,6 @@ GEM awesome_nested_set (3.0.0.rc.5) activerecord (>= 4.0.0, < 5) aws_cf_signer (0.1.3) - axlsx (2.0.1) - htmlentities (~> 4.3.1) - nokogiri (>= 1.4.1) - rubyzip (~> 1.2.1) axlsx_rails (0.2.0) axlsx (>= 2.0.1) rails (>= 3.1) @@ -262,6 +268,7 @@ GEM mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.99.1) + mimemagic (0.3.2) mina (0.3.8) open4 (~> 1.3.4) rake @@ -551,6 +558,7 @@ DEPENDENCIES ahoy_matey autoprefixer-rails awesome_nested_set (~> 3.0.0.rc.5) + axlsx! axlsx_rails bootstrap-sass (~> 3.3.4.1) bootstrap-switch-rails (~> 3.0.0)