jerryvos-acts-as-taggable-on 1.0.6

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,165 @@
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 find by tag with multiple contexts" do
60
+ @taggable.skill_list = "ruby, rails, css"
61
+ @taggable.tag_list = "bob, charlie"
62
+ @taggable.save
63
+ TaggableModel.find_tagged_with("bob", :on => [:skills, :tags]).first.should == @taggable
64
+ end
65
+
66
+ it "should be able to use the tagged_with named scope" do
67
+ @taggable.skill_list = "ruby, rails, css"
68
+ @taggable.tag_list = "bob, charlie"
69
+ @taggable.save
70
+ TaggableModel.tagged_with("ruby", {}).first.should == @taggable
71
+ TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
72
+ TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
73
+ end
74
+
75
+ it "should not care about case" do
76
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
77
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
78
+
79
+ Tag.find(:all).size.should == 1
80
+ TaggableModel.find_tagged_with("ruby").should == TaggableModel.find_tagged_with("Ruby")
81
+ end
82
+
83
+ it "should be able to get tag counts on model as a whole" do
84
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
85
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
86
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
87
+ TaggableModel.tag_counts.should_not be_empty
88
+ TaggableModel.skill_counts.should_not be_empty
89
+ end
90
+
91
+ it "should be able to get tag counts on an association" do
92
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
93
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
94
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
95
+ bob.tag_counts.first.count.should == 2
96
+ charlie.skill_counts.first.count.should == 1
97
+ end
98
+
99
+ it "should be able to set a custom tag context list" do
100
+ bob = TaggableModel.create(:name => "Bob")
101
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
102
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
103
+ bob.save
104
+ bob.reload
105
+ bob.tags_on(:rotors).should_not be_empty
106
+ end
107
+
108
+ it "should be able to find tagged on a custom tag context" do
109
+ bob = TaggableModel.create(:name => "Bob")
110
+ bob.set_tag_list_on(:rotors, "spinning, jumping")
111
+ bob.tag_list_on(:rotors).should == ["spinning","jumping"]
112
+ bob.save
113
+ TaggableModel.find_tagged_with("spinning", :on => :rotors).should_not be_empty
114
+ end
115
+
116
+ it "should be able to use named scopes to chain tag finds" do
117
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
118
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
119
+ steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, python')
120
+
121
+ # Let's only find those productive Rails developers
122
+ TaggableModel.tagged_with('rails', :on => :skills).all(:order => 'taggable_models.name').should == [bob, frank]
123
+ TaggableModel.tagged_with('happier', :on => :tags).all(:order => 'taggable_models.name').should == [bob, steve]
124
+ TaggableModel.tagged_with('rails', :on => :skills).tagged_with('happier', :on => :tags).should == [bob]
125
+ end
126
+
127
+ describe "Single Table Inheritance" do
128
+ before do
129
+ [TaggableModel, Tag, Tagging, TaggableUser].each(&:delete_all)
130
+ @taggable = TaggableModel.new(:name => "taggable")
131
+ @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
132
+ @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
133
+ end
134
+
135
+ it "should be able to save tags for inherited models" do
136
+ @inherited_same.tag_list = "bob, kelso"
137
+ @inherited_same.save
138
+ InheritingTaggableModel.find_tagged_with("bob").first.should == @inherited_same
139
+ end
140
+
141
+ it "should find STI tagged models on the superclass" do
142
+ @inherited_same.tag_list = "bob, kelso"
143
+ @inherited_same.save
144
+ TaggableModel.find_tagged_with("bob").first.should == @inherited_same
145
+ end
146
+
147
+ it "should be able to add on contexts only to some subclasses" do
148
+ @inherited_different.part_list = "fork, spoon"
149
+ @inherited_different.save
150
+ InheritingTaggableModel.find_tagged_with("fork", :on => :parts).should be_empty
151
+ AlteredInheritingTaggableModel.find_tagged_with("fork", :on => :parts).first.should == @inherited_different
152
+ end
153
+
154
+ it "should have different tag_counts_on for inherited models" do
155
+ @inherited_same.tag_list = "bob, kelso"
156
+ @inherited_same.save!
157
+ @inherited_different.tag_list = "fork, spoon"
158
+ @inherited_different.save!
159
+
160
+ InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
161
+ AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
162
+ TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
163
+ end
164
+ end
165
+ 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,32 @@
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.datetime "created_at"
8
+ t.integer "tagger_id", :limit => 11
9
+ t.string "tagger_type"
10
+ end
11
+
12
+ add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
13
+ add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
14
+
15
+ create_table "tags", :force => true do |t|
16
+ t.string "name"
17
+ end
18
+
19
+ create_table :taggable_models, :force => true do |t|
20
+ t.column :name, :string
21
+ t.column :type, :string
22
+ #t.column :cached_tag_list, :string
23
+ end
24
+ create_table :taggable_users, :force => true do |t|
25
+ t.column :name, :string
26
+ end
27
+ create_table :other_taggable_models, :force => true do |t|
28
+ t.column :name, :string
29
+ t.column :type, :string
30
+ #t.column :cached_tag_list, :string
31
+ end
32
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --reverse
3
+ --backtrace
@@ -0,0 +1,46 @@
1
+ # require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
2
+ require 'rubygems'
3
+ require 'active_support'
4
+ require 'active_record'
5
+ require 'spec'
6
+
7
+ module Spec::Example::ExampleGroupMethods
8
+ alias :context :describe
9
+ end
10
+
11
+ TEST_DATABASE_FILE = File.join(File.dirname(__FILE__), '..', 'test.sqlite3')
12
+
13
+ File.unlink(TEST_DATABASE_FILE) if File.exist?(TEST_DATABASE_FILE)
14
+ ActiveRecord::Base.establish_connection(
15
+ "adapter" => "sqlite3", "database" => TEST_DATABASE_FILE
16
+ )
17
+
18
+ RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
19
+
20
+ load(File.dirname(__FILE__) + '/schema.rb')
21
+
22
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
23
+ require File.join(File.dirname(__FILE__), '..', 'init')
24
+
25
+ class TaggableModel < ActiveRecord::Base
26
+ acts_as_taggable_on :tags, :languages
27
+ acts_as_taggable_on :skills
28
+ end
29
+
30
+ class OtherTaggableModel < ActiveRecord::Base
31
+ acts_as_taggable_on :tags, :languages
32
+ end
33
+
34
+ class InheritingTaggableModel < TaggableModel
35
+ end
36
+
37
+ class AlteredInheritingTaggableModel < TaggableModel
38
+ acts_as_taggable_on :parts
39
+ end
40
+
41
+ class TaggableUser < ActiveRecord::Base
42
+ acts_as_tagger
43
+ end
44
+
45
+ class UntaggableModel < ActiveRecord::Base
46
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jerryvos-acts-as-taggable-on
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-02 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: With ActsAsTaggableOn, you could tag a single model on several contexts, such as skills, interests, and awards. It also provides other advanced functionality.
17
+ email: michael@intridea.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - CHANGELOG
26
+ - MIT-LICENSE
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - lib/acts-as-taggable-on.rb
31
+ - lib/acts_as_taggable_on/acts_as_taggable_on.rb
32
+ - lib/acts_as_taggable_on/acts_as_tagger.rb
33
+ - lib/acts_as_taggable_on/tag.rb
34
+ - lib/acts_as_taggable_on/tag_list.rb
35
+ - lib/acts_as_taggable_on/tagging.rb
36
+ - lib/acts_as_taggable_on/tags_helper.rb
37
+ - rails/init.rb
38
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
39
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
40
+ - spec/acts_as_taggable_on/tag_list_spec.rb
41
+ - spec/acts_as_taggable_on/tag_spec.rb
42
+ - spec/acts_as_taggable_on/taggable_spec.rb
43
+ - spec/acts_as_taggable_on/tagger_spec.rb
44
+ - spec/acts_as_taggable_on/tagging_spec.rb
45
+ - spec/schema.rb
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/mbleigh/acts-as-taggable-on
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple tagging contexts on a single model.
76
+ test_files:
77
+ - spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
78
+ - spec/acts_as_taggable_on/acts_as_tagger_spec.rb
79
+ - spec/acts_as_taggable_on/tag_list_spec.rb
80
+ - spec/acts_as_taggable_on/tag_spec.rb
81
+ - spec/acts_as_taggable_on/taggable_spec.rb
82
+ - spec/acts_as_taggable_on/tagger_spec.rb
83
+ - spec/acts_as_taggable_on/tagging_spec.rb
84
+ - spec/schema.rb
85
+ - spec/spec_helper.rb