mongoid-tags-arent-hard 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,14 +13,19 @@ module Mongoid
13
13
  end
14
14
 
15
15
  def normalize(*tag_list)
16
- tag_list.flatten.map {|s| s.split(self.options[:separator]).map {|x| x.strip}}.flatten
16
+ x = tag_list.flatten.map {|s| s.split(self.options[:separator]).map {|x| x.strip}}.flatten
17
+ return x
17
18
  end
18
19
 
19
20
  def <<(*tag_list)
20
21
  self.tag_list << self.normalize(*tag_list)
21
22
  self.tag_list.flatten!
22
23
  self.tag_list.uniq!
23
- return self.tag_list
24
+ return self
25
+ end
26
+
27
+ def +(*tag_list)
28
+ self.<<(*tag_list)
24
29
  end
25
30
 
26
31
  def to_s
@@ -2,7 +2,7 @@ module Mongoid
2
2
  module Tags
3
3
  module Arent
4
4
  module Hard
5
- VERSION = "1.0.3"
5
+ VERSION = "1.0.5"
6
6
  end
7
7
  end
8
8
  end
@@ -44,6 +44,40 @@ describe Mongoid::TagsArentHard do
44
44
 
45
45
  end
46
46
 
47
+ describe '+=' do
48
+
49
+ it "adds and replaces using a string" do
50
+ foo.send("#{_name}=", ["foo", "bar"])
51
+ foo.send(_name).should eql(["foo","bar"])
52
+
53
+ fooa = foo.send(_name)
54
+ fooa += "a#{_separator}b"
55
+
56
+ fooa.should eql(["foo","bar", "a", "b"])
57
+ end
58
+
59
+ it "adds and replaces using an array" do
60
+ foo.send("#{_name}=", ["foo", "bar"])
61
+ foo.send(_name).should eql(["foo","bar"])
62
+
63
+ fooa = foo.send(_name)
64
+ fooa += ["a", "b"]
65
+
66
+ fooa.should eql(["foo","bar", "a", "b"])
67
+ end
68
+
69
+ it "adds and replaces using a Tags object" do
70
+ foo.send("#{_name}=", ["foo", "bar"])
71
+ foo.send(_name).should eql(["foo","bar"])
72
+
73
+ fooa = foo.send(_name)
74
+ fooa += Mongoid::TagsArentHard::Tags.new(["a", "b"], {})
75
+
76
+ fooa.should eql(["foo","bar", "a", "b"])
77
+ end
78
+
79
+ end
80
+
47
81
  context 'class scopes' do
48
82
 
49
83
  before(:each) do
@@ -54,6 +54,32 @@ describe Mongoid::TagsArentHard::Tags do
54
54
 
55
55
  end
56
56
 
57
+ describe '+' do
58
+
59
+ it "adds the string to the list" do
60
+ tags.should eql(["foo", "bar", "baz"])
61
+ ntags = tags + "a,b"
62
+ ntags.should eql(["foo", "bar", "baz", "a", "b"])
63
+ puts "ntags.class.name: #{ntags.class.name}"
64
+ ntags.should be_kind_of(Mongoid::TagsArentHard::Tags)
65
+ end
66
+
67
+ it "adds the array to the list" do
68
+ tags.should eql(["foo", "bar", "baz"])
69
+ ntags = tags + ["a", "b"]
70
+ ntags.should eql(["foo", "bar", "baz", "a", "b"])
71
+ ntags.should be_kind_of(Mongoid::TagsArentHard::Tags)
72
+ end
73
+
74
+ it "adds another Tag object" do
75
+ tags.should eql(["foo", "bar", "baz"])
76
+ ntags = tags + Mongoid::TagsArentHard::Tags.new(["a", "b"], {})
77
+ ntags.should eql(["foo", "bar", "baz", "a", "b"])
78
+ ntags.should be_kind_of(Mongoid::TagsArentHard::Tags)
79
+ end
80
+
81
+ end
82
+
57
83
  describe 'to_s, to_str' do
58
84
 
59
85
  it "returns a comma separated list of tags" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-tags-arent-hard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
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-09-21 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid