From 1118c732f11201f399ba41cf8a2a38d9f4ee4db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jun 2019 15:52:16 +0200 Subject: [PATCH] Bump acts-as-taggable-on to 6.0.0 Rails 5.1 introduced certain changes in the way a record is touched when the counter cache option is enabled in a belongs to association. We need to upgrade acts-as-taggable-on so it keeps changing the `updated_at` attribute when a new tag is added to a record. Note we now need to reload the records in some cases to get the `context_tag_list` method to return what we expect. Methods like `context_tags` however work properly with no need to reload the record. --- Gemfile | 2 +- Gemfile.lock | 6 ++--- ...ique_indices.acts_as_taggable_on_engine.rb | 17 ++++++++++++++ ..._on_taggings.acts_as_taggable_on_engine.rb | 22 +++++++++++++++++++ db/schema.rb | 7 ++++++ spec/models/budget/investment_spec.rb | 2 +- spec/models/legislation/process_spec.rb | 2 +- spec/models/proposal_spec.rb | 2 +- 8 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20190619133544_add_missing_unique_indices.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20190619133547_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb diff --git a/Gemfile b/Gemfile index 716f7c21b..8fa28ccf9 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" gem "rails", "5.1.7" -gem "acts-as-taggable-on", "~> 5.0.0" +gem "acts-as-taggable-on", "~> 6.0.0" gem "acts_as_votable", "~> 0.11.1" gem "ahoy_matey", "~> 1.6.0" gem "ancestry", "~> 3.0.7" diff --git a/Gemfile.lock b/Gemfile.lock index 889d5e0cd..5b2eeb0e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,8 +47,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts-as-taggable-on (5.0.0) - activerecord (>= 4.2.8) + acts-as-taggable-on (6.0.0) + activerecord (~> 5.0) acts_as_votable (0.11.1) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) @@ -602,7 +602,7 @@ PLATFORMS ruby DEPENDENCIES - acts-as-taggable-on (~> 5.0.0) + acts-as-taggable-on (~> 6.0.0) acts_as_votable (~> 0.11.1) ahoy_matey (~> 1.6.0) ancestry (~> 3.0.7) diff --git a/db/migrate/20190619133544_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20190619133544_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 000000000..b766e234f --- /dev/null +++ b/db/migrate/20190619133544_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -0,0 +1,17 @@ +# This migration comes from acts_as_taggable_on_engine (originally 2) +if ActiveRecord.gem_version >= Gem::Version.new("5.0") + class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end +else + class AddMissingUniqueIndices < ActiveRecord::Migration; end +end +AddMissingUniqueIndices.class_eval do + def self.up + add_index :taggings, + [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], + unique: true, name: "taggings_idx" + end + + def self.down + remove_index :taggings, name: "taggings_idx" + end +end diff --git a/db/migrate/20190619133547_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20190619133547_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 000000000..185a6a3bf --- /dev/null +++ b/db/migrate/20190619133547_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,22 @@ +# This migration comes from acts_as_taggable_on_engine (originally 6) +if ActiveRecord.gem_version >= Gem::Version.new("5.0") + class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end +else + class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end +end +AddMissingIndexesOnTaggings.class_eval do + def change + add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id + add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type + add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id + add_index :taggings, :context unless index_exists? :taggings, :context + + unless index_exists? :taggings, [:tagger_id, :tagger_type] + add_index :taggings, [:tagger_id, :tagger_type] + end + + unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: "taggings_idy" + add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: "taggings_idy" + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3dafb07b9..57012aa3c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1390,8 +1390,15 @@ ActiveRecord::Schema.define(version: 20191108173350) do t.integer "tagger_id" t.string "context", limit: 128 t.datetime "created_at" + t.index ["context"], name: "index_taggings_on_context" + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true t.index ["tag_id"], name: "index_taggings_on_tag_id" t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" + t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["taggable_type"], name: "index_taggings_on_taggable_type" + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type" + t.index ["tagger_id"], name: "index_taggings_on_tagger_id" end create_table "tags", id: :serial, force: :cascade do |t| diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index f358584c3..35961a911 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -1327,7 +1327,7 @@ describe Budget::Investment do let(:investment) { create(:budget_investment, :with_milestone_tags) } it "has milestone_tags" do - expect(investment.milestone_tag_list.count).to eq(1) + expect(investment.reload.milestone_tag_list.count).to eq(1) end end end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 6c31e175f..8a2c9eee7 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -218,7 +218,7 @@ describe Legislation::Process do let(:process) { create(:legislation_process, :with_milestone_tags) } it "has milestone_tags" do - expect(process.milestone_tag_list.count).to eq(1) + expect(process.reload.milestone_tag_list.count).to eq(1) end end end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index b92d4726c..e15d796ae 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -1045,7 +1045,7 @@ describe Proposal do let(:proposal) { create(:proposal, :with_milestone_tags) } it "has milestone_tags" do - expect(proposal.milestone_tag_list.count).to eq(1) + expect(proposal.reload.milestone_tag_list.count).to eq(1) end end end