diff --git a/.travis.yml b/.travis.yml index eff072637..2dbf8ca12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ env: - DB=postgresql gemfile: - - gemfiles/activerecord_3.2.gemfile - gemfiles/activerecord_4.0.gemfile - gemfiles/activerecord_4.1.gemfile @@ -28,9 +27,3 @@ matrix: allow_failures: - gemfile: gemfiles/activerecord_edge.gemfile - rvm: rbx-2 - exclude: - - rvm: 2.2 - gemfile: gemfiles/activerecord_3.2.gemfile - - rvm: rbx-2 - gemfile: gemfiles/activerecord_3.2.gemfile - diff --git a/Appraisals b/Appraisals index c1a495a04..0e9c5e6c6 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,3 @@ -appraise "activerecord-3.2" do - gem "activerecord", github: "rails/rails" , branch: '3-2-stable' -end - appraise "activerecord-4.0" do gem "activerecord", github: "rails/rails" , branch: '4-0-stable' end diff --git a/acts-as-taggable-on.gemspec b/acts-as-taggable-on.gemspec index 9290a8deb..21f26c2e1 100644 --- a/acts-as-taggable-on.gemspec +++ b/acts-as-taggable-on.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |gem| gem.post_install_message = File.read('UPGRADING.md') end - gem.add_runtime_dependency 'activerecord', ['>= 3.2', '< 5'] + gem.add_runtime_dependency 'activerecord', ['>= 4.0', '< 5'] gem.add_development_dependency 'sqlite3' gem.add_development_dependency 'mysql2', '~> 0.3.7' diff --git a/gemfiles/activerecord_3.2.gemfile b/gemfiles/activerecord_3.2.gemfile deleted file mode 100644 index a61e18a1a..000000000 --- a/gemfiles/activerecord_3.2.gemfile +++ /dev/null @@ -1,15 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "activerecord", :github => "rails/rails", :branch => "3-2-stable" - -group :local_development do - gem "guard" - gem "guard-rspec" - gem "appraisal" - gem "rake" - gem "byebug", :platform => :mri_21 -end - -gemspec :path => "../" diff --git a/lib/acts-as-taggable-on.rb b/lib/acts-as-taggable-on.rb index ad3791103..438449bf5 100644 --- a/lib/acts-as-taggable-on.rb +++ b/lib/acts-as-taggable-on.rb @@ -117,7 +117,6 @@ def self.apply_binary_collation(bincoll) end ActiveSupport.on_load(:active_record) do - extend ActsAsTaggableOn::Compatibility extend ActsAsTaggableOn::Taggable include ActsAsTaggableOn::Tagger end diff --git a/lib/acts_as_taggable_on/compatibility.rb b/lib/acts_as_taggable_on/compatibility.rb deleted file mode 100644 index 99e69cff9..000000000 --- a/lib/acts_as_taggable_on/compatibility.rb +++ /dev/null @@ -1,35 +0,0 @@ -module ActsAsTaggableOn::Compatibility - def has_many_with_taggable_compatibility(name, options = {}, &extention) - if ActsAsTaggableOn::Utils.active_record4? || ActsAsTaggableOn::Utils.active_record5? - scope, opts = build_taggable_scope_and_options(options) - has_many(name, scope, opts, &extention) - else - has_many(name, options, &extention) - end - end - - def build_taggable_scope_and_options(opts) - scope_opts, opts = parse_taggable_options(opts) - - unless scope_opts.empty? - scope = -> { - scope_opts.inject(self) { |result, hash| result.send(*hash) } - } - return [scope, opts] - end - - [nil, opts] - end - - def parse_taggable_options(opts) - scope_opts = {} - [:order, :having, :select, :group, :limit, :offset, :readonly].each do |o| - scope_opts[o] = opts.delete o if opts[o] - end - scope_opts[:where] = opts.delete :conditions if opts[:conditions] - scope_opts[:joins] = opts.delete :include if opts [:include] - scope_opts[:distinct] = opts.delete :uniq if opts[:uniq] - - [scope_opts, opts] - end -end diff --git a/lib/acts_as_taggable_on/taggable/core.rb b/lib/acts_as_taggable_on/taggable/core.rb index 963037311..2f137bb03 100644 --- a/lib/acts_as_taggable_on/taggable/core.rb +++ b/lib/acts_as_taggable_on/taggable/core.rb @@ -23,18 +23,15 @@ def initialize_acts_as_taggable_on_core class_eval do # when preserving tag order, include order option so that for a 'tags' context # the associations tag_taggings & tags are always returned in created order - has_many_with_taggable_compatibility context_taggings, as: :taggable, - dependent: :destroy, - class_name: 'ActsAsTaggableOn::Tagging', - order: taggings_order, - conditions: {context: tags_type}, - include: :tag - - has_many_with_taggable_compatibility context_tags, through: context_taggings, - source: :tag, - class_name: 'ActsAsTaggableOn::Tag', - order: taggings_order - + has_many context_taggings, -> { includes(:tag).order(taggings_order).where(context: tags_type) }, + as: :taggable, + class_name: ActsAsTaggableOn::Tagging, + dependent: :destroy + + has_many context_tags, -> { order(taggings_order) }, + class_name: ActsAsTaggableOn::Tag, + through: context_taggings, + source: :tag end taggable_mixin.class_eval <<-RUBY, __FILE__, __LINE__ + 1 diff --git a/lib/acts_as_taggable_on/tagger.rb b/lib/acts_as_taggable_on/tagger.rb index 5c451be8f..a1ade9369 100644 --- a/lib/acts_as_taggable_on/tagger.rb +++ b/lib/acts_as_taggable_on/tagger.rb @@ -15,18 +15,19 @@ module ClassMethods # end def acts_as_tagger(opts={}) class_eval do - has_many_with_taggable_compatibility :owned_taggings, - opts.merge( - as: :tagger, - dependent: :destroy, - class_name: '::ActsAsTaggableOn::Tagging' - ) + owned_taggings_scope = opts.delete(:scope) - has_many_with_taggable_compatibility :owned_tags, - through: :owned_taggings, - source: :tag, - class_name: '::ActsAsTaggableOn::Tag', - uniq: true + has_many :owned_taggings, owned_taggings_scope, + opts.merge( + as: :tagger, + class_name: ::ActsAsTaggableOn::Tagging, + dependent: :destroy + ) + + has_many :owned_tags, -> { distinct }, + class_name: ::ActsAsTaggableOn::Tag, + source: :tag, + through: :owned_taggings end include ActsAsTaggableOn::Tagger::InstanceMethods diff --git a/lib/acts_as_taggable_on/tagging.rb b/lib/acts_as_taggable_on/tagging.rb index df23df4ce..3411ed0cf 100644 --- a/lib/acts_as_taggable_on/tagging.rb +++ b/lib/acts_as_taggable_on/tagging.rb @@ -1,16 +1,5 @@ module ActsAsTaggableOn class Tagging < ::ActiveRecord::Base #:nodoc: - #TODO, remove from 4.0.0 - attr_accessible :tag, - :tag_id, - :context, - :taggable, - :taggable_type, - :taggable_id, - :tagger, - :tagger_type, - :tagger_id if defined?(ActiveModel::MassAssignmentSecurity) - belongs_to :tag, class_name: '::ActsAsTaggableOn::Tag', counter_cache: ActsAsTaggableOn.tags_counter belongs_to :taggable, polymorphic: true belongs_to :tagger, polymorphic: true diff --git a/spec/acts_as_taggable_on/taggable_spec.rb b/spec/acts_as_taggable_on/taggable_spec.rb index 97283eb7a..57e65a0a2 100644 --- a/spec/acts_as_taggable_on/taggable_spec.rb +++ b/spec/acts_as_taggable_on/taggable_spec.rb @@ -745,7 +745,6 @@ context 'Model.limit(x).tag_counts.sum(:tags_count)' do it 'should not break on Mysql' do - # Activerecord 3.2 return a string expect(TaggableModel.limit(2).tag_counts.sum('tags_count').to_i).to eq(5) end end diff --git a/spec/support/database.rb b/spec/support/database.rb index b552645a0..8af7025ae 100644 --- a/spec/support/database.rb +++ b/spec/support/database.rb @@ -13,13 +13,7 @@ config = ActiveRecord::Base.configurations[db_name] begin - #activerecord 4 uses symbol - #TODO, remove when activerecord 3 support is dropped - if ActsAsTaggableOn::Utils.active_record4? || ActsAsTaggableOn::Utils.active_record5? - ActiveRecord::Base.establish_connection(db_name.to_sym) - else - ActiveRecord::Base.establish_connection(db_name) - end + ActiveRecord::Base.establish_connection(db_name.to_sym) ActiveRecord::Base.connection rescue case db_name