From 5949e1a6c32e6e5903a0394b0c1090399d381445 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Wed, 24 May 2017 18:36:10 +0100 Subject: [PATCH 1/5] Upgrade to Rails 4.1 --- Gemfile | 6 +-- Gemfile.lock | 125 ++++++++++++++++++++++++++++----------------------- 2 files changed, 73 insertions(+), 58 deletions(-) diff --git a/Gemfile b/Gemfile index 8d12733b45..8d626b9288 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'browser' gem 'coffee-rails' gem 'exception_notification' gem 'gon' -gem 'haml-rails', '~> 0.4.0' +gem 'haml-rails' gem 'httparty' gem "jquery-fileupload-rails" gem 'jquery-rails' @@ -20,7 +20,7 @@ gem 'nokogiri' gem 'pg' gem 'pg_search' gem 'protected_attributes' -gem 'rails', '4.0.13' +gem 'rails', '4.1.16' gem 'rack-pratchett' gem 'redis-rails' gem 'resque' @@ -33,7 +33,7 @@ gem 'select2-rails' gem 'test-unit', '~> 3.0' # required by Heroku for production console gem 'tinymce-rails' gem 'uglifier' -gem 'will_paginate', '~> 3.0.6' +gem 'will_paginate' group :production do gem 'puma' diff --git a/Gemfile.lock b/Gemfile.lock index 58524606ec..9d27338f67 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,52 +1,53 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) + actionmailer (4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) + actionpack (4.1.16) + actionview (= 4.1.16) + activesupport (= 4.1.16) rack (~> 1.5.2) rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) + actionview (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + erubis (~> 2.7.0) + activemodel (4.1.16) + activesupport (= 4.1.16) + builder (~> 3.1) + activerecord (4.1.16) + activemodel (= 4.1.16) + activesupport (= 4.1.16) + arel (~> 5.0.0) + activesupport (4.1.16) i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) + tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) - api-pagination (4.5.2) - apipie-rails (0.4.0) - json - rails (>= 4.0) - arel (4.0.2) + api-pagination (4.6.1) + apipie-rails (0.5.1) + rails (>= 4.1) + arel (5.0.1.20140414130214) audited (4.2.2) rails-observers (~> 0.1.2) audited-activerecord (4.2.2) activerecord (~> 4.0) audited (= 4.2.2) - aws-sdk (2.9.21) - aws-sdk-resources (= 2.9.21) - aws-sdk-core (2.9.21) + aws-sdk (2.9.23) + aws-sdk-resources (= 2.9.23) + aws-sdk-core (2.9.23) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.9.21) - aws-sdk-core (= 2.9.21) + aws-sdk-resources (2.9.23) + aws-sdk-core (= 2.9.23) aws-sigv4 (1.0.0) browser (2.4.0) - builder (3.1.4) + builder (3.2.3) byebug (9.0.6) capybara (2.14.0) addressable @@ -113,14 +114,21 @@ GEM json multi_json request_store (>= 1.0) - haml (4.0.7) + haml (5.0.1) + temple (>= 0.8.0) tilt - haml-rails (0.4) - actionpack (>= 3.1, < 4.1) - activesupport (>= 3.1, < 4.1) - haml (>= 3.1, < 4.1) - railties (>= 3.1, < 4.1) + haml-rails (1.0.0) + actionpack (>= 4.0.1) + activesupport (>= 4.0.1) + haml (>= 4.0.6, < 6.0) + html2haml (>= 1.0.1) + railties (>= 4.0.1) hashdiff (0.3.4) + html2haml (2.2.0) + erubis (~> 2.7.0) + haml (>= 4.0, < 6) + nokogiri (>= 1.6.0) + ruby_parser (~> 3.5) httparty (0.15.5) multi_xml (>= 0.5.2) i18n (0.8.1) @@ -146,7 +154,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) - minitest (4.7.5) + minitest (5.10.2) mono_logger (1.1.0) multi_json (1.12.1) multi_test (0.1.2) @@ -165,7 +173,7 @@ GEM activesupport (>= 3.1) arel power_assert (1.0.2) - protected_attributes (1.1.3) + protected_attributes (1.1.4) activemodel (>= 4.0.1, < 5.0) public_suffix (2.0.5) puma (3.8.2) @@ -177,13 +185,15 @@ GEM rack-test (0.6.3) rack (>= 1.0) rack-timeout (0.4.2) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) + rails (4.1.16) + actionmailer (= 4.1.16) + actionpack (= 4.1.16) + actionview (= 4.1.16) + activemodel (= 4.1.16) + activerecord (= 4.1.16) + activesupport (= 4.1.16) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) + railties (= 4.1.16) sprockets-rails (~> 2.0) rails-observers (0.1.2) activemodel (~> 4.0) @@ -192,9 +202,9 @@ GEM rails_stdout_logging rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) + railties (4.1.16) + actionpack (= 4.1.16) + activesupport (= 4.1.16) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) @@ -262,7 +272,9 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) - rufus-scheduler (3.4.0) + ruby_parser (3.9.0) + sexp_processor (~> 4.1) + rufus-scheduler (3.4.2) et-orbi (~> 1.0) safe_yaml (1.0.4) sanitize (4.4.0) @@ -279,6 +291,7 @@ GEM seed_dump (0.5.3) select2-rails (4.0.3) thor (~> 0.14) + sexp_processor (4.9.0) simplecov (0.13.0) docile (~> 1.1.0) json (>= 1.8, < 3) @@ -295,7 +308,8 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - test-unit (3.2.3) + temple (0.8.0) + test-unit (3.2.4) power_assert thin (1.7.0) daemons (~> 1.0, >= 1.0.9) @@ -305,7 +319,7 @@ GEM thread_safe (0.3.6) tilt (2.0.7) timecop (0.8.1) - tinymce-rails (4.6.1) + tinymce-rails (4.6.2) railties (>= 3.1.1) tunemygc (1.0.69) twitter-bootstrap-rails (3.2.2) @@ -313,7 +327,8 @@ GEM execjs (>= 2.2.2, >= 2.2) less-rails (>= 2.5.0) railties (>= 3.1) - tzinfo (0.3.53) + tzinfo (1.2.3) + thread_safe (~> 0.1) uglifier (3.2.0) execjs (>= 0.3.0, < 3) vegas (0.1.11) @@ -322,7 +337,7 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - will_paginate (3.0.12) + will_paginate (3.1.5) xpath (2.0.0) nokogiri (~> 1.3) @@ -344,7 +359,7 @@ DEPENDENCIES exception_notification factory_girl_rails gon - haml-rails (~> 0.4.0) + haml-rails httparty jquery-fileupload-rails jquery-rails @@ -359,7 +374,7 @@ DEPENDENCIES rack-cors rack-pratchett rack-timeout - rails (= 4.0.13) + rails (= 4.1.16) rails_12factor rake (= 10.4.2) redis-rails @@ -381,7 +396,7 @@ DEPENDENCIES tunemygc uglifier webmock - will_paginate (~> 3.0.6) + will_paginate RUBY VERSION ruby 2.3.3p222 From 3e03e37533826643f6f073e78bcc341ce0ed3c7b Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Wed, 24 May 2017 18:39:22 +0100 Subject: [PATCH 2/5] Fix .count with .select in light of Rails 4.1 change See https://github.com/rails/rails/pull/10710 --- app/controllers/application_controller.rb | 2 +- app/views/posts/_generate_flat.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ceeef90914..1f1a6826cf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -107,7 +107,7 @@ def posts_from_relation(relation, no_tests=true, with_pagination=true) posts = posts.paginate(page: page, per_page: 25) if with_pagination posts = posts.no_tests if no_tests - if (with_pagination && posts.total_pages <= 1) || posts.count <= 25 + if (with_pagination && posts.total_pages <= 1) || posts.count(:all) <= 25 posts = posts.select {|post| post.visible_to?(current_user)} end diff --git a/app/views/posts/_generate_flat.haml b/app/views/posts/_generate_flat.haml index 7fe43c7cf9..05f1ca93bb 100644 --- a/app/views/posts/_generate_flat.haml +++ b/app/views/posts/_generate_flat.haml @@ -1,4 +1,4 @@ -- 1.upto((replies.count / 250.0).ceil).each do |index| +- 1.upto((replies.count(:all) / 250.0).ceil).each do |index| - replies.paginate(per_page: 250, page: index).each do |reply| - klass = cycle('even'.freeze, 'odd'.freeze) .post-container{class: klass} From 1862d2aed3ea0ff50e703d3fa94dd075283f6099 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Wed, 24 May 2017 18:42:58 +0100 Subject: [PATCH 3/5] Update to not use destructive in-line 'select!' on relation --- app/controllers/posts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 0b10461a7e..0e3b443694 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -41,7 +41,7 @@ def unread def mark posts = Post.where(id: params[:marked_ids]) - posts.select! do |post| + posts = posts.select do |post| post.visible_to?(current_user) end if params[:commit] == "Mark Read" From 906de238867e9806c7d894d16ccc23937bd8fcd5 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Wed, 24 May 2017 18:46:45 +0100 Subject: [PATCH 4/5] Set cookies_serializer to allow transparent upgrade to JSON This file is explicitly mentioned in the 4.0 -> 4.1 upgrade and it says if you want to use the new JSON format to set :hybrid here, to transparently migrate cookies; I'm not sure if this file was just ignored before, and we weren't using JSON, or what? If I run the server without this change it crashes when I try loading the site, and with this change it works. --- config/initializers/cookies_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 7f70458dee..54516e3f23 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json +Rails.application.config.action_dispatch.cookies_serializer = :hybrid From 18134a5c0268520a74c6b6d6027d837e4cd692c4 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Wed, 24 May 2017 18:37:31 +0100 Subject: [PATCH 5/5] Use has_many :through relation for galleries and icons (Fix recognizing galleries_icons relation with protected attributes) --- app/models/galleries_icon.rb | 5 +++++ app/models/gallery.rb | 15 ++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/models/galleries_icon.rb b/app/models/galleries_icon.rb index dd22ceea09..ad4be7c212 100644 --- a/app/models/galleries_icon.rb +++ b/app/models/galleries_icon.rb @@ -3,8 +3,13 @@ class GalleriesIcon < ActiveRecord::Base belongs_to :gallery accepts_nested_attributes_for :icon, allow_destroy: true + after_create :set_has_gallery after_destroy :unset_has_gallery + def set_has_gallery + icon.update_attributes(has_gallery: true) + end + def unset_has_gallery return if icon.galleries.present? icon.update_attributes(has_gallery: false) diff --git a/app/models/gallery.rb b/app/models/gallery.rb index 2d61dc09bf..658ff7f5fa 100644 --- a/app/models/gallery.rb +++ b/app/models/gallery.rb @@ -1,8 +1,9 @@ class Gallery < ActiveRecord::Base belongs_to :user belongs_to :cover_icon, class_name: Icon + has_many :galleries_icons - has_and_belongs_to_many :icons, -> { order('LOWER(keyword)') }, after_add: :set_has_gallery, after_remove: :unset_has_gallery + has_many :icons, -> { order('LOWER(keyword)') }, through: :galleries_icons has_many :characters_galleries has_many :characters, through: :characters_galleries @@ -20,16 +21,4 @@ def default_icon def character_gallery_for(character) characters_galleries.where(character_id: character).first end - - private - - def set_has_gallery(icon) - return unless valid? # don't change icon status unless the gallery being saved is valid - icon.update_attributes(has_gallery: true) - end - - def unset_has_gallery(icon) - return if icon.galleries.present? - icon.update_attributes(has_gallery: false) - end end