acts-as-taggable-on 3.2.2 → 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc40e6d7c5c8b741bfc71aee7ae2406c6f824108
4
- data.tar.gz: 3c89e20ed3b39ef33d52724d4bb8b9aa3e5738f9
3
+ metadata.gz: 755e4d829ddc31ccd6ffb8385594ed8c5c64971f
4
+ data.tar.gz: 1ce12972b7d9d436484d619843a7bdf316a5c3b7
5
5
  SHA512:
6
- metadata.gz: e4142af492646d113a10fa0ae4815d91a281f2a55d60fb70b653a96d4ac58e24c56e1e10bcbf9907bbcc06cee2b476b6ec4a568cc25e5247578a140cbf388d85
7
- data.tar.gz: eceb8e025f83cdbc9e237405eac982aa3b7c7ef0f54d803fcd80d1ed837b833d4f07fe549f0eb0eaa443edb5cdc84bcad79555a67a886e7fc706b46aa5d37b35
6
+ metadata.gz: c8f129a07903598bcb765b260bd14db168b4a6fbf6989cef816157ae6350cadd733f75ca6cc0169e00fa8c19b59710198b868f52044f07efca451c44aa9a046c
7
+ data.tar.gz: 578b3d36b654b9343a36df3a7086b40b3ef32f6b43973d92c0f31251ea095405b692d2ef131ba74086366d117eef0fcd2334b51ce8f7ce3c0266481819a0a2a1
data/.travis.yml CHANGED
@@ -3,15 +3,19 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1.1
5
5
  - rbx-2
6
+ - ruby-head
7
+
6
8
  env:
7
9
  - DB=sqlite3
8
10
  - DB=mysql
9
11
  - DB=postgresql
12
+
10
13
  gemfile:
11
14
  - gemfiles/activerecord_3.2.gemfile
12
15
  - gemfiles/activerecord_4.0.gemfile
13
16
  - gemfiles/activerecord_4.1.gemfile
14
17
  - gemfiles/activerecord_edge.gemfile
18
+
15
19
  cache: bundler
16
20
  script: bundle exec rake
17
21
  before_install: gem install bundler
@@ -20,4 +24,19 @@ matrix:
20
24
  fast_finish: true
21
25
  allow_failures:
22
26
  - gemfile: gemfiles/activerecord_edge.gemfile
23
- - rvm: rbx-2
27
+ - rvm: rbx-2
28
+ exclude:
29
+ - rvm: 1.9.3
30
+ gemfile: ci/Gemfile.activerecord-4.0.x
31
+ - rvm: 1.9.3
32
+ gemfile: ci/Gemfile.activerecord-4.1.x
33
+ - rvm: 1.9.3
34
+ gemfile: ci/Gemfile.activerecord-edge
35
+ - rvm: rbx-2
36
+ gemfile: ci/Gemfile.activerecord-3.2.x
37
+ - rvm: ruby-head
38
+ gemfile: ci/Gemfile.activerecord-3.2.x
39
+ - rvm: ruby-head
40
+ gemfile: ci/Gemfile.activerecord-4.0.x
41
+ - rvm: ruby-head
42
+ gemfile: ci/Gemfile.activerecord-4.1.x
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ group :local_development do
7
7
  gem 'guard-rspec'
8
8
  gem 'appraisal'
9
9
  gem 'rake'
10
+ gem 'byebug'
10
11
  end
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
29
29
  gem.add_development_dependency 'mysql2'
30
30
  gem.add_development_dependency 'pg'
31
31
 
32
- gem.add_development_dependency 'rspec-rails' , '~> 3.0.0.beta2'
32
+ gem.add_development_dependency 'rspec-rails' , '~> 3.0.0.beta1'
33
33
  gem.add_development_dependency 'rspec-its', '~> 1.0'
34
34
  gem.add_development_dependency 'rspec', '3.0.0.beta2'
35
35
  gem.add_development_dependency 'ammeter', '~> 1.0'
@@ -10,6 +10,7 @@ group :local_development do
10
10
  gem "guard-rspec"
11
11
  gem "appraisal"
12
12
  gem "rake"
13
+ gem "byebug"
13
14
  end
14
15
 
15
16
  gemspec :path => "../"
@@ -10,6 +10,7 @@ group :local_development do
10
10
  gem "guard-rspec"
11
11
  gem "appraisal"
12
12
  gem "rake"
13
+ gem "byebug"
13
14
  end
14
15
 
15
16
  gemspec :path => "../"
@@ -10,6 +10,7 @@ group :local_development do
10
10
  gem "guard-rspec"
11
11
  gem "appraisal"
12
12
  gem "rake"
13
+ gem "byebug"
13
14
  end
14
15
 
15
16
  gemspec :path => "../"
@@ -11,6 +11,7 @@ group :local_development do
11
11
  gem "guard-rspec"
12
12
  gem "appraisal"
13
13
  gem "rake"
14
+ gem "byebug"
14
15
  end
15
16
 
16
17
  gemspec :path => "../"
@@ -53,6 +53,7 @@ module ActsAsTaggableOn::Taggable
53
53
  # * :order - A piece of SQL to order by. Eg 'tags.count desc' or 'taggings.created_at desc'
54
54
  # * :on - Scope the find to only include a certain context
55
55
  def all_tags(options = {})
56
+ options = options.dup
56
57
  options.assert_valid_keys :start_at, :end_at, :conditions, :order, :limit, :on
57
58
 
58
59
  ## Generate conditions:
@@ -87,6 +88,7 @@ module ActsAsTaggableOn::Taggable
87
88
  # * :at_most - Exclude tags with a frequency greater than the given value
88
89
  # * :on - Scope the find to only include a certain context
89
90
  def all_tag_counts(options = {})
91
+ options = options.dup
90
92
  options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :on, :id
91
93
 
92
94
  ## Generate conditions:
@@ -83,6 +83,7 @@ module ActsAsTaggableOn::Taggable
83
83
  # User.tagged_with("awesome", "cool", :owned_by => foo ) # Users that are tagged with just awesome and cool by 'foo'
84
84
  def tagged_with(tags, options = {})
85
85
  tag_list = ActsAsTaggableOn::TagList.from(tags)
86
+ options = options.dup
86
87
  empty_result = where('1 = 0')
87
88
 
88
89
  return empty_result if tag_list.empty?
@@ -382,7 +383,7 @@ module ActsAsTaggableOn::Taggable
382
383
 
383
384
  # Destroy old taggings:
384
385
  if old_tags.present?
385
- ActsAsTaggableOn::Tagging.destroy_all(tagger_type: nil, tagger_id: nil, context: context.to_s, tag_id: old_tags)
386
+ self.taggings.not_owned.by_context(context).destroy_all(tag_id: old_tags)
386
387
  end
387
388
 
388
389
  # Create new taggings:
@@ -41,7 +41,7 @@ module ActsAsTaggableOn::Taggable
41
41
  end
42
42
 
43
43
  def related_tags_for(context, klass, options = {})
44
- tags_to_ignore = Array.wrap(options.delete(:ignore)).map(&:to_s) || []
44
+ tags_to_ignore = Array.wrap(options[:ignore]).map(&:to_s) || []
45
45
  tags_to_find = tags_on(context).map { |t| t.name }.reject { |t| tags_to_ignore.include? t }
46
46
  related_where(klass, ["#{exclude_self(klass, id)} #{klass.table_name}.#{klass.primary_key} = #{ActsAsTaggableOn::Tagging.table_name}.taggable_id AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = '#{klass.base_class}' AND #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND #{ActsAsTaggableOn::Tag.table_name}.name IN (?)", tags_to_find])
47
47
  end
@@ -1,4 +1,4 @@
1
- # coding: utf-8
1
+ # encoding: utf-8
2
2
  module ActsAsTaggableOn
3
3
  class Tag < ::ActiveRecord::Base
4
4
 
@@ -15,6 +15,12 @@ module ActsAsTaggableOn
15
15
  belongs_to :taggable, polymorphic: true
16
16
  belongs_to :tagger, polymorphic: true
17
17
 
18
+ scope :owned_by, ->(owner) { where(tagger: owner) }
19
+ scope :not_owned, -> { where(tagger_id: nil, tagger_type: nil) }
20
+
21
+ scope :by_contexts, ->(contexts = ['tags']) { where(context: contexts) }
22
+ scope :by_context, ->(context= 'tags') { by_contexts(context.to_s) }
23
+
18
24
  validates_presence_of :context
19
25
  validates_presence_of :tag_id
20
26
 
@@ -1,4 +1,4 @@
1
1
  module ActsAsTaggableOn
2
- VERSION = '3.2.2'
2
+ VERSION = '3.2.3'
3
3
  end
4
4
 
@@ -494,6 +494,12 @@ describe 'Taggable' do
494
494
  end
495
495
  end
496
496
 
497
+ it 'should options key not be deleted' do
498
+ options = {:exclude => true}
499
+ TaggableModel.tagged_with("foo", options)
500
+ expect(options).to eq({:exclude => true})
501
+ end
502
+
497
503
  context 'Duplicates' do
498
504
  context 'should not create duplicate taggings' do
499
505
  let(:bob) { TaggableModel.create(name: 'Bob') }
@@ -23,5 +23,29 @@ describe ActsAsTaggableOn::Tagging do
23
23
  2.times { ActsAsTaggableOn::Tagging.create(taggable: @taggable, tag: @tag, context: 'tags') }
24
24
  }).to change(ActsAsTaggableOn::Tagging, :count).by(1)
25
25
  end
26
-
27
- end
26
+
27
+ it 'should not delete tags of other records' do
28
+ 6.times { TaggableModel.create(name: 'Bob Jones', tag_list: 'very, serious, bug') }
29
+ expect(ActsAsTaggableOn::Tag.count).to eq(3)
30
+ taggable = TaggableModel.first
31
+ taggable.tag_list = 'bug'
32
+ taggable.save
33
+
34
+ expect(taggable.tag_list).to eq(['bug'])
35
+
36
+ another_taggable = TaggableModel.where('id != ?', taggable.id).sample
37
+ expect(another_taggable.tag_list.sort).to eq(%w(very serious bug).sort)
38
+ end
39
+
40
+ pending 'context scopes' do
41
+ describe '.by_context'
42
+
43
+ describe '.by_contexts'
44
+
45
+ describe '.owned_by'
46
+
47
+ describe '.not_owned'
48
+
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -99,14 +99,14 @@ dependencies:
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 3.0.0.beta2
102
+ version: 3.0.0.beta1
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 3.0.0.beta2
109
+ version: 3.0.0.beta1
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: rspec-its
112
112
  requirement: !ruby/object:Gem::Requirement