Skip to content

Commit

Permalink
Merge pull request #767 from rbritom/master
Browse files Browse the repository at this point in the history
Changes required to support Ruby on Rails version 5
  • Loading branch information
seuros committed Jul 11, 2016
2 parents ca17731 + 830f90d commit 9a0b7d1
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 137 deletions.
20 changes: 13 additions & 7 deletions .travis.yml
@@ -1,30 +1,36 @@
language: ruby
cache: bundler

rvm:
- 2.3.1
- 2.2
- 2.2.5
- 2.1
- 2.0.0
- rbx-2

env:
- DB=sqlite3
- DB=mysql
- DB=postgresql

gemfile:
- gemfiles/activerecord_4.0.gemfile
- gemfiles/activerecord_4.1.gemfile
- gemfiles/activerecord_5.0.gemfile
- gemfiles/activerecord_4.2.gemfile
- gemfiles/activerecord_4.1.gemfile
- gemfiles/activerecord_4.0.gemfile

sudo: false

bundler_args: '--without local_development --jobs 3 --retry 3'

before_install:
- gem install bundler

script: bundle exec rake

matrix:
exclude:
- rvm: 2.0.0
gemfile: gemfiles/activerecord_5.0.gemfile
- rvm: 2.1
gemfile: gemfiles/activerecord_5.0.gemfile
fast_finish: true
allow_failures:
- gemfile: gemfiles/activerecord_edge.gemfile
- rvm: rbx-2
17 changes: 8 additions & 9 deletions Appraisals
@@ -1,16 +1,15 @@
appraise "activerecord-4.0" do
gem "activerecord", github: "rails/rails" , branch: '4-0-stable'
appraise 'activerecord-5.0' do
gem 'activerecord', "~> 5.0.0"
end

appraise "activerecord-4.1" do
gem "activerecord", github: "rails/rails" , branch: '4-1-stable'
appraise "activerecord-4.2" do
gem "activerecord", "~> 4.2.0"
end

appraise "activerecord-4.2" do
gem "railties", github: "rails/rails" , branch: '4-2-stable'
gem "activerecord", github: "rails/rails" , branch: '4-2-stable'
appraise "activerecord-4.1" do
gem "activerecord", "~> 4.1.0"
end

appraise 'activerecord-5.0' do
gem 'activerecord', "~> 5.0.0"
appraise "activerecord-4.0" do
gem "activerecord", "~> 4.0.0"
end
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -7,5 +7,5 @@ group :local_development do
gem 'guard-rspec'
gem 'appraisal'
gem 'rake'
gem 'byebug' , platform: :mri_21
gem 'byebug' , platforms: [:mri_21, :mri_22, :mri_23]
end
2 changes: 1 addition & 1 deletion acts-as-taggable-on.gemspec
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'activerecord', ['>= 4.0']

gem.add_development_dependency 'sqlite3'
gem.add_development_dependency 'mysql2', '~> 0.3.7'
gem.add_development_dependency 'mysql2', '~> 0.3'
gem.add_development_dependency 'pg'

gem.add_development_dependency 'rspec-rails'
Expand Down
5 changes: 3 additions & 2 deletions db/migrate/2_add_missing_unique_indices.rb
Expand Up @@ -2,7 +2,7 @@ class AddMissingUniqueIndices < ActiveRecord::Migration
def self.up
add_index :tags, :name, unique: true

remove_index :taggings, :tag_id
remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
remove_index :taggings, [:taggable_id, :taggable_type, :context]
add_index :taggings,
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
Expand All @@ -13,7 +13,8 @@ def self.down
remove_index :tags, :name

remove_index :taggings, name: 'taggings_idx'
add_index :taggings, :tag_id

add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
add_index :taggings, [:taggable_id, :taggable_type, :context]
end
end
4 changes: 2 additions & 2 deletions gemfiles/activerecord_4.0.gemfile
Expand Up @@ -2,14 +2,14 @@

source "https://rubygems.org"

gem "activerecord", :github => "rails/rails", :branch => "4-0-stable"
gem "activerecord", "~> 4.0.0"

group :local_development do
gem "guard"
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", :platform => :mri_21
gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
end

gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/activerecord_4.1.gemfile
Expand Up @@ -2,14 +2,14 @@

source "https://rubygems.org"

gem "activerecord", :github => "rails/rails", :branch => "4-1-stable"
gem "activerecord", "~> 4.1.0"

group :local_development do
gem "guard"
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", :platform => :mri_21
gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
end

gemspec :path => "../"
5 changes: 2 additions & 3 deletions gemfiles/activerecord_4.2.gemfile
Expand Up @@ -2,15 +2,14 @@

source "https://rubygems.org"

gem "railties", :github => "rails/rails", :branch => "4-2-stable"
gem "activerecord", :github => "rails/rails", :branch => "4-2-stable"
gem "activerecord", "~> 4.2.0"

group :local_development do
gem "guard"
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", :platform => :mri_21
gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
end

gemspec :path => "../"
9 changes: 3 additions & 6 deletions gemfiles/activerecord_5.0.gemfile
Expand Up @@ -2,17 +2,14 @@

source "https://rubygems.org"

# You can change the gem to your local path with `gem 'arel', path: 'local_gem_path'`
gem 'arel', github: "rails/arel" , branch: 'master'
gem "railties", github: "rails/rails" , branch: 'master'
gem "activerecord", github: "rails/rails" , branch: 'master'
gem "activerecord", "~> 5.0.0"

group :local_development do
gem "guard"
gem "guard-rspec"
gem "appraisal"
gem "rake"
gem "byebug", :platform => :mri_22
gem "byebug", :platforms => [:mri_21, :mri_22, :mri_23]
end

gemspec :path => "../"
gemspec :path => "../"
8 changes: 6 additions & 2 deletions lib/acts-as-taggable-on.rb
Expand Up @@ -2,7 +2,12 @@
require 'active_record/version'
require 'active_support/core_ext/module'

require_relative 'acts_as_taggable_on/engine' if defined?(Rails)
begin
require 'rails/engine'
require 'acts_as_taggable_on/engine'
rescue LoadError

end

require 'digest/sha1'

Expand All @@ -13,7 +18,6 @@ module ActsAsTaggableOn
autoload :TagList
autoload :GenericParser
autoload :DefaultParser
autoload :TagListParser
autoload :Taggable
autoload :Tagger
autoload :Tagging
Expand Down
1 change: 0 additions & 1 deletion lib/acts_as_taggable_on/engine.rb
@@ -1,4 +1,3 @@
require 'rails/engine'
module ActsAsTaggableOn
class Engine < Rails::Engine
end
Expand Down
2 changes: 0 additions & 2 deletions lib/acts_as_taggable_on/tag.rb
Expand Up @@ -2,8 +2,6 @@
module ActsAsTaggableOn
class Tag < ::ActiveRecord::Base

attr_accessible :name if defined?(ActiveModel::MassAssignmentSecurity)

### ASSOCIATIONS:

has_many :taggings, dependent: :destroy, class_name: '::ActsAsTaggableOn::Tagging'
Expand Down
13 changes: 1 addition & 12 deletions lib/acts_as_taggable_on/tag_list.rb
Expand Up @@ -85,6 +85,7 @@ def clean!
map!(&:parameterize) if ActsAsTaggableOn.force_parameterize

ActsAsTaggableOn.strict_case_match ? uniq! : uniq!{ |tag| tag.downcase }
self
end


Expand All @@ -99,18 +100,6 @@ def extract_and_apply_options!(args)
args.flatten!
end


## DEPRECATED
def self.from(string)
ActiveRecord::Base.logger.warn <<WARNING
ActsAsTaggableOn::TagList.from is deprecated \
and will be removed from v4.0+, use \
ActsAsTaggableOn::DefaultParser.new instead
WARNING
@parser.new(string).parse
end


end
end

21 changes: 0 additions & 21 deletions lib/acts_as_taggable_on/tag_list_parser.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/acts_as_taggable_on/taggable/ownership.rb
Expand Up @@ -108,9 +108,9 @@ def save_owned_tags

# Find all taggings that belong to the taggable (self), are owned by the owner,
# have the correct context, and are removed from the list.
ActsAsTaggableOn::Tagging.destroy_all(taggable_id: id, taggable_type: self.class.base_class.to_s,
tagger_type: owner.class.base_class.to_s, tagger_id: owner.id,
tag_id: old_tags, context: context) if old_tags.present?
ActsAsTaggableOn::Tagging.where(taggable_id: id, taggable_type: self.class.base_class.to_s,
tagger_type: owner.class.base_class.to_s, tagger_id: owner.id,
tag_id: old_tags, context: context).destroy_all if old_tags.present?

# Create new taggings:
new_tags.each do |tag|
Expand Down
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/tagging.rb
Expand Up @@ -8,8 +8,8 @@ class Tagging < ::ActiveRecord::Base #:nodoc:
scope :owned_by, ->(owner) { where(tagger: owner) }
scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) }

scope :by_contexts, ->(contexts = ['tags']) { where(context: contexts) }
scope :by_context, ->(context= 'tags') { by_contexts(context.to_s) }
scope :by_contexts, ->(contexts) { where(context: (contexts || 'tags')) }
scope :by_context, ->(context = 'tags') { by_contexts(context.to_s) }

validates_presence_of :context
validates_presence_of :tag_id
Expand Down
5 changes: 0 additions & 5 deletions lib/acts_as_taggable_on/utils.rb
Expand Up @@ -13,18 +13,13 @@ def using_postgresql?
end

def using_mysql?
#We should probably use regex for mysql to support prehistoric adapters
connection && connection.adapter_name == 'Mysql2'
end

def sha_prefix(string)
Digest::SHA1.hexdigest(string)[0..6]
end

def active_record4?
::ActiveRecord::VERSION::MAJOR == 4
end

def active_record5?
::ActiveRecord::VERSION::MAJOR == 5
end
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/version.rb
@@ -1,4 +1,4 @@
module ActsAsTaggableOn
VERSION = '3.5.0'
VERSION = '4.0.0.pre'
end

2 changes: 1 addition & 1 deletion spec/acts_as_taggable_on/acts_as_tagger_spec.rb
Expand Up @@ -72,7 +72,7 @@
expect(@taggable.tag_list_on(:foo_boo)).to be_empty
expect(-> {
@tagger.tag(@taggable, with: 'this, and, that', on: :foo_boo, force: false)
}).to raise_error
}).to raise_error(RuntimeError)
end

it 'should not create the tag context on-the-fly when the default is over-ridden' do
Expand Down
46 changes: 0 additions & 46 deletions spec/acts_as_taggable_on/tag_list_parser_spec.rb

This file was deleted.

14 changes: 13 additions & 1 deletion spec/acts_as_taggable_on/tag_list_spec.rb
Expand Up @@ -83,6 +83,18 @@
new_tag_list = tag_list.concat(another_tag_list)
expect(new_tag_list.class).to eq(ActsAsTaggableOn::TagList)
end

context 'without duplicates' do
let(:arr) { ['crazy', 'alien'] }
let(:another_tag_list) { ActsAsTaggableOn::TagList.new(*arr) }
it 'adds other list' do
expect(tag_list.concat(another_tag_list)).to eq(%w[awesome radical crazy alien])
end

it 'adds other array' do
expect(tag_list.concat(arr)).to eq(%w[awesome radical crazy alien])
end
end
end

describe '#to_s' do
Expand All @@ -92,7 +104,7 @@

it 'should be able to call to_s on a frozen tag list' do
tag_list.freeze
expect(-> { tag_list.add('cool', 'rad,bodacious') }).to raise_error
expect(-> { tag_list.add('cool', 'rad,bodacious') }).to raise_error(RuntimeError)
expect(-> { tag_list.to_s }).to_not raise_error
end
end
Expand Down

0 comments on commit 9a0b7d1

Please sign in to comment.