mongoid-genesis 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid/genesis.rb +6 -2
- data/spec/mongoid/genesis_spec.rb +16 -2
- metadata +22 -6
data/lib/mongoid/genesis.rb
CHANGED
@@ -27,9 +27,13 @@ module Mongoid
|
|
27
27
|
|
28
28
|
def write_and_preserve_attribute(field_name, value)
|
29
29
|
init_genesis if not self.genesis
|
30
|
-
self.genesis.preserve field_name
|
31
30
|
|
32
|
-
self.
|
31
|
+
if value and self.genesis.read_attribute(field_name) == value
|
32
|
+
self.restore_genesis(field_name)
|
33
|
+
else
|
34
|
+
self.genesis.preserve field_name
|
35
|
+
self.write_attribute(field_name, value)
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -24,20 +24,34 @@ describe Mongoid::Genesis do
|
|
24
24
|
its(:title) { should eql 'The Art of Peace' }
|
25
25
|
its('genesis.title') { should eql 'The Art of War' }
|
26
26
|
|
27
|
-
context "
|
27
|
+
context "and changing title to 'The Art of Neutrality'" do
|
28
28
|
before { book.write_and_preserve_attribute :title, 'The Art of Neutrality' }
|
29
29
|
|
30
30
|
its(:title) { should eql 'The Art of Neutrality' }
|
31
31
|
its('genesis.title') { should eql 'The Art of War' }
|
32
|
+
|
33
|
+
context "and rechanging it to 'The Art of War'" do
|
34
|
+
before { book.write_and_preserve_attribute :title, 'The Art of War' }
|
35
|
+
|
36
|
+
its(:title) { should eql 'The Art of War' }
|
37
|
+
its('genesis.title') { should be_nil }
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
41
|
+
|
42
|
+
context "when changing title to nil" do
|
43
|
+
before { book.write_and_preserve_attribute :title, nil }
|
44
|
+
|
45
|
+
its(:title) { should be_nil }
|
46
|
+
its('genesis.title') { should eql 'The Art of War' }
|
47
|
+
end
|
34
48
|
end
|
35
49
|
|
36
50
|
describe "#restore_genesis" do
|
37
51
|
context "when changing title to 'The Art of Peace'" do
|
38
52
|
before { book.write_and_preserve_attribute :title, 'The Art of Peace' }
|
39
53
|
|
40
|
-
context "
|
54
|
+
context "and restoring genesis for title" do
|
41
55
|
before { book.restore_genesis(:title) }
|
42
56
|
|
43
57
|
its(:title) { should eql 'The Art of War' }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-genesis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sebastien Rosa
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: mongoid
|
@@ -79,9 +79,25 @@ dependencies:
|
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id004
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: rspec-compact-doc-formatter
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 25
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
- 0
|
93
|
+
- 3
|
94
|
+
version: 0.0.3
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: metrical
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
101
|
none: false
|
86
102
|
requirements:
|
87
103
|
- - ">="
|
@@ -93,7 +109,7 @@ dependencies:
|
|
93
109
|
- 0
|
94
110
|
version: 0.1.0
|
95
111
|
type: :development
|
96
|
-
version_requirements: *
|
112
|
+
version_requirements: *id006
|
97
113
|
description: Mongoid Genesis will give you the ability to override attribute values without losing the original one.
|
98
114
|
email:
|
99
115
|
- sebastien@demarque.com
|