mongo_mapper 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -3,6 +3,7 @@ module MongoMapper
3
3
  DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was']
4
4
 
5
5
  def self.included(base)
6
+ base.alias_method_chain :initialize, :dirty
6
7
  base.alias_method_chain :write_attribute, :dirty
7
8
  base.alias_method_chain :save, :dirty
8
9
  base.alias_method_chain :save!, :dirty
@@ -52,6 +53,11 @@ module MongoMapper
52
53
  changed.inject({}) { |h, attribute| h[attribute] = key_change(attribute); h }
53
54
  end
54
55
 
56
+ def initialize_with_dirty(attrs={})
57
+ initialize_without_dirty(attrs)
58
+ changed_keys.clear unless new?
59
+ end
60
+
55
61
  # Attempts to +save+ the record and clears changed keys if successful.
56
62
  def save_with_dirty(*args) #:nodoc:
57
63
  if status = save_without_dirty(*args)
data/mongo_mapper.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_mapper}
8
- s.version = "0.5.3"
8
+ s.version = "0.5.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
@@ -29,6 +29,11 @@ class DirtyTest < Test::Unit::TestCase
29
29
  doc.phrase_change.should == [nil, 'Golly Gee Willikers Batman']
30
30
  end
31
31
 
32
+ should "happen when initializing" do
33
+ doc = @document.new(:phrase => 'Foo')
34
+ doc.changed?.should be_true
35
+ end
36
+
32
37
  should "clear changes on save" do
33
38
  doc = @document.new
34
39
  doc.phrase = 'Golly Gee Willikers Batman'
@@ -46,6 +51,22 @@ class DirtyTest < Test::Unit::TestCase
46
51
  doc.phrase_changed?.should_not be_true
47
52
  doc.phrase_change.should be_nil
48
53
  end
54
+
55
+ should "not happen when loading from database" do
56
+ doc = @document.create(:phrase => 'Foo')
57
+
58
+ from_db = @document.find(doc.id)
59
+ from_db.changed?.should be_false
60
+ end
61
+
62
+ should "happen if changed after loading from database" do
63
+ doc = @document.create(:phrase => 'Foo')
64
+
65
+ from_db = @document.find(doc.id)
66
+ from_db.changed?.should be_false
67
+ from_db.phrase = 'Bar'
68
+ from_db.changed?.should be_true
69
+ end
49
70
  end
50
71
 
51
72
  context "blank new value and type integer" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker