From e58217d7d72fd100f725320490cc842ef0ecaa13 Mon Sep 17 00:00:00 2001 From: Russell Garner Date: Fri, 2 May 2014 13:34:18 +0100 Subject: [PATCH] Update acts-as-taggable-on from 3.0.1 to 3.1.1 * This fixes the issue where the Mapping.with_traffic_summary scope would not chain with Mapping.tagged_with, generating invalid SQL when a `count` was required (falling over on `any?` and the like) * While we initially patched AATO ourselves, it turns out a fix was already merged for AATO 3.1.0 (https://github.com/mbleigh/acts-as-taggable-on/pull/417) * 3.1.1 also had a tag counting performance improvement, which in truth doesn't do much for us but requires a migration --- Gemfile | 2 +- Gemfile.lock | 18 ++++++++++-------- ...cache_to_tags.acts_as_taggable_on_engine.rb | 15 +++++++++++++++ db/structure.sql | 7 +++++-- spec/models/mapping_spec.rb | 8 -------- 5 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20140502114341_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb diff --git a/Gemfile b/Gemfile index be09239f1..97de01607 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'gds-api-adapters', '7.14.0' gem 'mlanett-redis-lock', '0.2.6' gem 'whenever', '0.8.4' gem 'gretel', '3.0.5' -gem 'acts-as-taggable-on', '3.0.1' +gem 'acts-as-taggable-on', '3.1.1' gem 'select2-rails', '3.5.2' gem 'activerecord-import', '0.5.0' gem 'sidekiq', '3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index c0e9acf01..bd1fe9e37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,8 +31,10 @@ GEM activesupport (3.2.17) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - acts-as-taggable-on (3.0.1) - rails (>= 3, < 5) + acts-as-taggable-on (3.1.1) + actionpack (>= 3, < 5) + activerecord (>= 3, < 5) + activesupport (>= 3, < 5) addressable (2.3.5) airbrake (3.1.15) builder @@ -142,7 +144,7 @@ GEM mini_portile (0.5.1) mlanett-redis-lock (0.2.6) redis - multi_json (1.8.4) + multi_json (1.9.3) multi_xml (0.5.5) multipart-post (1.2.0) mysql2 (0.3.13) @@ -186,7 +188,7 @@ GEM rack (>= 0.4) rack-cache (1.2) rack (>= 0.4) - rack-ssl (1.3.3) + rack-ssl (1.3.4) rack rack-test (0.6.2) rack (>= 1.0) @@ -206,7 +208,7 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) raindrops (0.11.0) - rake (10.1.1) + rake (10.3.1) rdoc (3.12.2) json (~> 1.4) redis (3.0.7) @@ -250,14 +252,14 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.18.1) + thor (0.19.1) tilt (1.4.1) timecop (0.5.9.2) timers (1.1.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.38) + tzinfo (0.3.39) uglifier (2.0.1) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) @@ -283,7 +285,7 @@ PLATFORMS DEPENDENCIES activerecord-import (= 0.5.0) - acts-as-taggable-on (= 3.0.1) + acts-as-taggable-on (= 3.1.1) airbrake (= 3.1.15) bootstrap-sass (= 3.1.0) capybara (= 2.1.0) diff --git a/db/migrate/20140502114341_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20140502114341_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 000000000..d0dab1683 --- /dev/null +++ b/db/migrate/20140502114341_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -0,0 +1,15 @@ +# This migration comes from acts_as_taggable_on_engine (originally 3) +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration + def self.up + add_column :tags, :taggings_count, :integer, :default => 0 + + ActsAsTaggableOn::Tag.reset_column_information + ActsAsTaggableOn::Tag.find_each do |tag| + ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings) + end + end + + def self.down + remove_column :tags, :taggings_count + end +end diff --git a/db/structure.sql b/db/structure.sql index b5037804b..53e8caf43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -148,7 +148,7 @@ CREATE TABLE `organisations_sites` ( `site_id` int(11) NOT NULL, `organisation_id` int(11) NOT NULL, UNIQUE KEY `index_organisations_sites_on_site_id_and_organisation_id` (`site_id`,`organisation_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `schema_migrations` ( `version` varchar(255) COLLATE utf8_unicode_ci NOT NULL, @@ -164,7 +164,7 @@ CREATE TABLE `sessions` ( PRIMARY KEY (`id`), KEY `index_sessions_on_session_id` (`session_id`), KEY `index_sessions_on_updated_at` (`updated_at`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `sites` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -201,6 +201,7 @@ CREATE TABLE `taggings` ( CREATE TABLE `tags` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `taggings_count` int(11) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `index_tags_on_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -316,3 +317,5 @@ INSERT INTO schema_migrations (version) VALUES ('20140417100412'); INSERT INTO schema_migrations (version) VALUES ('20140422160500'); INSERT INTO schema_migrations (version) VALUES ('20140422184036'); + +INSERT INTO schema_migrations (version) VALUES ('20140502114341'); diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index 31a8b42b9..39b5b64b3 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -235,14 +235,6 @@ ['/path-3', 40 * 3 + 30 * 3] ] end - - it 'plays nicely with tagging' do - m = Mapping.first - m.tag_list = ['foo'] - m.save! - - expect { @mappings.tagged_with('foo').any? }.to_not raise_error - end end end