tagalong 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,11 +16,11 @@ module Tagalong
16
16
 
17
17
  module InstanceMethods
18
18
  def has_tag?(name)
19
- return self.tagalong_tags(true).map { |r| r.name }.include?(name)
19
+ return self.tagalong_tags.map { |r| r.name }.include?(name)
20
20
  end
21
21
 
22
22
  def tags
23
- return self.tagalong_tags(true).order("number_of_references DESC").map { |r| r.name }
23
+ return self.tagalong_tags.order("number_of_references DESC").map { |r| r.name }
24
24
  end
25
25
  end
26
26
  end
@@ -28,9 +28,12 @@ module Tagalong
28
28
 
29
29
  def tags(taggable = nil)
30
30
  if taggable == nil
31
- return self.tagalong_tags(true).order("number_of_references DESC").map { |r| r.name }
31
+ return self.tagalong_tags.order("number_of_references DESC").map { |r| r.name }
32
32
  else
33
- return self.tagalong_tags(true).joins("LEFT OUTER JOIN tagalong_taggings ON tagalong_taggings.tagalong_tag_id = tagalong_tags.id").select("tagalong_tags.id, tagalong_tags.name, tagalong_tags.number_of_references, tagalong_taggings.id as used").order("number_of_references DESC").map { |r| { :tag => r.name, :used => !r.used.nil?, :number_of_references => r.number_of_references } }
33
+ return self.tagalong_tags.
34
+ joins("LEFT OUTER JOIN tagalong_taggings ON tagalong_taggings.tagalong_tag_id = tagalong_tags.id AND tagalong_taggings.taggable_id = '#{taggable.id.to_s}'").
35
+ select("tagalong_tags.id, tagalong_tags.name, tagalong_tags.number_of_references, tagalong_taggings.id as used").
36
+ order("number_of_references DESC").map { |r| { :tag => r.name, :used => !r.used.nil?, :number_of_references => r.number_of_references } }
34
37
  end
35
38
  end
36
39
 
@@ -1,3 +1,3 @@
1
1
  module Tagalong
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -55,6 +55,31 @@ describe "Tagger" do
55
55
  { :tag => "bar", :used => false, :number_of_references => 0 }
56
56
  ]
57
57
  end
58
+
59
+ it "returns a hash of tags with usage information about the passed taggable on secondary calls when the taggable changes" do
60
+ tag = @user.tagalong_tags.create!(:name => "foo", :number_of_references => 1)
61
+ @contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
62
+ @user.tagalong_tags.create!(:name => "bar", :number_of_references => 0)
63
+ tag = @user.tagalong_tags.create!(:name => "car", :number_of_references => 1)
64
+ @contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
65
+ @user.tags(@contact).should == [
66
+ { :tag => "foo", :used => true, :number_of_references => 1 },
67
+ { :tag => "car", :used => true, :number_of_references => 1 },
68
+ { :tag => "bar", :used => false, :number_of_references => 0 }
69
+ ]
70
+ @other_contact = Contact.create!(:name => "My Other Taggable")
71
+ tag = @user.tagalong_tags.create!(:name => "jones", :number_of_references => 1)
72
+ @other_contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
73
+ tag = @user.tagalong_tags.create!(:name => "jimmy", :number_of_references => 2)
74
+ @other_contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
75
+ @user.tags(@other_contact).should == [
76
+ { :tag => "jimmy", :used => true, :number_of_references => 2 },
77
+ { :tag => "foo", :used => false, :number_of_references => 1 },
78
+ { :tag => "car", :used => false, :number_of_references => 1 },
79
+ { :tag => "jones", :used => true, :number_of_references => 1 },
80
+ { :tag => "bar", :used => false, :number_of_references => 0 }
81
+ ]
82
+ end
58
83
  end
59
84
  end
60
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagalong
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-12 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70212871717240 !ruby/object:Gem::Requirement
16
+ requirement: &70224007918900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70212871717240
24
+ version_requirements: *70224007918900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70212871716800 !ruby/object:Gem::Requirement
27
+ requirement: &70224007918420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70212871716800
35
+ version_requirements: *70224007918420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70212871716300 !ruby/object:Gem::Requirement
38
+ requirement: &70224007917920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70212871716300
46
+ version_requirements: *70224007917920
47
47
  description: A Rails tagging plugin that makes sense.
48
48
  email:
49
49
  - cyphactor@gmail.com