acts-as-taggable-on 1.0.17 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.17
1
+ 1.0.18
@@ -19,15 +19,15 @@ module ActiveRecord
19
19
  args.compact! if args
20
20
  for tag_type in args
21
21
  tag_type = tag_type.to_s
22
- # use aliased_join_table_name for context condition so that sphix can join multiple
22
+ # use aliased_join_table_name for context condition so that sphinx can join multiple
23
23
  # tag references from same model without getting an ambiguous column error
24
- self.class_eval do
24
+ class_eval do
25
25
  has_many "#{tag_type.singularize}_taggings".to_sym, :as => :taggable, :dependent => :destroy,
26
- :include => :tag, :conditions => ['#{aliased_join_table_name rescue "taggings"}.context = ?',tag_type], :class_name => "Tagging"
26
+ :include => :tag, :conditions => ['#{aliased_join_table_name || Tagging.table_name rescue Tagging.table_name}.context = ?',tag_type], :class_name => "Tagging"
27
27
  has_many "#{tag_type}".to_sym, :through => "#{tag_type.singularize}_taggings".to_sym, :source => :tag
28
28
  end
29
29
 
30
- self.class_eval <<-RUBY
30
+ class_eval <<-RUBY
31
31
  def self.taggable?
32
32
  true
33
33
  end
@@ -86,7 +86,7 @@ module ActiveRecord
86
86
  if respond_to?(:tag_types)
87
87
  write_inheritable_attribute( :tag_types, (tag_types + args).uniq )
88
88
  else
89
- self.class_eval do
89
+ class_eval do
90
90
  write_inheritable_attribute(:tag_types, args.uniq)
91
91
  class_inheritable_reader :tag_types
92
92
 
@@ -185,7 +185,8 @@ module ActiveRecord
185
185
 
186
186
  { :joins => joins.join(" "),
187
187
  :group => group,
188
- :conditions => conditions.join(" AND ") }.update(options)
188
+ :conditions => conditions.join(" AND "),
189
+ :readonly => false }.update(options)
189
190
  end
190
191
 
191
192
  # Calculate the tag counts for all tags.
@@ -225,9 +226,9 @@ module ActiveRecord
225
226
  joins << sanitize_sql(["AND #{Tagging.table_name}.context = ?",options.delete(:on).to_s]) unless options[:on].nil?
226
227
  joins << " INNER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id"
227
228
 
228
- unless self.descends_from_active_record?
229
+ unless descends_from_active_record?
229
230
  # Current model is STI descendant, so add type checking to the join condition
230
- joins << " AND #{table_name}.#{self.inheritance_column} = '#{self.name}'"
231
+ joins << " AND #{table_name}.#{inheritance_column} = '#{name}'"
231
232
  end
232
233
 
233
234
  # Based on a proposed patch by donV to ActiveRecord Base
@@ -317,7 +318,7 @@ module ActiveRecord
317
318
  end
318
319
 
319
320
  def tag_counts_on(context, options={})
320
- self.class.tag_counts_on(context, options.merge(:id => self.id))
321
+ self.class.tag_counts_on(context, options.merge(:id => id))
321
322
  end
322
323
 
323
324
  def related_tags_for(context, klass, options = {})
@@ -327,9 +328,9 @@ module ActiveRecord
327
328
  end
328
329
 
329
330
  def related_search_options(context, klass, options = {})
330
- tags_to_find = self.tags_on(context).collect { |t| t.name }
331
+ tags_to_find = tags_on(context).collect { |t| t.name }
331
332
 
332
- exclude_self = "#{klass.table_name}.id != #{self.id} AND" if self.class == klass
333
+ exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass
333
334
 
334
335
  { :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
335
336
  :from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
@@ -346,9 +347,9 @@ module ActiveRecord
346
347
  end
347
348
 
348
349
  def matching_context_search_options(search_context, result_context, klass, options = {})
349
- tags_to_find = self.tags_on(search_context).collect { |t| t.name }
350
+ tags_to_find = tags_on(search_context).collect { |t| t.name }
350
351
 
351
- exclude_self = "#{klass.table_name}.id != #{self.id} AND" if self.class == klass
352
+ exclude_self = "#{klass.table_name}.id != #{id} AND" if self.class == klass
352
353
 
353
354
  { :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
354
355
  :from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
@@ -373,7 +374,7 @@ module ActiveRecord
373
374
  new_tag_names = instance_variable_get("@#{tag_type.singularize}_list") - tags_on(tag_type).map(&:name)
374
375
  old_tags = tags_on(tag_type, owner).reject { |tag| instance_variable_get("@#{tag_type.singularize}_list").include?(tag.name) }
375
376
 
376
- self.class.transaction do
377
+ transaction do
377
378
  base_tags.delete(*old_tags) if old_tags.any?
378
379
  new_tag_names.each do |new_tag_name|
379
380
  new_tag = Tag.find_or_create_with_like_by_name(new_tag_name)
@@ -388,7 +389,7 @@ module ActiveRecord
388
389
 
389
390
  def reload_with_tag_list(*args)
390
391
  self.class.tag_types.each do |tag_type|
391
- self.instance_variable_set("@#{tag_type.to_s.singularize}_list", nil)
392
+ instance_variable_set("@#{tag_type.to_s.singularize}_list", nil)
392
393
  end
393
394
 
394
395
  reload_without_tag_list(*args)
@@ -1,13 +1,24 @@
1
1
  class Tag < ActiveRecord::Base
2
+
3
+ attr_accessible :name
4
+
5
+ ### ASSOCIATIONS:
6
+
2
7
  has_many :taggings, :dependent => :destroy
3
8
 
9
+ ### VALIDATIONS:
10
+
4
11
  validates_presence_of :name
5
12
  validates_uniqueness_of :name
6
13
 
14
+ ### NAMED SCOPES:
15
+
7
16
  named_scope :named, lambda { |name| { :conditions => ["name = ?", name] } }
8
17
  named_scope :named_like, lambda { |name| { :conditions => ["name LIKE ?", "%#{name}%"] } }
9
18
  named_scope :named_like_any, lambda { |list| { :conditions => list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR ") } }
10
19
 
20
+ ### METHODS:
21
+
11
22
  # LIKE is used for cross-database case-insensitivity
12
23
  def self.find_or_create_with_like_by_name(name)
13
24
  find(:first, :conditions => ["name LIKE ?", name]) || create(:name => name)
@@ -1,4 +1,8 @@
1
1
  class Tagging < ActiveRecord::Base #:nodoc:
2
+ attr_accessible :tag, :tag_id, :context,
3
+ :taggable, :taggable_type, :taggable_id,
4
+ :tagger, :tagger_type, :tagger_id
5
+
2
6
  belongs_to :tag
3
7
  belongs_to :taggable, :polymorphic => true
4
8
  belongs_to :tagger, :polymorphic => true
@@ -108,6 +108,12 @@ describe "Taggable" do
108
108
  TaggableModel.all_tag_counts.first.count.should == 3 # ruby
109
109
  end
110
110
 
111
+ it "should not return read-only records" do
112
+ TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
113
+
114
+ TaggableModel.tagged_with("ruby").first.should_not be_readonly
115
+ end
116
+
111
117
  it "should be able to get scoped tag counts" do
112
118
  bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
113
119
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
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: 1.0.17
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-05 00:00:00 +01:00
12
+ date: 2010-01-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15