From 9ac5ace5997bb6d208a9e1ea32366db2e3d089eb Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Thu, 13 Oct 2016 17:01:25 -0500 Subject: [PATCH] update to rails 5 --- .rubocop.yml | 8 ++ Gemfile | 3 +- Gemfile.lock | 107 ++++++++++--------- bin/spring | 2 +- circle.yml | 1 + config/application.rb | 2 - config/environments/production.rb | 2 +- config/environments/test.rb | 5 +- spec/controllers/catalog_controller_spec.rb | 6 +- spec/controllers/exhibits_controller_spec.rb | 24 ++--- spec/controllers/pages_controller_spec.rb | 2 +- spec/rails_helper.rb | 2 + 12 files changed, 88 insertions(+), 76 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index db0bb3be..b263a973 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -35,6 +35,9 @@ Metrics/ClassLength: Metrics/MethodLength: Enabled: false +Metrics/BlockLength: + Max: 28 + Style/BlockDelimiters: Exclude: - 'spec/**/*' @@ -101,6 +104,11 @@ Rails/Date: Rails/TimeZone: Enabled: false +Rails/DynamicFindBy: + Exclude: + - 'app/controllers/exhibits_controller.rb' + - 'app/decorators/applies_title_from_slug.rb' + RSpec/ExampleWording: CustomTransform: be: is diff --git a/Gemfile b/Gemfile index 5ae06782..79f2ad97 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.7.1' +gem 'rails', '5.0.0.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets @@ -50,6 +50,7 @@ group :development, :test do gem 'capistrano-passenger' gem 'capistrano-rails-console' gem 'database_cleaner' + gem 'rails-controller-testing' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 74bbc6db..8ded4c23 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: git://github.com/pulibrary/pul_assets.git - revision: afaa2495a4579c4c6154cb672106d2fad15438ac + revision: 84dc633f5ff39167b4f7e7acf2517fffda630f0f specs: pul-assets (0.2.2) bourbon (~> 4.2.6) @@ -37,40 +37,42 @@ GIT GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.7.1) - actionpack (= 4.2.7.1) - actionview (= 4.2.7.1) - activejob (= 4.2.7.1) + actioncable (5.0.0.1) + actionpack (= 5.0.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.7.1) - actionview (= 4.2.7.1) - activesupport (= 4.2.7.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.0.1) + actionview (= 5.0.0.1) + activesupport (= 5.0.0.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.7.1) - activesupport (= 4.2.7.1) + actionview (5.0.0.1) + activesupport (= 5.0.0.1) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.7.1) - activesupport (= 4.2.7.1) - globalid (>= 0.3.0) - activemodel (4.2.7.1) - activesupport (= 4.2.7.1) - builder (~> 3.1) - activerecord (4.2.7.1) - activemodel (= 4.2.7.1) - activesupport (= 4.2.7.1) - arel (~> 6.0) - activesupport (4.2.7.1) + activejob (5.0.0.1) + activesupport (= 5.0.0.1) + globalid (>= 0.3.6) + activemodel (5.0.0.1) + activesupport (= 5.0.0.1) + activerecord (5.0.0.1) + activemodel (= 5.0.0.1) + activesupport (= 5.0.0.1) + arel (~> 7.0) + activesupport (5.0.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) acts-as-taggable-on (4.0.0) activerecord (>= 4.0) @@ -80,7 +82,7 @@ GEM almond-rails (0.0.3) rails (>= 4.2, < 6) amq-protocol (2.0.1) - arel (6.0.3) + arel (7.1.4) ast (2.3.0) autoprefixer-rails (6.5.1) execjs @@ -283,6 +285,7 @@ GEM net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (3.2.0) + nio4r (1.2.1) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) normalize-rails (3.0.3) @@ -323,33 +326,36 @@ GEM pry (~> 0.10) pry-rails (0.3.4) pry (>= 0.9.10) - rack (1.6.4) + rack (2.0.1) rack-protection (1.5.3) rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.7.1) - actionmailer (= 4.2.7.1) - actionpack (= 4.2.7.1) - actionview (= 4.2.7.1) - activejob (= 4.2.7.1) - activemodel (= 4.2.7.1) - activerecord (= 4.2.7.1) - activesupport (= 4.2.7.1) + rails (5.0.0.1) + actioncable (= 5.0.0.1) + actionmailer (= 5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) + activemodel (= 5.0.0.1) + activerecord (= 5.0.0.1) + activesupport (= 5.0.0.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.7.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) + railties (= 5.0.0.1) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.1) + actionpack (~> 5.x) + actionview (~> 5.x) + activesupport (~> 5.x) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (4.2.7.1) - actionpack (= 4.2.7.1) - activesupport (= 4.2.7.1) + railties (5.0.0.1) + actionpack (= 5.0.0.1) + activesupport (= 5.0.0.1) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.1.0) @@ -393,7 +399,7 @@ GEM rspec-mocks (~> 3.5.0) rspec-support (~> 3.5.0) rspec-support (3.5.0) - rubocop (0.43.0) + rubocop (0.44.1) parser (>= 2.3.1.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) @@ -556,7 +562,8 @@ DEPENDENCIES pry-rails pul-assets! pul_uv_rails! - rails (= 4.2.7.1) + rails (= 5.0.0.1) + rails-controller-testing redis-namespace rsolr (~> 1.0.6) rspec-rails diff --git a/bin/spring b/bin/spring index 62ec28f8..4e9d144a 100755 --- a/bin/spring +++ b/bin/spring @@ -8,7 +8,7 @@ unless defined?(Spring) require 'bundler' if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) - Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq } + Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(File::PATH_SEPARATOR) } gem 'spring', match[1] require 'spring/binstub' end diff --git a/circle.yml b/circle.yml index ab19e833..b1f8a98e 100644 --- a/circle.yml +++ b/circle.yml @@ -13,6 +13,7 @@ dependencies: - npm install -g eslint post: - sudo sh bin/ci_kakadu_install.sh + - bundle exec rails db:migrate RAILS_ENV=test - bundle exec rake pomegranate:server: background: true - bin/jetty_wait diff --git a/config/application.rb b/config/application.rb index a5ff5179..001dd533 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,8 +25,6 @@ class Application < Rails::Application # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true config.autoload_paths += %W(#{Rails.root}/app/workers) end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 536d8aa3..564d55bc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -22,7 +22,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = true + config.public_file_server.enabled = true # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08b..82af12f6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -13,8 +13,8 @@ config.eager_load = false # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + config.public_file_server.enabled = true + config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -39,4 +39,5 @@ # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + config.active_job.queue_adapter = :inline end diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index 207c4be7..67c6951e 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -8,7 +8,7 @@ resource = IIIFResource.new manifest_url: url, exhibit: exhibit expect(resource.save_and_index).to be_truthy - get :index, q: "", exhibit_id: exhibit.id + get :index, params: { q: "", exhibit_id: exhibit.id } expect(document_ids).to eq [resource.document_builder.to_solr.to_a.first[:id]] end @@ -17,7 +17,7 @@ resource = IIIFResource.new manifest_url: url, exhibit: exhibit expect(resource.save_and_index).to be_truthy - get :index, q: "SR1", exhibit_id: exhibit.id + get :index, params: { q: "SR1", exhibit_id: exhibit.id } expect(document_ids).to eq [resource.document_builder.to_solr.to_a.first[:id]] end @@ -33,7 +33,7 @@ spotlight_resource_type_ssim: ["iiif_resources"]) index.commit - get :index, search_field: "all_fields" + get :index, params: { search_field: "all_fields" } expect(document_ids.length).to eq 1 expect(assigns[:response][:response][:numFound]).to eq 1 diff --git a/spec/controllers/exhibits_controller_spec.rb b/spec/controllers/exhibits_controller_spec.rb index 1b217ed9..4a0bc76e 100644 --- a/spec/controllers/exhibits_controller_spec.rb +++ b/spec/controllers/exhibits_controller_spec.rb @@ -7,15 +7,13 @@ end describe "#create" do context "when given just a slug" do - let(:params) do + let(:exhibit) do { - exhibit: { - slug: "princeton-best" - } + slug: "princeton-best" } end it "works and pulls the title" do - post :create, params + post :create, params: { exhibit: exhibit } expect(response).not_to render_template "new" last_exhibit = Spotlight::Exhibit.last @@ -25,30 +23,26 @@ end context "when not given a slug" do render_views - let(:params) do + let(:exhibit) do { - exhibit: { - slug: "" - } + slug: "" } end it "renders an error" do - post :create, params + post :create, params: { exhibit: exhibit } expect(response).to render_template "new" expect(assigns["exhibit"].errors.messages[:slug]).to eq ["can't be blank"] end end context "when given no params" do - let(:params) do + let(:exhibit) do { - exhibit: { - tag_list: nil - } + tag_list: nil } end it "renders an error" do - post :create, params + post :create, params: { exhibit: exhibit } expect(response).to render_template "new" expect(assigns["exhibit"].errors.messages[:slug]).to eq ["can't be blank"] diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index ac604aca..a4337d7d 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -3,7 +3,7 @@ RSpec.describe PagesController do describe "robots" do it "renders robot.text" do - get :robots, format: :text + get :robots, params: { format: :text } expect(response).to render_template "pages/robots" end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 23eec841..629c8574 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,6 +5,8 @@ abort("The Rails environment is running in production mode!") if Rails.env.production? require 'spec_helper' require 'rspec/rails' +require 'rails-controller-testing' + # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in