mongoid_taggable_with_context 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 330460cba0321c62c198a6ac426fa2f33452e252
4
- data.tar.gz: 260e96cbacc75cdecdbe58553219f3f1b2f720fd
3
+ metadata.gz: 186f1d14401b1a4813ba9f0a59bf5ecc6747379d
4
+ data.tar.gz: 42ea2145a014a4cc59c4bfb3b18b353dadc4fdfd
5
5
  SHA512:
6
- metadata.gz: 2c7476f6fc9dd74b48fce65eeb1878f1765d919845c2a92bead00dda8503f1b0e171746742a61ca698da1b274210367b213bdf006398b2091098b1e411497285
7
- data.tar.gz: 1b9f6d7f64ed234bee25d7b2141ed2a6151ffad9fe3fddb75fb7fe9f667d687eeddf10042f14b713c0a3cefb80f8537551ce5138d535bbb189138d43ce011a22
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
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
3
  module TaggableWithContext
4
- VERSION = '1.1.2'
4
+ VERSION = '1.1.3'
5
5
  end
6
6
  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.2"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_taggable_with_context
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Qian