mongoid-simple-tags 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  rvm:
2
2
  - 1.9.3
3
-
3
+ services: mongodb
4
4
  script: rake spec
data/Gemfile.lock CHANGED
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-simple-tags (0.0.6)
4
+ mongoid-simple-tags (0.0.7)
5
5
  bson_ext (~> 1.6)
6
6
  mongoid (~> 3.0.3)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.7)
12
- activesupport (= 3.2.7)
11
+ activemodel (3.2.8)
12
+ activesupport (= 3.2.8)
13
13
  builder (~> 3.0.0)
14
- activesupport (3.2.7)
14
+ activesupport (3.2.8)
15
15
  i18n (~> 0.6)
16
16
  multi_json (~> 1.0)
17
- bson (1.6.4)
18
- bson_ext (1.6.4)
19
- bson (~> 1.6.4)
20
- builder (3.0.0)
17
+ bson (1.7.0)
18
+ bson_ext (1.7.0)
19
+ bson (~> 1.7.0)
20
+ builder (3.0.3)
21
21
  diff-lcs (1.1.3)
22
- i18n (0.6.0)
23
- mongoid (3.0.3)
22
+ i18n (0.6.1)
23
+ mongoid (3.0.5)
24
24
  activemodel (~> 3.1)
25
25
  moped (~> 1.1)
26
26
  origin (~> 1.0)
27
27
  tzinfo (~> 0.3.22)
28
- moped (1.2.0)
28
+ moped (1.2.1)
29
29
  multi_json (1.3.6)
30
- origin (1.0.4)
30
+ origin (1.0.8)
31
31
  rspec (2.10.0)
32
32
  rspec-core (~> 2.10.0)
33
33
  rspec-expectations (~> 2.10.0)
data/README.rdoc CHANGED
@@ -6,11 +6,11 @@ mongoid-simple-tags is a basic and simple tagging system for mongoid using map-r
6
6
  == Install
7
7
 
8
8
  Add the following to Gemfile:
9
-
9
+
10
10
  gem "mongoid-simple-tags", "0.0.7"
11
11
 
12
12
  == Usage
13
-
13
+
14
14
  === Model
15
15
 
16
16
  class User
@@ -34,9 +34,10 @@ mongoid-simple-tags is a basic and simple tagging system for mongoid using map-r
34
34
  User.tagged_with("linux") # => [u, u2]
35
35
 
36
36
  # using map-reduce function
37
-
38
- User.all_tags #=>[{:name=>"free software", :count=>1}, {:name=>"linux", :count=>2}, {:name=>"tucuman", :count=>1}]
39
37
 
38
+ User.all_tags #=>[{:name=>"free software", :count=>1}, {:name=>"linux", :count=>2}, {:name=>"tucuman", :count=>1}]
39
+
40
+ User.tag_list #=>["free software", "linux", "tucuman"]
40
41
 
41
42
  == Copyright
42
43
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -3,15 +3,15 @@ module Mongoid
3
3
  module Taggable
4
4
  def self.included(base)
5
5
  base.class_eval do |klass|
6
- klass.field :tags, :type => Array
6
+ klass.field :tags, :type => Array, :default => []
7
7
  klass.index({ tags: 1 }, { background: true })
8
-
8
+
9
9
  include InstanceMethods
10
10
  extend ClassMethods
11
-
11
+
12
12
  end
13
13
  end
14
-
14
+
15
15
  module InstanceMethods
16
16
  def tag_list=(tags)
17
17
  self.tags = tags.split(",").collect{ |t| t.strip }.delete_if{ |t| t.blank? }
@@ -20,8 +20,12 @@ module Mongoid
20
20
  def tag_list
21
21
  self.tags.join(", ") if tags
22
22
  end
23
+
24
+ def tags
25
+ super || []
26
+ end
23
27
  end
24
-
28
+
25
29
 
26
30
  module ClassMethods
27
31
 
@@ -57,13 +61,17 @@ module Mongoid
57
61
  warn "[DEPRECATION] `scoped_tags` is deprecated. Please use `all_tags` instead."
58
62
  all_tags(scope)
59
63
  end
60
-
64
+
61
65
  def tagged_with(tags)
62
66
  tags = [tags] unless tags.is_a? Array
63
- criteria.in(:tags => tags).to_a
67
+ criteria.in(:tags => tags)
68
+ end
69
+
70
+ def tag_list
71
+ self.all_tags.collect{|tag| tag[:name]}
64
72
  end
65
73
  end
66
-
74
+
67
75
  end
68
76
  end
69
77
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "mongoid-simple-tags"
5
- s.version = "0.0.7"
5
+ s.version = "0.0.8"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["chebyte"]
8
8
  s.email = ["maurotorres@gmail.com"]
@@ -19,16 +19,29 @@ describe "A Taggable model" do
19
19
  let(:user) { User.new(name: 'Tuquito') }
20
20
 
21
21
  it "should have a tag_list method" do
22
- user.respond_to?(:tag_list)
22
+ user.should respond_to(:tag_list)
23
+ end
24
+
25
+ it "should have a tag_list class method" do
26
+ User.should respond_to(:tag_list)
23
27
  end
24
28
 
25
29
  it "should be able to update a tag list" do
26
30
  tag_list = "linux, tucuman, free software"
27
31
  tags = tag_list.split(',').map{ |tag| tag.strip}.flatten
28
-
32
+
29
33
  user.tag_list = tag_list
30
34
  user.tags.should == tags
31
35
  end
36
+
37
+ it "returns an empty array if there are no tags" do
38
+ user.tags = nil
39
+ user.tags.should_not be_nil
40
+ user.tags.should eql([])
41
+ end
42
+
43
+
44
+
32
45
  end
33
46
 
34
47
 
@@ -37,15 +50,15 @@ describe "A Taggable model with tags assigned" do
37
50
  before(:each) do
38
51
  @user = User.create!(name: 'Tuquito', tag_list: "linux, tucuman, free software")
39
52
  end
40
-
41
- it "should be able to find tagged_with objects" do
53
+
54
+ it "should be able to find tagged_with objects" do
42
55
  User.tagged_with('linux').first.should == @user
43
56
  User.tagged_with(['tucuman', 'free software']).first.should == @user
44
57
  end
45
58
 
46
59
  it "should be able to find tagged_with objects if more than one object is present" do
47
60
  user_2 = User.create!(name: 'ubuntu', tag_list: 'linux')
48
-
61
+
49
62
  tagged_with_list = User.tagged_with('linux')
50
63
  tagged_with_list.include?(@user).should be_true
51
64
  tagged_with_list.include?(user_2).should be_true
@@ -54,7 +67,7 @@ describe "A Taggable model with tags assigned" do
54
67
  it "should return all_tags per Model class" do
55
68
  User.create(name: 'ubuntu', tag_list: 'linux')
56
69
 
57
- expected_tag_list = [
70
+ expected_tag_list = [
58
71
  {:name => "free software", :count => 1},
59
72
  {:name => "linux", :count => 2},
60
73
  {:name => "tucuman", :count => 1}
@@ -62,11 +75,16 @@ describe "A Taggable model with tags assigned" do
62
75
  User.all_tags.should == expected_tag_list
63
76
  end
64
77
 
78
+ it "returns an array of all tags used on all instances of a model" do
79
+ User.create(name: 'ubuntu', tag_list: 'linux')
80
+ User.tag_list.sort.should == ["linux", "tucuman", "free software"].sort
81
+ end
82
+
65
83
  end
66
84
 
67
85
  describe "A Taggable model with scope" do
68
86
 
69
- before(:each) do
87
+ before(:each) do
70
88
  @organization_1 = Organization.create(name: 'Qualica')
71
89
  @user_1 = @organization_1.users.create(name: 'User1', tag_list: "ubuntu, linux, tucuman")
72
90
  @user_2 = @organization_1.users.create(name: 'User2', tag_list: "ubuntu, linux, tucuman")
@@ -76,14 +94,14 @@ describe "A Taggable model with scope" do
76
94
  @user_4 = @organization_2.users.create(name: 'User4', tag_list: 'ubuntu, linux, tucuman')
77
95
  end
78
96
 
79
- it "should return scoped tags when passing one option" do
97
+ it "should return scoped tags when passing one option" do
80
98
  results = User.all_tags(organization_id: @organization_1.id)
81
99
  results.empty?.should be_false
82
100
 
83
101
  results.include?( {:name => "linux", :count => 2 } ).should be_true
84
102
  results.include?( {:name => "ubuntu", :count => 2 } ).should be_true
85
103
  results.include?( {:name => "tucuman", :count => 2 } ).should be_true
86
-
104
+
87
105
  results = User.all_tags(organization_id: @organization_2.id)
88
106
  results.empty?.should be_false
89
107
  results.include?( {:name =>"linux", :count => 1 } ).should be_true
@@ -94,16 +112,16 @@ describe "A Taggable model with scope" do
94
112
 
95
113
  it "should return scoped tags when passing more than one option" do
96
114
  results = User.all_tags(organization_id: @organization_1.id, name: @user_1.name)
97
-
115
+
98
116
  results.empty?.should be_false
99
117
  results.include?( {:name => "linux", :count => 1 } ).should be_true
100
118
  results.include?( {:name => "ubuntu", :count => 1 } ).should be_true
101
119
  results.include?( {:name => "tucuman", :count => 1 } ).should be_true
102
120
  end
103
121
 
104
- it "should return scoped tags when calling deprecated scoped_tags method" do
122
+ it "should return scoped tags when calling deprecated scoped_tags method" do
105
123
  results = User.all_tags(organization_id: @organization_1.id)
106
-
124
+
107
125
  results.empty?.should be_false
108
126
  results.include?( {:name => "linux", :count => 2 } ).should be_true
109
127
  results.include?( {:name => "ubuntu", :count => 2 } ).should be_true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-simple-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec