acts-as-taggable-on-for-domains 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe TagList do
4
+ before(:each) do
5
+ @tag_list = TagList.new("awesome","radical")
6
+ end
7
+
8
+ it "should be an array" do
9
+ @tag_list.is_a?(Array).should be_true
10
+ end
11
+
12
+ it "should be able to be add a new tag word" do
13
+ @tag_list.add("cool")
14
+ @tag_list.include?("cool").should be_true
15
+ end
16
+
17
+ it "should be able to add delimited lists of words" do
18
+ @tag_list.add("cool, wicked", :parse => true)
19
+ @tag_list.include?("cool").should be_true
20
+ @tag_list.include?("wicked").should be_true
21
+ end
22
+
23
+ it "should be able to add an array of words" do
24
+ @tag_list.add(["cool", "wicked"], :parse => true)
25
+ @tag_list.include?("cool").should be_true
26
+ @tag_list.include?("wicked").should be_true
27
+ end
28
+
29
+ it "should be able to remove words" do
30
+ @tag_list.remove("awesome")
31
+ @tag_list.include?("awesome").should be_false
32
+ end
33
+
34
+ it "should be able to remove delimited lists of words" do
35
+ @tag_list.remove("awesome, radical", :parse => true)
36
+ @tag_list.should be_empty
37
+ end
38
+
39
+ it "should be able to remove an array of words" do
40
+ @tag_list.remove(["awesome", "radical"], :parse => true)
41
+ @tag_list.should be_empty
42
+ end
43
+
44
+ it "should give a delimited list of words when converted to string" do
45
+ @tag_list.to_s.should == "awesome, radical"
46
+ end
47
+
48
+ it "should quote escape tags with commas in them" do
49
+ @tag_list.add("cool","rad,bodacious")
50
+ @tag_list.to_s.should == "awesome, radical, cool, \"rad,bodacious\""
51
+ end
52
+ end
@@ -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,186 @@
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 tag counts on an association" 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
+ bob.tag_counts.first.count.should == 2
90
+ charlie.skill_counts.first.count.should == 1
91
+ end
92
+
93
+ it "should be able to set a custom tag context list" do
94
+ bob = TaggableModel.create(:name => "Bob")
95
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
96
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
97
+ bob.save
98
+ bob.reload
99
+ bob.tags_on(:rotors).should_not be_empty
100
+ end
101
+
102
+ it "should be able to find tagged" do
103
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
104
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
105
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
106
+
107
+ TaggableModel.find_tagged_with("ruby", :order => 'taggable_models.name').should == [bob, frank, steve]
108
+ TaggableModel.find_tagged_with("ruby, rails", :order => 'taggable_models.name').should == [bob, frank]
109
+ TaggableModel.find_tagged_with(["ruby", "rails"], :order => 'taggable_models.name').should == [bob, frank]
110
+ end
111
+
112
+ it "should be able to find tagged on a custom tag context" do
113
+ bob = TaggableModel.create(:name => "Bob")
114
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
115
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
116
+ bob.save
117
+ TaggableModel.find_tagged_with("spinning", :on => :rotors).should == [bob]
118
+ end
119
+
120
+ it "should be able to use named scopes to chain tag finds" 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, python')
124
+
125
+ # Let's only find those productive Rails developers
126
+ TaggableModel.tagged_with('rails', :on => :skills, :order => 'taggable_models.name').should == [bob, frank]
127
+ TaggableModel.tagged_with('happier', :on => :tags, :order => 'taggable_models.name').should == [bob, steve]
128
+ TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).should == [bob]
129
+ TaggableModel.tagged_with('rails').tagged_with('happier', :on => :tags).should == [bob]
130
+ end
131
+
132
+ it "should be able to find tagged with only the matching tags" do
133
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "lazy, happier")
134
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "fitter, happier, inefficient")
135
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => "fitter, happier")
136
+
137
+ TaggableModel.find_tagged_with("fitter, happier", :match_all => true).should == [steve]
138
+ end
139
+
140
+ it "should be able to find tagged with some excluded tags" do
141
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "happier, lazy")
142
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "happier")
143
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => "happier")
144
+
145
+ TaggableModel.find_tagged_with("lazy", :exclude => true).should == [frank, steve]
146
+ end
147
+
148
+ describe "Single Table Inheritance" do
149
+ before do
150
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
151
+ @taggable = TaggableModel.new(:name => "taggable")
152
+ @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
153
+ @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
154
+ end
155
+
156
+ it "should be able to save tags for inherited models" do
157
+ @inherited_same.tag_list = "bob, kelso"
158
+ @inherited_same.save
159
+ InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
160
+ end
161
+
162
+ it "should find STI tagged models on the superclass" do
163
+ @inherited_same.tag_list = "bob, kelso"
164
+ @inherited_same.save
165
+ TaggableModel.find_tagged_with("bob").first.should == @inherited_same
166
+ end
167
+
168
+ it "should be able to add on contexts only to some subclasses" do
169
+ @inherited_different.part_list = "fork, spoon"
170
+ @inherited_different.save
171
+ InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
172
+ AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
173
+ end
174
+
175
+ it "should have different tag_counts_on for inherited models" do
176
+ @inherited_same.tag_list = "bob, kelso"
177
+ @inherited_same.save!
178
+ @inherited_different.tag_list = "fork, spoon"
179
+ @inherited_different.save!
180
+
181
+ InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
182
+ AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
183
+ TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
184
+ end
185
+ end
186
+ 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,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Tagging do
4
+ before(:each) do
5
+ @tagging = Tagging.new
6
+ end
7
+
8
+ describe 'Tagging' do
9
+ it 'should respond to "domain_id"' do
10
+ @tagging.should respond_to(:domain_id)
11
+ end
12
+ end
13
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,34 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table "taggings", :force => true do |t|
3
+ t.integer "domain_id", :limit => 11
4
+ t.integer "tag_id", :limit => 11
5
+ t.integer "taggable_id", :limit => 11
6
+ t.string "taggable_type"
7
+ t.string "context"
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", ["domain_id", "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 :domain_id, :integer
22
+ t.column :name, :string
23
+ t.column :type, :string
24
+ #t.column :cached_tag_list, :string
25
+ end
26
+ create_table :taggable_users, :force => true do |t|
27
+ t.column :name, :string
28
+ end
29
+ create_table :other_taggable_models, :force => true do |t|
30
+ t.column :name, :string
31
+ t.column :type, :string
32
+ #t.column :cached_tag_list, :string
33
+ end
34
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --reverse
3
+ --backtrace
@@ -0,0 +1,53 @@
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
46
+
47
+ class Domain
48
+ class << self
49
+ def current_domain_id
50
+ 1
51
+ end
52
+ end
53
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts-as-taggable-on-for-domains
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ - Josh N. Abbott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-11-13 00:00:00 -08:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Same as ActsAsTaggableOn but tagging happens within the context of a domain id. This means an object could be tagged with something for one domain, but the same object, in the context of a different domain id, could have completely different taggings.
18
+ email: joshnabbott@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README
26
+ - README.rdoc
27
+ files:
28
+ - .document
29
+ - .gitignore
30
+ - LICENSE
31
+ - README
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - acts-as-taggable-on-for-domains.gemspec
36
+ - generators/acts_as_taggable_on_migration/acts_as_taggable_on_migration_generator.rb
37
+ - generators/acts_as_taggable_on_migration/templates/migration.rb
38
+ - init.rb
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_taggable_on_scoped_by_domain.rb
42
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
43
+ - lib/acts_as_taggable_on/tag.rb
44
+ - lib/acts_as_taggable_on/tag_list.rb
45
+ - lib/acts_as_taggable_on/tagging.rb
46
+ - lib/acts_as_taggable_on/tags_helper.rb
47
+ - rails/init.rb
48
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
49
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
50
+ - spec/acts_as_taggable_on/tag_list_spec.rb
51
+ - spec/acts_as_taggable_on/tag_spec.rb
52
+ - spec/acts_as_taggable_on/taggable_spec.rb
53
+ - spec/acts_as_taggable_on/tagger_spec.rb
54
+ - spec/acts_as_taggable_on/tagging_spec.rb
55
+ - spec/schema.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ - uninstall.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/joshnabbott/acts-as-taggable-on-for-domains
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: The same as ActsAsTaggableOn but implements domain scoping.
87
+ test_files:
88
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
89
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
90
+ - spec/acts_as_taggable_on/tag_list_spec.rb
91
+ - spec/acts_as_taggable_on/tag_spec.rb
92
+ - spec/acts_as_taggable_on/taggable_spec.rb
93
+ - spec/acts_as_taggable_on/tagger_spec.rb
94
+ - spec/acts_as_taggable_on/tagging_spec.rb
95
+ - spec/schema.rb
96
+ - spec/spec_helper.rb