From 4a7b1eeb94f480d0f531411ddab6500b687589a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Wed, 21 Dec 2016 09:29:40 +0100 Subject: [PATCH 1/5] Update ActionCable to ~>5.0.1 and remove our monkeypatch for pg --- Gemfile | 2 +- config/initializers/action_cable_patch.rb | 52 ----------------------- 2 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 config/initializers/action_cable_patch.rb diff --git a/Gemfile b/Gemfile index 393dc1c6a36..1b88da3374b 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,7 @@ unless dependencies.detect { |d| d.name == "manageiq-ui-classic" } end # Unmodified gems -gem "actioncable", "~>5.0.0" +gem "actioncable", "~>5.0.1" gem "activerecord-session_store", "~>1.0.0" gem "acts_as_list", "~>0.7.2" gem "acts_as_tree", "~>2.1.0" # acts_as_tree needs to be required so that it loads before ancestry diff --git a/config/initializers/action_cable_patch.rb b/config/initializers/action_cable_patch.rb deleted file mode 100644 index 64ae322d785..00000000000 --- a/config/initializers/action_cable_patch.rb +++ /dev/null @@ -1,52 +0,0 @@ -if Gem::Version.new(ActionCable::VERSION::STRING) < Gem::Version.new("5.0.1") - ActiveSupport.on_load(:action_cable) do - require 'action_cable/subscription_adapter/postgresql' - ActionCable::SubscriptionAdapter::PostgreSQL.class_eval do - def new_connection - ar_conn = ActiveRecord::Base.connection_pool.checkout - ActiveRecord::Base.connection_pool.remove ar_conn - - pg_conn = ar_conn.raw_connection - - unless pg_conn.is_a?(PG::Connection) - raise 'ActiveRecord database must be Postgres in order to use the Postgres ActionCable storage adapter' - end - - yield pg_conn - end - end - - ActionCable::SubscriptionAdapter::PostgreSQL::Listener.class_eval do - def listen - @adapter.new_connection do |pg_conn| - catch :shutdown do - loop do - until @queue.empty? - action, channel, callback = @queue.pop(true) - - case action - when :listen - pg_conn.exec("LISTEN #{pg_conn.escape_identifier channel}") - @event_loop.post(&callback) if callback - when :unlisten - pg_conn.exec("UNLISTEN #{pg_conn.escape_identifier channel}") - when :shutdown - throw :shutdown - end - end - - pg_conn.wait_for_notify(1) do |chan, pid, message| - broadcast(chan, message) - end - end - end - end - end - end - end -elsif Rails.env.development? - errstr = "ActionCable version is 5.0.1 or newer, please see if we still need this patch: #{__FILE__}!" - # Display errors in both development.log and STDOUT - Rails.logger.warn(errstr) - warn(errstr) -end From 31defe11d36960d9de6e73697c247be7e6c9be34 Mon Sep 17 00:00:00 2001 From: Chris Arcand Date: Wed, 21 Dec 2016 20:58:29 -0600 Subject: [PATCH 2/5] Revert "temporarily force rails to < 5.0.1" This reverts commit 475f1e925b2a70355b53ee6d4b3bdba9d3f59f81. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1b88da3374b..fa5ef14e49c 100644 --- a/Gemfile +++ b/Gemfile @@ -88,7 +88,7 @@ gem "paperclip", "~>4.3.0" gem "pg-pglogical", "~>1.0.0", :require => false gem "puma", "~>3.3.0" gem "query_relation", "~>0.1.0", :require => false -gem "rails", "~>5.0.0", ">= 5.0.0.1", "< 5.0.1" +gem "rails", "~>5.0.0", ">= 5.0.0.1" gem "rails-controller-testing", :require => false gem "rails-i18n", "~>5.x" gem "recursive-open-struct", "~>1.0.0" From 374e34c64f10564201ff4f499ed6610e7661f3cb Mon Sep 17 00:00:00 2001 From: Chris Arcand Date: Wed, 21 Dec 2016 21:05:36 -0600 Subject: [PATCH 3/5] Remove unnecessary actioncable specification There's no reason ActionCable should be specified independently of Rails as railties locks them at exact versions. That is, actioncable is included and loaded in the stack regardless of being set here, and setting action cable like this actually forces the entire framework at 5.0.1 anyway. --- Gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index fa5ef14e49c..843931cd5df 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,6 @@ unless dependencies.detect { |d| d.name == "manageiq-ui-classic" } end # Unmodified gems -gem "actioncable", "~>5.0.1" gem "activerecord-session_store", "~>1.0.0" gem "acts_as_list", "~>0.7.2" gem "acts_as_tree", "~>2.1.0" # acts_as_tree needs to be required so that it loads before ancestry @@ -88,7 +87,7 @@ gem "paperclip", "~>4.3.0" gem "pg-pglogical", "~>1.0.0", :require => false gem "puma", "~>3.3.0" gem "query_relation", "~>0.1.0", :require => false -gem "rails", "~>5.0.0", ">= 5.0.0.1" +gem "rails", "~>5.0.1" gem "rails-controller-testing", :require => false gem "rails-i18n", "~>5.x" gem "recursive-open-struct", "~>1.0.0" From 28a71e9facb0f2ddd4189f47cf02d47795b681ad Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Fri, 6 Jan 2017 13:23:52 -0600 Subject: [PATCH 4/5] Have attributes_builder handle MIQ virtual_attributes This overwrites the default method for this by adding an additional check to the proc that is defined with the AttributeSet::Builder to check to see if the key should be provided a default from the `_default_attributes` hash to not only check to see if it is a column from the database, but also a virtual_attribute. The functionality added by: https://github.com/rails/rails/commit/3e37a8b9e84a9dd532485ee7945c9d053b9f9d86#diff-6c8fd220c92c2b25aa29891b59d00c04 was meant to help vanilla Rails' "virtual attributes" by assigning a default value on model instantiation. This is not what used to be done for any attributes (database or otherwise) besides the primary key for that model. What this does is includes `virtual_attributes` as attributes that aren't defined with a default value, along the database column attributes. --- lib/extensions/ar_virtual.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/extensions/ar_virtual.rb b/lib/extensions/ar_virtual.rb index 3c890ce0160..01c423dfb98 100644 --- a/lib/extensions/ar_virtual.rb +++ b/lib/extensions/ar_virtual.rb @@ -386,6 +386,14 @@ def virtual_attribute_names end end + def attributes_builder + @attributes_builder ||= ::ActiveRecord::AttributeSet::Builder.new(attribute_types, primary_key) do |name| + unless columns_hash.key?(name) || virtual_attribute?(name) + _default_attributes[name].dup + end + end + end + private def load_schema! From 4e96ee4fb928dc3e03e7c48dd37146005cc56427 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Mon, 9 Jan 2017 13:48:32 -0500 Subject: [PATCH 5/5] Use strings for nested joins In the following: https://github.com/rails/rails/pull/25146 Rails added a regression to making nested joins with references to those joins in the WHERE clause, and this causes an error when running this test suite in Rails 5.0.1. This has been addressed in Rails with: https://github.com/rails/rails/pull/27598 And has been merged into master, but it is likely that Rails 5.0.1 will not be pulled from Rubygems, and the ManageIQ will fail to run tests properly with that version of Rails. Because of that, and to allow the tests to function in the same way, the simplest thing to do is to stringify the keys manually avoid the error for now. This is against the convention (most Rails devs prefer symbols), but this allows the tests to remain as they were. --- .../graph_of_inventory_collections_targeted_refresh_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb index 0c7b68d6adb..6b3f1653174 100644 --- a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb +++ b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb @@ -309,7 +309,7 @@ :manager_ref => [:vm_or_template]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, - :arel => @ems.disks.joins(:hardware => :vm_or_template).where(:hardware => {:vms => {:ems_ref => vm_refs}}), + :arel => @ems.disks.joins(:hardware => :vm_or_template).where('hardware' => {'vms' => {'ems_ref' => vm_refs}}), :manager_ref => [:hardware, :device_name]) @vm_data_3 = vm_data(3).merge( @@ -393,7 +393,7 @@ :manager_ref => [:vm_or_template]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, - :arel => @ems.disks.joins(:hardware => :vm_or_template).where(:hardware => {:vms => {:ems_ref => vm_refs}}), + :arel => @ems.disks.joins(:hardware => :vm_or_template).where('hardware' => {'vms' => {'ems_ref' => vm_refs}}), :manager_ref => [:hardware, :device_name]) @data[:image_hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware,