From ad65defda007bf54303346e260793510ef27eef4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 6 Jan 2018 20:07:52 +0100 Subject: [PATCH 1/4] Add rubocop rspec cops to rubocop config --- .rubocop.yml | 1 + Gemfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index f14616b6e..4807f0453 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,5 @@ inherit_from: .rubocop_todo.yml +require: rubocop-rspec AllCops: DisplayCopNames: true diff --git a/Gemfile b/Gemfile index d2624de93..a67e65cdf 100644 --- a/Gemfile +++ b/Gemfile @@ -88,6 +88,7 @@ group :development do gem 'capistrano3-delayed-job', '~> 1.7.3' gem 'mdl', '~> 0.4.0', require: false gem 'rubocop', '~> 0.52.1', require: false + gem 'rubocop-rspec', '~> 1.21.0', require: false gem 'rvm1-capistrano3', '~> 1.4.0', require: false gem 'scss_lint', '~> 0.54.0', require: false gem 'web-console', '~> 3.3.0' From a79232ef011ff18076f160c7bdef9bc3b792a527 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 6 Jan 2018 20:18:24 +0100 Subject: [PATCH 2/4] Enable RSpec/BeforeAfterAll rule and fix all issues --- .rubocop.yml | 3 ++ spec/lib/manager_authenticator_spec.rb | 52 ++++++++++++-------------- spec/lib/tasks/settings_spec.rb | 4 -- spec/models/organization_spec.rb | 12 +++--- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4807f0453..61208ad4b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,3 +24,6 @@ Metrics/LineLength: Layout/IndentationConsistency: EnforcedStyle: rails + +RSpec/BeforeAfterAll: + Enabled: true diff --git a/spec/lib/manager_authenticator_spec.rb b/spec/lib/manager_authenticator_spec.rb index 8f27a61d3..34f1f9819 100644 --- a/spec/lib/manager_authenticator_spec.rb +++ b/spec/lib/manager_authenticator_spec.rb @@ -1,66 +1,60 @@ require 'rails_helper' describe ManagerAuthenticator do + let(:authenticator) { ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") } + describe 'initialization params' do it 'should cause auth to return false if blank login' do - authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905") - expect(authenticator.auth).to be false + blank_login_authenticator = ManagerAuthenticator.new(login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905") + expect(blank_login_authenticator.auth).to be false end it 'should cause auth to return false if blank user_key' do - authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905") - expect(authenticator.auth).to be false + blank_user_key_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905") + expect(blank_user_key_authenticator.auth).to be false end it 'should cause auth to return false if blank date' do - authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "") - expect(authenticator.auth).to be false + blank_date_authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "") + expect(blank_date_authenticator.auth).to be false end end describe '#auth' do - before(:all) do - @authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") - end - it 'should return false if not manager_exists' do - allow(@authenticator).to receive(:manager_exists?).and_return(false) - allow(@authenticator).to receive(:application_authorized?).and_return(true) + allow(authenticator).to receive(:manager_exists?).and_return(false) + allow(authenticator).to receive(:application_authorized?).and_return(true) - expect(@authenticator.auth).to be false + expect(authenticator.auth).to be false end it 'should return false if not application_authorized' do - allow(@authenticator).to receive(:manager_exists?).and_return(true) - allow(@authenticator).to receive(:application_authorized?).and_return(false) + allow(authenticator).to receive(:manager_exists?).and_return(true) + allow(authenticator).to receive(:application_authorized?).and_return(false) - expect(@authenticator.auth).to be false + expect(authenticator.auth).to be false end it 'should return ok if manager_exists and application_authorized' do - allow(@authenticator).to receive(:manager_exists?).and_return(true) - allow(@authenticator).to receive(:application_authorized?).and_return(true) + allow(authenticator).to receive(:manager_exists?).and_return(true) + allow(authenticator).to receive(:application_authorized?).and_return(true) - expect(@authenticator.auth).to be_truthy + expect(authenticator.auth).to be_truthy end end describe 'SOAP' do - before(:all) do - @authenticator = ManagerAuthenticator.new(login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905") - end - it 'should call the verification user method' do message = { ub: {user_key: "31415926", date: "20151031135905"} } - allow(@authenticator).to receive(:application_authorized?).and_return(true) - expect(@authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message) - @authenticator.auth + allow(authenticator).to receive(:application_authorized?).and_return(true) + expect(authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: message) + authenticator.auth end it 'should call the permissions check method' do - allow(@authenticator).to receive(:manager_exists?).and_return(true) - expect(@authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} }) - @authenticator.auth + allow(authenticator).to receive(:manager_exists?).and_return(true) + expect(authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} }) + authenticator.auth end end end diff --git a/spec/lib/tasks/settings_spec.rb b/spec/lib/tasks/settings_spec.rb index 1311763bf..8a48dce15 100644 --- a/spec/lib/tasks/settings_spec.rb +++ b/spec/lib/tasks/settings_spec.rb @@ -15,10 +15,6 @@ describe 'Settings Rake' do Rake.application.invoke_task 'settings:per_page_code_migration' end - after(:all) do - Setting['per_page_code_head'] = '' - end - context 'Neither per_page_code_head or per_page_code Settings exist' do before do Setting.where(key: 'per_page_code').first&.destroy diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index 402c0d092..1aeca4088 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -45,7 +45,7 @@ describe Organization do end describe "self.search" do - before(:all) {@organization = create(:organization, name: "Watershed", user: create(:user, phone_number: "333"))} + let!(:organization) { create(:organization, name: "Watershed", user: create(:user, phone_number: "333")) } it "returns no results if search term is empty" do expect(Organization.search(" ").size).to eq(0) @@ -55,19 +55,19 @@ describe Organization do expect(Organization.search("Greenpeace").size).to eq 0 search = Organization.search("Tershe") expect(search.size).to eq 1 - expect(search.first).to eq @organization + expect(search.first).to eq organization end scenario "finds by users email" do - search = Organization.search(@organization.user.email) + search = Organization.search(organization.user.email) expect(search.size).to eq 1 - expect(search.first).to eq @organization + expect(search.first).to eq organization end scenario "finds by users phone number" do - search = Organization.search(@organization.user.phone_number) + search = Organization.search(organization.user.phone_number) expect(search.size).to eq 1 - expect(search.first).to eq @organization + expect(search.first).to eq organization end end end From 541026025f9b023fd5a658747d54f7d8f2b41f5a Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 6 Jan 2018 20:41:17 +0100 Subject: [PATCH 3/4] Update rubocop config with some rspec cops rules without issues --- .rubocop.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 61208ad4b..eb2db80ef 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,5 +25,20 @@ Metrics/LineLength: Layout/IndentationConsistency: EnforcedStyle: rails +RSpec/AlignLeftLetBrace: + Enabled: false + +RSpec/AlignRightLetBrace: + Enabled: false + +RSpec/AnyInstance: + Enabled: false + +RSpec/AroundBlock: + Enabled: true + +RSpec/BeEql: + Enabled: true + RSpec/BeforeAfterAll: Enabled: true From 19de0e2e33978228c04760653ee121f7e54a0f36 Mon Sep 17 00:00:00 2001 From: "depfu[bot]" Date: Sat, 6 Jan 2018 19:55:39 +0000 Subject: [PATCH 4/4] Upgrade unicorn to version 5.4.0 --- Gemfile | 2 +- Gemfile.lock | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index a67e65cdf..8c47ee92c 100644 --- a/Gemfile +++ b/Gemfile @@ -50,7 +50,7 @@ gem 'sprockets', '~> 3.7.1' gem 'turbolinks', '~> 2.5.3' gem 'turnout', '~> 2.4.0' gem 'uglifier', '~> 3.2.0' -gem 'unicorn', '~> 5.3.0' +gem 'unicorn', '~> 5.4.0' gem 'whenever', '~> 0.9.7', require: false source 'https://rails-assets.org' do diff --git a/Gemfile.lock b/Gemfile.lock index 6b0db9a4a..9d960b418 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -228,7 +228,7 @@ GEM activerecord kaminari-core (= 1.1.1) kaminari-core (1.1.1) - kgio (2.11.0) + kgio (2.11.1) knapsack_pro (0.53.0) rake kramdown (1.14.0) @@ -301,7 +301,7 @@ GEM cocaine (~> 0.5.5) mime-types mimemagic (~> 0.3.0) - parallel (1.11.2) + parallel (1.12.1) paranoia (2.4.0) activerecord (>= 4.0, < 5.2) parser (2.4.0.2) @@ -354,7 +354,7 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.2.2) rake - raindrops (0.18.0) + raindrops (0.19.0) rake (12.3.0) redcarpet (3.4.0) referer-parser (0.3.0) @@ -382,14 +382,16 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) - rubocop (0.49.1) + rubocop (0.52.1) parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) + parser (>= 2.4.0.2, < 3.0) powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) + rubocop-rspec (1.21.0) + rubocop (>= 0.52.0) + ruby-progressbar (1.9.0) rubyzip (1.2.1) rvm1-capistrano3 (1.4.0) capistrano (~> 3.0) @@ -463,7 +465,7 @@ GEM uglifier (3.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.0) - unicorn (5.3.0) + unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) uniform_notifier (1.10.0) @@ -552,7 +554,8 @@ DEPENDENCIES rinku (~> 2.0.2) rollbar (~> 2.15.5) rspec-rails (~> 3.6) - rubocop (~> 0.49.1) + rubocop (~> 0.52.1) + rubocop-rspec (~> 1.21.0) rubyzip (~> 1.2.0) rvm1-capistrano3 (~> 1.4.0) sass-rails (~> 5.0, >= 5.0.4) @@ -566,7 +569,7 @@ DEPENDENCIES turbolinks (~> 2.5.3) turnout (~> 2.4.0) uglifier (~> 3.2.0) - unicorn (~> 5.3.0) + unicorn (~> 5.4.0) web-console (~> 3.3.0) whenever (~> 0.9.7)