mongoid_taggable_with_context 1.1.2 → 1.1.3
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186f1d14401b1a4813ba9f0a59bf5ecc6747379d
|
4
|
+
data.tar.gz: 42ea2145a014a4cc59c4bfb3b18b353dadc4fdfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e06dede604cb1fdf85110065a3c537411e937fa29eaf41ae55afb73052cfea5e0857930d24460f1098eb4a93ea9267f22e5f1ffc03b086bb51932bb3215f276
|
7
|
+
data.tar.gz: 42bdc3e64da2950a37ad4e8947aff8a1804bc075ac791653b833916d9759c8b0720b5ba242cc12882ce615c4cef2e0fa4726476226c5ecd6669a0965724836d1
|
@@ -13,7 +13,11 @@ module Mongoid::TaggableWithContext
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def tag_string_for(context)
|
16
|
-
self.read_attribute(context).join(self.class.get_tag_separator_for(context))
|
16
|
+
self.read_attribute(context).join(self.class.get_tag_separator_for(context)) rescue ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_tag_string_for(context, value)
|
20
|
+
self.write_attribute(context, self.class.format_tags_for(context, value))
|
17
21
|
end
|
18
22
|
|
19
23
|
module ClassMethods
|
@@ -100,6 +104,7 @@ module Mongoid::TaggableWithContext
|
|
100
104
|
# Helper method to convert a a tag input value of unknown type
|
101
105
|
# to a formatted array.
|
102
106
|
def format_tags_for(context, value)
|
107
|
+
return nil if value.nil?
|
103
108
|
# 0) Tags must be an array or a string
|
104
109
|
raise InvalidTagsFormat unless value.is_a?(Array) || value.is_a?(String)
|
105
110
|
# 1) convert String to Array
|
@@ -305,6 +310,10 @@ module Mongoid::TaggableWithContext
|
|
305
310
|
re_define_method("#{context}_string") do
|
306
311
|
tag_string_for(context)
|
307
312
|
end
|
313
|
+
|
314
|
+
re_define_method("#{context}_string=") do |value|
|
315
|
+
set_tag_string_for(context, value)
|
316
|
+
end
|
308
317
|
end
|
309
318
|
end
|
310
319
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mongoid_taggable_with_context"
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Qian", "Luca G. Soave", "John Shields", "Wilker Lucio", "Ches Martin"]
|
@@ -72,6 +72,12 @@ describe Mongoid::TaggableWithContext do
|
|
72
72
|
@m.tags = %w[some new tags]
|
73
73
|
@m.tags_string.should == "some new tags"
|
74
74
|
end
|
75
|
+
|
76
|
+
it "should set tags from tags string" do
|
77
|
+
tags = "some cool tags"
|
78
|
+
@m.albums_string = tags
|
79
|
+
@m.albums.should == tags.split(' ')
|
80
|
+
end
|
75
81
|
|
76
82
|
it "should retrieve artists string" do
|
77
83
|
@m.artists = %w[some new tags]
|
@@ -97,6 +103,11 @@ describe Mongoid::TaggableWithContext do
|
|
97
103
|
@m.tags = ["some", nil, "new", nil, "tags"]
|
98
104
|
@m.tags.should == %w[some new tags]
|
99
105
|
end
|
106
|
+
|
107
|
+
it "should allow tags to be set to nil" do
|
108
|
+
@m.tags = nil
|
109
|
+
@m.tags.should == nil
|
110
|
+
end
|
100
111
|
end
|
101
112
|
|
102
113
|
context "saving tags from array" do
|