ordered-tags 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Tag do
4
+ before(:each) do
5
+ @tag = Tag.new
6
+ @user = TaggableModel.create(:name => "Pablo")
7
+ end
8
+
9
+ it "should require a name" do
10
+ @tag.valid?
11
+ @tag.errors.on(:name).should == "can't be blank"
12
+ @tag.name = "something"
13
+ @tag.valid?
14
+ @tag.errors.on(:name).should be_nil
15
+ end
16
+
17
+ it "should equal a tag with the same name" do
18
+ @tag.name = "awesome"
19
+ new_tag = Tag.new(:name => "awesome")
20
+ new_tag.should == @tag
21
+ end
22
+
23
+ it "should return its name when to_s is called" do
24
+ @tag.name = "cool"
25
+ @tag.to_s.should == "cool"
26
+ end
27
+ end
@@ -0,0 +1,204 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Taggable" do
4
+ before(:each) do
5
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
6
+ @taggable = TaggableModel.new(:name => "Bob Jones")
7
+ end
8
+
9
+ it "should be able to create tags" do
10
+ @taggable.skill_list = "ruby, rails, css"
11
+ @taggable.instance_variable_get("@skill_list").instance_of?(TagList).should be_true
12
+ @taggable.save
13
+
14
+ Tag.find(:all).size.should == 3
15
+ end
16
+
17
+ it "should be able to create tags through the tag list directly" do
18
+ @taggable.tag_list_on(:test).add("hello")
19
+ @taggable.save
20
+ @taggable.reload
21
+ @taggable.tag_list_on(:test).should == ["hello"]
22
+ end
23
+
24
+ it "should differentiate between contexts" do
25
+ @taggable.skill_list = "ruby, rails, css"
26
+ @taggable.tag_list = "ruby, bob, charlie"
27
+ @taggable.save
28
+ @taggable.reload
29
+ @taggable.skill_list.include?("ruby").should be_true
30
+ @taggable.skill_list.include?("bob").should be_false
31
+ end
32
+
33
+ it "should be able to remove tags through list alone" do
34
+ @taggable.skill_list = "ruby, rails, css"
35
+ @taggable.save
36
+ @taggable.reload
37
+ @taggable.should have(3).skills
38
+ @taggable.skill_list = "ruby, rails"
39
+ @taggable.save
40
+ @taggable.reload
41
+ @taggable.should have(2).skills
42
+ end
43
+
44
+ it "should be able to find by tag" do
45
+ @taggable.skill_list = "ruby, rails, css"
46
+ @taggable.save
47
+ TaggableModel.find_tagged_with("ruby").first.should == @taggable
48
+ end
49
+
50
+ it "should be able to find by tag with context" do
51
+ @taggable.skill_list = "ruby, rails, css"
52
+ @taggable.tag_list = "bob, charlie"
53
+ @taggable.save
54
+ TaggableModel.find_tagged_with("ruby").first.should == @taggable
55
+ TaggableModel.find_tagged_with("bob", :on => :skills).first.should_not == @taggable
56
+ TaggableModel.find_tagged_with("bob", :on => :tags).first.should == @taggable
57
+ end
58
+
59
+ it "should be able to use the tagged_with named scope" do
60
+ @taggable.skill_list = "ruby, rails, css"
61
+ @taggable.tag_list = "bob, charlie"
62
+ @taggable.save
63
+
64
+ TaggableModel.tagged_with("ruby").first.should == @taggable
65
+ TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
66
+ TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
67
+ end
68
+
69
+ it "should not care about case" do
70
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
71
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
72
+
73
+ Tag.find(:all).size.should == 1
74
+ TaggableModel.find_tagged_with("ruby").should == TaggableModel.find_tagged_with("Ruby")
75
+ end
76
+
77
+ it "should be able to get tag counts on model as a whole" do
78
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
79
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
80
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
81
+ TaggableModel.tag_counts.should_not be_empty
82
+ TaggableModel.skill_counts.should_not be_empty
83
+ end
84
+
85
+ it "should be able to get all tag counts on model as whole" do
86
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
87
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
88
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
89
+
90
+ TaggableModel.all_tag_counts.should_not be_empty
91
+ TaggableModel.all_tag_counts.first.count.should == 3 # ruby
92
+ end
93
+
94
+ it "should be able to get scoped tag counts" do
95
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
96
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
97
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
98
+
99
+ TaggableModel.tagged_with("ruby").tag_counts.first.count.should == 2 # ruby
100
+ TaggableModel.tagged_with("ruby").skill_counts.first.count.should == 1 # ruby
101
+ end
102
+
103
+ it "should be able to get all scoped tag counts" do
104
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
105
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
106
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
107
+
108
+ TaggableModel.tagged_with("ruby").all_tag_counts.first.count.should == 3 # ruby
109
+ end
110
+
111
+ it "should be able to set a custom tag context list" do
112
+ bob = TaggableModel.create(:name => "Bob")
113
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
114
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
115
+ bob.save
116
+ bob.reload
117
+ bob.tags_on(:rotors).should_not be_empty
118
+ end
119
+
120
+ it "should be able to find tagged" do
121
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
122
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
123
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
124
+
125
+ TaggableModel.find_tagged_with("ruby", :order => 'taggable_models.name').should == [bob, frank, steve]
126
+ TaggableModel.find_tagged_with("ruby, rails", :order => 'taggable_models.name').should == [bob, frank]
127
+ TaggableModel.find_tagged_with(["ruby", "rails"], :order => 'taggable_models.name').should == [bob, frank]
128
+ end
129
+
130
+ it "should be able to find tagged on a custom tag context" do
131
+ bob = TaggableModel.create(:name => "Bob")
132
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
133
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
134
+ bob.save
135
+ TaggableModel.find_tagged_with("spinning", :on => :rotors).should == [bob]
136
+ end
137
+
138
+ it "should be able to use named scopes to chain tag finds" do
139
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
140
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
141
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, python')
142
+
143
+ # Let's only find those productive Rails developers
144
+ TaggableModel.tagged_with('rails', :on => :skills, :order => 'taggable_models.name').should == [bob, frank]
145
+ TaggableModel.tagged_with('happier', :on => :tags, :order => 'taggable_models.name').should == [bob, steve]
146
+ TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).should == [bob]
147
+ TaggableModel.tagged_with('rails').tagged_with('happier', :on => :tags).should == [bob]
148
+ end
149
+
150
+ it "should be able to find tagged with only the matching tags" do
151
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "lazy, happier")
152
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "fitter, happier, inefficient")
153
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => "fitter, happier")
154
+
155
+ TaggableModel.find_tagged_with("fitter, happier", :match_all => true).should == [steve]
156
+ end
157
+
158
+ it "should be able to find tagged with some excluded tags" do
159
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "happier, lazy")
160
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "happier")
161
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => "happier")
162
+
163
+ TaggableModel.find_tagged_with("lazy", :exclude => true).should == [frank, steve]
164
+ end
165
+
166
+ describe "Single Table Inheritance" do
167
+ before do
168
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
169
+ @taggable = TaggableModel.new(:name => "taggable")
170
+ @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
171
+ @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
172
+ end
173
+
174
+ it "should be able to save tags for inherited models" do
175
+ @inherited_same.tag_list = "bob, kelso"
176
+ @inherited_same.save
177
+ InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
178
+ end
179
+
180
+ it "should find STI tagged models on the superclass" do
181
+ @inherited_same.tag_list = "bob, kelso"
182
+ @inherited_same.save
183
+ TaggableModel.find_tagged_with("bob").first.should == @inherited_same
184
+ end
185
+
186
+ it "should be able to add on contexts only to some subclasses" do
187
+ @inherited_different.part_list = "fork, spoon"
188
+ @inherited_different.save
189
+ InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
190
+ AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
191
+ end
192
+
193
+ it "should have different tag_counts_on for inherited models" do
194
+ @inherited_same.tag_list = "bob, kelso"
195
+ @inherited_same.save!
196
+ @inherited_different.tag_list = "fork, spoon"
197
+ @inherited_different.save!
198
+
199
+ InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
200
+ AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
201
+ TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Tagger" do
4
+ before(:each) do
5
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
6
+ @user = TaggableUser.new
7
+ @taggable = TaggableModel.new(:name => "Bob Jones")
8
+ end
9
+
10
+ it "should have taggings" do
11
+ @user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
12
+ @user.owned_taggings.size == 2
13
+ end
14
+
15
+ it "should have tags" do
16
+ @user.tag(@taggable, :with=>'ruby,scheme', :on=>:tags)
17
+ @user.owned_tags.size == 2
18
+ end
19
+
20
+ it "is tagger" do
21
+ @user.is_tagger?.should(be_true)
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Tagging do
4
+ before(:each) do
5
+ @tagging = Tagging.new
6
+ end
7
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,33 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table "taggings", :force => true do |t|
3
+ t.integer "tag_id", :limit => 11
4
+ t.integer "taggable_id", :limit => 11
5
+ t.string "taggable_type"
6
+ t.string "context"
7
+ t.integer "position"
8
+ t.datetime "created_at"
9
+ t.integer "tagger_id", :limit => 11
10
+ t.string "tagger_type"
11
+ end
12
+
13
+ add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
14
+ add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
15
+
16
+ create_table "tags", :force => true do |t|
17
+ t.string "name"
18
+ end
19
+
20
+ create_table :taggable_models, :force => true do |t|
21
+ t.column :name, :string
22
+ t.column :type, :string
23
+ #t.column :cached_tag_list, :string
24
+ end
25
+ create_table :taggable_users, :force => true do |t|
26
+ t.column :name, :string
27
+ end
28
+ create_table :other_taggable_models, :force => true do |t|
29
+ t.column :name, :string
30
+ t.column :type, :string
31
+ #t.column :cached_tag_list, :string
32
+ end
33
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --reverse
3
+ --backtrace
@@ -0,0 +1,45 @@
1
+ # require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
2
+ require 'rubygems'
3
+ require 'activerecord'
4
+ require 'spec'
5
+
6
+ module Spec::Example::ExampleGroupMethods
7
+ alias :context :describe
8
+ end
9
+
10
+ TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
11
+
12
+ File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
13
+ ActiveRecord::Base.establish_connection(
14
+ "adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
15
+ )
16
+
17
+ RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
18
+
19
+ load(File.dirname(__FILE__) + '/schema.rb')
20
+
21
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
22
+ require File.join(File.dirname(__FILE__), '..', 'init')
23
+
24
+ class TaggableModel < ActiveRecord::Base
25
+ acts_as_taggable_on :tags, :languages
26
+ acts_as_taggable_on :skills
27
+ end
28
+
29
+ class OtherTaggableModel < ActiveRecord::Base
30
+ acts_as_taggable_on :tags, :languages
31
+ end
32
+
33
+ class InheritingTaggableModel < TaggableModel
34
+ end
35
+
36
+ class AlteredInheritingTaggableModel < TaggableModel
37
+ acts_as_taggable_on :parts
38
+ end
39
+
40
+ class TaggableUser < ActiveRecord::Base
41
+ acts_as_tagger
42
+ end
43
+
44
+ class UntaggableModel < ActiveRecord::Base
45
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ordered-tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Benoit B\xC3\xA9n\xC3\xA9zech"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: acts_as_list
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Based on ActsAsTaggableOn
26
+ email: benoit.benezech@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - CHANGELOG
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION
39
+ - lib/acts-as-taggable-on.rb
40
+ - lib/acts_as_taggable_on/acts_as_taggable_on.rb
41
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
42
+ - lib/acts_as_taggable_on/tag.rb
43
+ - lib/acts_as_taggable_on/tag_list.rb
44
+ - lib/acts_as_taggable_on/tagging.rb
45
+ - lib/acts_as_taggable_on/tags_helper.rb
46
+ - rails/init.rb
47
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
48
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
49
+ - spec/acts_as_taggable_on/tag_list_spec.rb
50
+ - spec/acts_as_taggable_on/tag_spec.rb
51
+ - spec/acts_as_taggable_on/taggable_spec.rb
52
+ - spec/acts_as_taggable_on/tagger_spec.rb
53
+ - spec/acts_as_taggable_on/tagging_spec.rb
54
+ - spec/schema.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/bbenezech/acts-as-taggable-on
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Based on ActsAsTaggableOn
85
+ test_files:
86
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
87
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
88
+ - spec/acts_as_taggable_on/tag_list_spec.rb
89
+ - spec/acts_as_taggable_on/tag_spec.rb
90
+ - spec/acts_as_taggable_on/taggable_spec.rb
91
+ - spec/acts_as_taggable_on/tagger_spec.rb
92
+ - spec/acts_as_taggable_on/tagging_spec.rb
93
+ - spec/schema.rb
94
+ - spec/spec_helper.rb