mongoid-tags-arent-hard 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,9 @@ module Mongoid
21
21
  self.tag_list << self.normalize(*tag_list)
22
22
  self.tag_list.flatten!
23
23
  self.tag_list.uniq!
24
+ if self.options[:owner]
25
+ self.options[:owner].send("#{self.options[:_name]}_will_change!")
26
+ end
24
27
  return self
25
28
  end
26
29
 
@@ -8,12 +8,13 @@ module Mongoid
8
8
  module ClassMethods
9
9
 
10
10
  def taggable_with(name, options = {})
11
- options = {separator: Mongoid::TagsArentHard.config.separator}.merge(options)
11
+ options = {separator: Mongoid::TagsArentHard.config.separator, _name: name}.merge(options)
12
12
  self.field(name, type: Array, default: [])
13
13
  self.class_eval do
14
14
  define_method(name) do
15
15
  val = super()
16
16
  unless val.is_a?(Mongoid::TagsArentHard::Tags)
17
+ options.merge!(owner: self)
17
18
  val = Mongoid::TagsArentHard::Tags.new(val, options)
18
19
  self.send("#{name}=", val)
19
20
  end
@@ -21,6 +22,7 @@ module Mongoid
21
22
  end
22
23
  define_method("#{name}=") do |val|
23
24
  unless val.is_a?(Mongoid::TagsArentHard::Tags)
25
+ options.merge!(owner: self)
24
26
  val = Mongoid::TagsArentHard::Tags.new(val, options)
25
27
  end
26
28
  super(val)
@@ -2,7 +2,7 @@ module Mongoid
2
2
  module Tags
3
3
  module Arent
4
4
  module Hard
5
- VERSION = "1.0.5"
5
+ VERSION = "1.0.6"
6
6
  end
7
7
  end
8
8
  end
@@ -78,6 +78,19 @@ describe Mongoid::TagsArentHard do
78
78
 
79
79
  end
80
80
 
81
+ describe 'changes' do
82
+
83
+ it "tracks changes correctly" do
84
+ foo.save!
85
+ foo.reload
86
+ foo.send("#{_name}=", [])
87
+ foo.send(_name) << ["foo", "bar"]
88
+ changes = foo.changes
89
+ changes[_name.to_s].should eql([[], ["foo", "bar"]])
90
+ end
91
+
92
+ end
93
+
81
94
  context 'class scopes' do
82
95
 
83
96
  before(:each) 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.5
4
+ version: 1.0.6
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-24 00:00:00.000000000 Z
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid