tagalong 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,6 @@ module Tagalong
4
4
  belongs_to :taggable, :polymorphic => true
5
5
 
6
6
  validates_presence_of :tagalong_tag_id
7
- validates_presence_of :tagalong_tag_id, :scope => [ :taggable_type, :taggable_id ]
7
+ validates_uniqueness_of :tagalong_tag_id, :scope => [ :taggable_type, :taggable_id ]
8
8
  end
9
9
  end
@@ -15,12 +15,12 @@ module Tagalong
15
15
  end
16
16
 
17
17
  module InstanceMethods
18
- def has_tag?(name)
18
+ def tagged_with?(name)
19
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.order("number_of_references DESC").map { |r| r.name }
23
+ return self.tagalong_tags.order("name ASC").map { |r| r.name }
24
24
  end
25
25
  end
26
26
  end
@@ -28,12 +28,12 @@ module Tagalong
28
28
 
29
29
  def tags(taggable = nil)
30
30
  if taggable == nil
31
- return self.tagalong_tags.order("number_of_references DESC").map { |r| r.name }
31
+ return self.tagalong_tags.order("name ASC").map { |r| r.name }
32
32
  else
33
33
  return self.tagalong_tags.
34
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
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 } }
36
+ order("name ASC").map { |r| { :tag => r.name, :used => !r.used.nil?, :number_of_references => r.number_of_references } }
37
37
  end
38
38
  end
39
39
 
@@ -1,3 +1,3 @@
1
1
  module Tagalong
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -10,15 +10,15 @@ describe "Taggable" do
10
10
  end
11
11
 
12
12
  describe "Integration" do
13
- describe "#has_tag?" do
13
+ describe "#tagged_with?" do
14
14
  it "returns true if the taggable has the given tag" do
15
15
  tag = @user.tagalong_tags.create!(:name => "foo")
16
16
  @contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
17
- @contact.has_tag?("foo").should be_true
17
+ @contact.tagged_with?("foo").should be_true
18
18
  end
19
19
 
20
20
  it "returns false if the taggable does NOT have the given tag" do
21
- @contact.has_tag?("bar").should be_false
21
+ @contact.tagged_with?("bar").should be_false
22
22
  end
23
23
  end
24
24
 
@@ -27,7 +27,7 @@ describe "Taggable" do
27
27
  @contact.tagalong_tags.create!(:name => "foo")
28
28
  @contact.tagalong_tags.create!(:name => "bar")
29
29
  @contact.tagalong_tags.create!(:name => "car")
30
- @contact.tags.should == ["foo", "bar", "car"]
30
+ @contact.tags.should == ["bar", "car", "foo"]
31
31
  end
32
32
 
33
33
  it "returns list of tags currently applied in descending order of references" do
@@ -31,14 +31,14 @@ describe "Tagger" do
31
31
  @user.tagalong_tags.create!(:name => "foo")
32
32
  @user.tagalong_tags.create!(:name => "bar")
33
33
  @user.tagalong_tags.create!(:name => "car")
34
- @user.tags.should == ["foo", "bar", "car"]
34
+ @user.tags.should == ["bar", "car", "foo"]
35
35
  end
36
36
 
37
- it "returns the list of tags in descending order of number of references" do
37
+ it "returns the list of tags in ascending alphabetical order" do
38
38
  @user.tagalong_tags.create!(:name => "foo", :number_of_references => 20)
39
39
  @user.tagalong_tags.create!(:name => "bar", :number_of_references => 100)
40
40
  @user.tagalong_tags.create!(:name => "car", :number_of_references => 8)
41
- @user.tags.should == ["bar", "foo", "car"]
41
+ @user.tags.should == ["bar", "car", "foo"]
42
42
  end
43
43
  end
44
44
 
@@ -50,9 +50,9 @@ describe "Tagger" do
50
50
  tag = @user.tagalong_tags.create!(:name => "car", :number_of_references => 1)
51
51
  @contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
52
52
  @user.tags(@contact).should == [
53
- { :tag => "foo", :used => true, :number_of_references => 1 },
53
+ { :tag => "bar", :used => false, :number_of_references => 0 },
54
54
  { :tag => "car", :used => true, :number_of_references => 1 },
55
- { :tag => "bar", :used => false, :number_of_references => 0 }
55
+ { :tag => "foo", :used => true, :number_of_references => 1 }
56
56
  ]
57
57
  end
58
58
 
@@ -63,9 +63,9 @@ describe "Tagger" do
63
63
  tag = @user.tagalong_tags.create!(:name => "car", :number_of_references => 1)
64
64
  @contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
65
65
  @user.tags(@contact).should == [
66
- { :tag => "foo", :used => true, :number_of_references => 1 },
66
+ { :tag => "bar", :used => false, :number_of_references => 0 },
67
67
  { :tag => "car", :used => true, :number_of_references => 1 },
68
- { :tag => "bar", :used => false, :number_of_references => 0 }
68
+ { :tag => "foo", :used => true, :number_of_references => 1 }
69
69
  ]
70
70
  @other_contact = Contact.create!(:name => "My Other Taggable")
71
71
  tag = @user.tagalong_tags.create!(:name => "jones", :number_of_references => 1)
@@ -73,11 +73,11 @@ describe "Tagger" do
73
73
  tag = @user.tagalong_tags.create!(:name => "jimmy", :number_of_references => 2)
74
74
  @other_contact.tagalong_taggings.create!(:tagalong_tag_id => tag.id)
75
75
  @user.tags(@other_contact).should == [
76
- { :tag => "jimmy", :used => true, :number_of_references => 2 },
77
- { :tag => "foo", :used => false, :number_of_references => 1 },
76
+ { :tag => "bar", :used => false, :number_of_references => 0 },
78
77
  { :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 }
78
+ { :tag => "foo", :used => false, :number_of_references => 1 },
79
+ { :tag => "jimmy", :used => true, :number_of_references => 2 },
80
+ { :tag => "jones", :used => true, :number_of_references => 1 }
81
81
  ]
82
82
  end
83
83
  end
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.3
4
+ version: 0.0.4
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-14 00:00:00.000000000 Z
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70224007918900 !ruby/object:Gem::Requirement
16
+ requirement: &70166717593920 !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: *70224007918900
24
+ version_requirements: *70166717593920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70224007918420 !ruby/object:Gem::Requirement
27
+ requirement: &70166717593440 !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: *70224007918420
35
+ version_requirements: *70166717593440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70224007917920 !ruby/object:Gem::Requirement
38
+ requirement: &70166717592940 !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: *70224007917920
46
+ version_requirements: *70166717592940
47
47
  description: A Rails tagging plugin that makes sense.
48
48
  email:
49
49
  - cyphactor@gmail.com