tagger 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,12 @@
1
+ class Link < ActiveRecord::Base
2
+ taggable :separator => :space
3
+ end
4
+
5
+ class Post < ActiveRecord::Base
6
+ belongs_to :category
7
+ taggable :scope => :category
8
+ end
9
+
10
+ class Category < ActiveRecord::Base
11
+ has_many :posts
12
+ end
@@ -0,0 +1,125 @@
1
+ require "spec_helper"
2
+
3
+ describe Tagger do
4
+ fixtures :posts, :categories, :links, :tags
5
+
6
+ before do
7
+ @link = links(:simples_ideias)
8
+ @category = categories(:programming)
9
+ @post = posts(:all_about_rails)
10
+ end
11
+
12
+ it "should have many tags" do
13
+ expect { @post.tags }.to_not raise_error
14
+ end
15
+
16
+ it "should have many taggings" do
17
+ expect { @post.taggings }.to_not raise_error
18
+ end
19
+
20
+ it "should create tags" do
21
+ @post.tagged_with = "rails, programming, howto"
22
+ @post.save
23
+ @post.tags.count.should == 3
24
+ end
25
+
26
+ it "should create tags separated by spaces" do
27
+ @link.tagged_with = %[programming "nando vieira" blog]
28
+ @link.save
29
+ @link.tags.count.should == 3
30
+ end
31
+
32
+ it "should return joined list" do
33
+ @post.tagged_with = "rails, programming, howto"
34
+ @post.save
35
+ @post.tagged_with.should == "howto, programming, rails"
36
+ end
37
+
38
+ it "should accept multiples words when separated by space" do
39
+ @link.tagged_with = %["Ruby on Rails" programming howto]
40
+ @link.save
41
+ @link.tagged_with.should == %[howto programming "Ruby on Rails"]
42
+ end
43
+
44
+ it "should sort tags by name" do
45
+ @link.tagged_with = "e f g a z"
46
+ @link.save
47
+ @link.tagged_with.should == "a e f g z"
48
+ end
49
+
50
+ it "should create tag using scope" do
51
+ @post.tagged_with = "rails, programming"
52
+ @post.save
53
+
54
+ tagging = @post.taggings.first
55
+ tagging.should_not be_nil
56
+ tagging.scope == categories(:programming)
57
+ end
58
+
59
+ describe Tag do
60
+ it "should return its name on the to_s method" do
61
+ Tag.create(:name => "rails").to_s.should == "rails"
62
+ end
63
+
64
+ it "should strip empty tags when using comma" do
65
+ Tag.parse("rails,,,,,,,,,,programming", :comma).should == %w[programming rails]
66
+ end
67
+
68
+ it "should strip empty tags when using space" do
69
+ Tag.parse("rails programming", :space).should == %w[programming rails]
70
+ end
71
+
72
+ it "should recognize multiple words when using comma" do
73
+ Tag.parse("ruby on rails, web development, programming, ruby", :comma).should == ["programming", "ruby", "ruby on rails", "web development"]
74
+ end
75
+
76
+ it "should recognize multiple words when using space" do
77
+ Tag.parse(%["ruby on rails" "web development" programming ruby], :space).should == ["programming", "ruby", "ruby on rails", "web development"]
78
+ end
79
+ end
80
+
81
+ describe "Tag.cloud" do
82
+ it "should return total as number" do
83
+ posts(:all_about_rails).update_attribute(:tagged_with, "ruby, rails, web")
84
+ posts(:ideas).update_attribute(:tagged_with, "ruby, rails, web")
85
+
86
+ @tags = Tag.cloud(:post)
87
+ @tags.first.total.should == 2
88
+ end
89
+
90
+ it "should return tags using scope" do
91
+ posts(:all_about_rails).update_attribute(:tagged_with, "ruby, rails, web")
92
+ posts(:ideas).update_attribute(:tagged_with, "ruby, rails, web")
93
+
94
+ @tags = Tag.cloud(:post, :scope => categories(:essays))
95
+ @tags.first.total.should == 1
96
+ end
97
+
98
+ it "should return limited tags" do
99
+ @post.update_attribute(:tagged_with, "ruby, rails, programming, howto")
100
+
101
+ @tags = Tag.cloud(:post, :limit => 2)
102
+ @tags.size.should == 2
103
+ @tags.first.name == "howto"
104
+ @tags.last.name == "rails"
105
+ end
106
+ end
107
+
108
+ describe Tagging do
109
+ it "should set scope" do
110
+ tagging = create_tagging(:scope => categories(:programming))
111
+ tagging.scope.should == categories(:programming)
112
+ tagging.scopable_type == "Category"
113
+ tagging.scopable_id == categories(:programming).id
114
+ end
115
+ end
116
+
117
+ private
118
+ def create_tagging(options={})
119
+ Tagging.create({
120
+ :tag => tags(:ruby),
121
+ :scope => categories(:programming),
122
+ :taggable => posts(:all_about_rails)
123
+ }.merge(options))
124
+ end
125
+ end
data/tagger.gemspec ADDED
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tagger}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nando Vieira"]
12
+ s.date = %q{2010-10-05}
13
+ s.description = %q{Add tagging support for Rails apps}
14
+ s.email = %q{fnando.vieira@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "MIT-LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "lib/tagger.rb",
25
+ "lib/tagger/active_record.rb",
26
+ "lib/tagger/generator.rb",
27
+ "lib/tagger/helper.rb",
28
+ "lib/tagger/railtie.rb",
29
+ "lib/tagger/tag.rb",
30
+ "lib/tagger/tagging.rb",
31
+ "lib/tagger/version.rb",
32
+ "spec/fixtures/categories.yml",
33
+ "spec/fixtures/links.yml",
34
+ "spec/fixtures/posts.yml",
35
+ "spec/fixtures/tags.yml",
36
+ "spec/helpers/helper_spec.rb",
37
+ "spec/schema.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/support/config/boot.rb",
40
+ "spec/support/config/database.yml",
41
+ "spec/support/log/test.log",
42
+ "spec/support/models.rb",
43
+ "spec/tagger_spec.rb",
44
+ "tagger.gemspec",
45
+ "templates/taggings.rb",
46
+ "templates/tags.rb"
47
+ ]
48
+ s.homepage = %q{http://github.com/fnando/tagger}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.3.7}
52
+ s.summary = %q{Add tagging support for Rails apps}
53
+ s.test_files = [
54
+ "spec/helpers/helper_spec.rb",
55
+ "spec/schema.rb",
56
+ "spec/spec_helper.rb",
57
+ "spec/support/config/boot.rb",
58
+ "spec/support/models.rb",
59
+ "spec/tagger_spec.rb"
60
+ ]
61
+
62
+ if s.respond_to? :specification_version then
63
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
+ s.specification_version = 3
65
+
66
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
68
+ else
69
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
70
+ end
71
+ else
72
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
73
+ end
74
+ end
75
+
@@ -0,0 +1,15 @@
1
+ class CreateTaggings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :taggings do |t|
4
+ t.references :tag, :user
5
+ t.references :scopable, :taggable, :polymorphic => true
6
+ end
7
+
8
+ add_index :taggings, [:taggable_type, :taggable_id]
9
+ add_index :taggings, [:scopable_type, :scopable_id]
10
+ end
11
+
12
+ def self.down
13
+ drop_table :taggings
14
+ end
15
+ end
data/templates/tags.rb ADDED
@@ -0,0 +1,13 @@
1
+ class CreateTags < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :tags do |t|
4
+ t.string :name
5
+ end
6
+
7
+ add_index :tags, :name
8
+ end
9
+
10
+ def self.down
11
+ drop_table :tags
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagger
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Nando Vieira
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-05 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Add tagging support for Rails apps
36
+ email: fnando.vieira@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - lib/tagger.rb
50
+ - lib/tagger/active_record.rb
51
+ - lib/tagger/generator.rb
52
+ - lib/tagger/helper.rb
53
+ - lib/tagger/railtie.rb
54
+ - lib/tagger/tag.rb
55
+ - lib/tagger/tagging.rb
56
+ - lib/tagger/version.rb
57
+ - spec/fixtures/categories.yml
58
+ - spec/fixtures/links.yml
59
+ - spec/fixtures/posts.yml
60
+ - spec/fixtures/tags.yml
61
+ - spec/helpers/helper_spec.rb
62
+ - spec/schema.rb
63
+ - spec/spec_helper.rb
64
+ - spec/support/config/boot.rb
65
+ - spec/support/config/database.yml
66
+ - spec/support/log/test.log
67
+ - spec/support/models.rb
68
+ - spec/tagger_spec.rb
69
+ - tagger.gemspec
70
+ - templates/taggings.rb
71
+ - templates/tags.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/fnando/tagger
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.7
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Add tagging support for Rails apps
104
+ test_files:
105
+ - spec/helpers/helper_spec.rb
106
+ - spec/schema.rb
107
+ - spec/spec_helper.rb
108
+ - spec/support/config/boot.rb
109
+ - spec/support/models.rb
110
+ - spec/tagger_spec.rb