mongomodel 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +23 -11
- data/gemfiles/rails-3.2.gemfile +2 -2
- data/gemfiles/rails-4-observers.gemfile +1 -1
- data/gemfiles/rails-4.1.gemfile +2 -2
- data/gemfiles/{mongoid.gemfile → rails-4.2.gemfile} +2 -3
- data/gemfiles/{mongo_mapper.gemfile → rails-5.0.gemfile} +2 -3
- data/gemfiles/rails-5.1.gemfile +10 -0
- data/gemfiles/rails-5.2.gemfile +10 -0
- data/lib/mongomodel.rb +15 -15
- data/lib/mongomodel/attributes/mongo.rb +7 -7
- data/lib/mongomodel/attributes/store.rb +4 -4
- data/lib/mongomodel/attributes/typecasting.rb +7 -7
- data/lib/mongomodel/compatibility/mongo_mapper.rb +3 -3
- data/lib/mongomodel/compatibility/mongoid.rb +3 -3
- data/lib/mongomodel/concerns/abstract_class.rb +3 -3
- data/lib/mongomodel/concerns/activemodel.rb +4 -4
- data/lib/mongomodel/concerns/associations.rb +8 -8
- data/lib/mongomodel/concerns/associations/base/association.rb +5 -5
- data/lib/mongomodel/concerns/associations/base/definition.rb +4 -4
- data/lib/mongomodel/concerns/associations/base/proxy.rb +1 -1
- data/lib/mongomodel/concerns/associations/belongs_to.rb +19 -19
- data/lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb +36 -36
- data/lib/mongomodel/concerns/associations/has_many_by_ids.rb +34 -34
- data/lib/mongomodel/concerns/attribute_methods.rb +10 -10
- data/lib/mongomodel/concerns/attribute_methods/before_type_cast.rb +4 -4
- data/lib/mongomodel/concerns/attribute_methods/dirty.rb +95 -13
- data/lib/mongomodel/concerns/attribute_methods/forbidden.rb +1 -1
- data/lib/mongomodel/concerns/attribute_methods/multi_parameter_assignment.rb +6 -6
- data/lib/mongomodel/concerns/attribute_methods/nested.rb +18 -18
- data/lib/mongomodel/concerns/attribute_methods/protected.rb +3 -3
- data/lib/mongomodel/concerns/attribute_methods/query.rb +3 -3
- data/lib/mongomodel/concerns/attribute_methods/read.rb +4 -4
- data/lib/mongomodel/concerns/attribute_methods/write.rb +4 -4
- data/lib/mongomodel/concerns/attributes.rb +18 -18
- data/lib/mongomodel/concerns/callbacks.rb +7 -7
- data/lib/mongomodel/concerns/document_parent.rb +2 -2
- data/lib/mongomodel/concerns/logging.rb +2 -2
- data/lib/mongomodel/concerns/map_reduce.rb +11 -11
- data/lib/mongomodel/concerns/pretty_inspect.rb +3 -3
- data/lib/mongomodel/concerns/properties.rb +18 -18
- data/lib/mongomodel/concerns/record_status.rb +9 -13
- data/lib/mongomodel/concerns/serialization.rb +4 -4
- data/lib/mongomodel/concerns/timestamps.rb +4 -4
- data/lib/mongomodel/concerns/translation.rb +2 -2
- data/lib/mongomodel/concerns/validations.rb +5 -5
- data/lib/mongomodel/concerns/validations/associated.rb +1 -1
- data/lib/mongomodel/document.rb +6 -6
- data/lib/mongomodel/document/callbacks.rb +15 -21
- data/lib/mongomodel/document/collection_modifiers.rb +5 -5
- data/lib/mongomodel/document/dynamic_finders.rb +1 -1
- data/lib/mongomodel/document/indexes.rb +19 -19
- data/lib/mongomodel/document/optimistic_locking.rb +7 -7
- data/lib/mongomodel/document/persistence.rb +23 -23
- data/lib/mongomodel/document/scopes.rb +20 -20
- data/lib/mongomodel/document/validations.rb +6 -6
- data/lib/mongomodel/document/validations/uniqueness.rb +11 -11
- data/lib/mongomodel/embedded_document.rb +11 -11
- data/lib/mongomodel/locale/en.yml +0 -1
- data/lib/mongomodel/log_subscriber.rb +5 -5
- data/lib/mongomodel/railtie.rb +13 -13
- data/lib/mongomodel/support/collection.rb +31 -31
- data/lib/mongomodel/support/configuration.rb +11 -11
- data/lib/mongomodel/support/core_extensions.rb +1 -1
- data/lib/mongomodel/support/dynamic_finder.rb +12 -12
- data/lib/mongomodel/support/exceptions.rb +6 -6
- data/lib/mongomodel/support/instrumented_collection.rb +20 -20
- data/lib/mongomodel/support/map.rb +33 -33
- data/lib/mongomodel/support/mongo_operator.rb +6 -6
- data/lib/mongomodel/support/mongo_options.rb +18 -18
- data/lib/mongomodel/support/mongo_order.rb +16 -16
- data/lib/mongomodel/support/paginator.rb +8 -8
- data/lib/mongomodel/support/reference.rb +10 -10
- data/lib/mongomodel/support/scope.rb +37 -37
- data/lib/mongomodel/support/scope/array_methods.rb +1 -1
- data/lib/mongomodel/support/scope/batches.rb +1 -1
- data/lib/mongomodel/support/scope/dynamic_finders.rb +1 -1
- data/lib/mongomodel/support/scope/finder_methods.rb +7 -7
- data/lib/mongomodel/support/scope/load_methods.rb +1 -1
- data/lib/mongomodel/support/scope/pagination.rb +1 -1
- data/lib/mongomodel/support/scope/query_methods.rb +6 -6
- data/lib/mongomodel/support/scope/spawn_methods.rb +8 -8
- data/lib/mongomodel/support/types.rb +2 -2
- data/lib/mongomodel/support/types/array.rb +1 -1
- data/lib/mongomodel/support/types/boolean.rb +3 -3
- data/lib/mongomodel/support/types/custom.rb +3 -3
- data/lib/mongomodel/support/types/date.rb +2 -2
- data/lib/mongomodel/support/types/date_time.rb +6 -16
- data/lib/mongomodel/support/types/float.rb +1 -1
- data/lib/mongomodel/support/types/hash.rb +1 -1
- data/lib/mongomodel/support/types/integer.rb +13 -10
- data/lib/mongomodel/support/types/object.rb +5 -5
- data/lib/mongomodel/support/types/rational.rb +3 -3
- data/lib/mongomodel/support/types/time.rb +2 -2
- data/lib/mongomodel/version.rb +1 -1
- data/lib/rails/generators/mongo_model/config/templates/mongomodel.yml +3 -4
- data/lib/rails/generators/mongo_model/model/model_generator.rb +3 -3
- data/mongomodel.gemspec +5 -4
- data/spec/mongomodel/attributes/store_spec.rb +21 -21
- data/spec/mongomodel/concerns/activemodel_spec.rb +4 -4
- data/spec/mongomodel/concerns/associations/base/association_spec.rb +12 -12
- data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +34 -21
- data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +53 -53
- data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +30 -30
- data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +7 -7
- data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +45 -41
- data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +7 -7
- data/spec/mongomodel/concerns/attribute_methods/nested_spec.rb +31 -31
- data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +15 -15
- data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +19 -19
- data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +9 -9
- data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +6 -6
- data/spec/mongomodel/concerns/attribute_methods_spec.rb +13 -13
- data/spec/mongomodel/concerns/attributes_spec.rb +34 -34
- data/spec/mongomodel/concerns/callbacks_spec.rb +25 -21
- data/spec/mongomodel/concerns/logging_spec.rb +5 -3
- data/spec/mongomodel/concerns/map_reduce_spec.rb +19 -19
- data/spec/mongomodel/concerns/observing_spec.rb +3 -3
- data/spec/mongomodel/concerns/pretty_inspect_spec.rb +10 -10
- data/spec/mongomodel/concerns/properties_spec.rb +11 -11
- data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +13 -13
- data/spec/mongomodel/concerns/timestamps_spec.rb +39 -39
- data/spec/mongomodel/concerns/validations_spec.rb +41 -38
- data/spec/mongomodel/document/callbacks_spec.rb +20 -16
- data/spec/mongomodel/document/collection_modifiers_spec.rb +16 -16
- data/spec/mongomodel/document/dynamic_finders_spec.rb +46 -46
- data/spec/mongomodel/document/finders_spec.rb +15 -15
- data/spec/mongomodel/document/indexes_spec.rb +29 -29
- data/spec/mongomodel/document/optimistic_locking_spec.rb +16 -16
- data/spec/mongomodel/document/persistence_spec.rb +39 -39
- data/spec/mongomodel/document/scopes_spec.rb +17 -17
- data/spec/mongomodel/document/validations/uniqueness_spec.rb +46 -46
- data/spec/mongomodel/document/validations_spec.rb +35 -35
- data/spec/mongomodel/document_spec.rb +19 -19
- data/spec/mongomodel/embedded_document_spec.rb +19 -19
- data/spec/mongomodel/mongomodel_spec.rb +7 -6
- data/spec/mongomodel/support/collection_spec.rb +54 -54
- data/spec/mongomodel/support/configuration_spec.rb +1 -1
- data/spec/mongomodel/support/map_spec.rb +66 -66
- data/spec/mongomodel/support/mongo_operator_spec.rb +5 -5
- data/spec/mongomodel/support/mongo_options_spec.rb +42 -42
- data/spec/mongomodel/support/mongo_order_spec.rb +24 -24
- data/spec/mongomodel/support/paginator_spec.rb +15 -15
- data/spec/mongomodel/support/property_spec.rb +29 -23
- data/spec/mongomodel/support/scope_spec.rb +205 -204
- data/spec/spec_helper.rb +13 -2
- data/spec/support/callbacks.rb +3 -8
- data/spec/support/helpers/define_class.rb +7 -7
- data/spec/support/helpers/document_finder_stubs.rb +6 -6
- data/spec/support/helpers/specs_for.rb +1 -1
- data/spec/support/helpers/validations.rb +1 -1
- data/spec/support/matchers/find_with.rb +8 -8
- data/spec/support/matchers/respond_to_boolean.rb +3 -3
- data/spec/support/matchers/run_callbacks.rb +6 -9
- data/spec/support/models.rb +5 -5
- metadata +23 -7
@@ -6,13 +6,13 @@ module MongoModel
|
|
6
6
|
define_class(:Book, EmbeddedDocument) do
|
7
7
|
has_many :chapters
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "defaults to :by => :ids" do
|
11
11
|
Book.associations[:chapters].should be_a(Associations::HasManyByIds)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
specs_for(Document, EmbeddedDocument) do
|
17
17
|
shared_examples_for "accessing and manipulating a has_many :by => :ids association" do
|
18
18
|
it "accesses chapters" do
|
@@ -136,7 +136,7 @@ module MongoModel
|
|
136
136
|
should_raise("addding chapters with unshift") { subject.chapters.unshift(nonchapter) }
|
137
137
|
end
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
describe "has_many :by => :ids association" do
|
141
141
|
define_class(:Chapter, Document)
|
142
142
|
define_class(:IllustratedChapter, :Chapter)
|
@@ -144,34 +144,34 @@ module MongoModel
|
|
144
144
|
has_many :chapters, :by => :ids
|
145
145
|
end
|
146
146
|
define_class(:NonChapter, Document)
|
147
|
-
|
147
|
+
|
148
148
|
let(:chapter1) { Chapter.create!(:id => '1') }
|
149
149
|
let(:chapter2) { IllustratedChapter.create!(:id => '2') }
|
150
150
|
let(:chapter3) { Chapter.create!(:id => '3') }
|
151
151
|
let(:nonchapter) { NonChapter.create! }
|
152
|
-
|
152
|
+
|
153
153
|
context "when uninitialized" do
|
154
154
|
subject { Book.new }
|
155
|
-
|
155
|
+
|
156
156
|
it "is empty" do
|
157
157
|
subject.chapters.should be_empty
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it "has an empty ids array" do
|
161
161
|
subject.chapter_ids.should be_empty
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
context "with chapters set" do
|
166
166
|
subject { Book.new(:chapters => [chapter1, chapter2]) }
|
167
167
|
it_should_behave_like "accessing and manipulating a has_many :by => :ids association"
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
context "with chapter ids set" do
|
171
171
|
subject { Book.new(:chapter_ids => [chapter1.id, chapter2.id]) }
|
172
172
|
it_should_behave_like "accessing and manipulating a has_many :by => :ids association"
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
context "when loaded from database" do
|
176
176
|
if specing?(Document)
|
177
177
|
let(:book) { Book.create!(:chapter_ids => [chapter1.id, chapter2.id]) }
|
@@ -184,9 +184,9 @@ module MongoModel
|
|
184
184
|
let(:shelf) { Bookshelf.create!(:book => book) }
|
185
185
|
subject { Bookshelf.find(shelf.id).book }
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it_should_behave_like "accessing and manipulating a has_many :by => :ids association"
|
189
|
-
|
189
|
+
|
190
190
|
context "when child objects are destroyed" do
|
191
191
|
it "does not load the deleted child objects" do
|
192
192
|
chapter1.destroy
|
@@ -194,12 +194,12 @@ module MongoModel
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
describe "with :dependent => :destroy option" do
|
199
199
|
define_class(:Book, described_class) do
|
200
200
|
has_many :chapters, :by => :ids, :dependent => :destroy
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
if specing?(Document)
|
204
204
|
subject { Book.create!(:chapters => [chapter1, chapter2, chapter3]) }
|
205
205
|
else
|
@@ -209,31 +209,31 @@ module MongoModel
|
|
209
209
|
let(:book) { Book.new(:chapters => [chapter1, chapter2, chapter3]) }
|
210
210
|
subject { Bookshelf.create!(:book => book) }
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
context "when the parent object is destroyed" do
|
214
214
|
it "calls destroy on the child objects" do
|
215
215
|
chapter1.should_receive(:destroy)
|
216
216
|
chapter2.should_receive(:destroy)
|
217
217
|
chapter3.should_receive(:destroy)
|
218
|
-
|
218
|
+
|
219
219
|
subject.destroy
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
it "removes the child objects from their collection" do
|
223
223
|
subject.destroy
|
224
|
-
|
225
|
-
Chapter.exists?(chapter1.id).should
|
226
|
-
Chapter.exists?(chapter2.id).should
|
227
|
-
Chapter.exists?(chapter3.id).should
|
224
|
+
|
225
|
+
Chapter.exists?(chapter1.id).should be false
|
226
|
+
Chapter.exists?(chapter2.id).should be false
|
227
|
+
Chapter.exists?(chapter3.id).should be false
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
describe "with :dependent => :delete option" do
|
233
233
|
define_class(:Book, described_class) do
|
234
234
|
has_many :chapters, :by => :ids, :dependent => :delete
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
if specing?(Document)
|
238
238
|
subject { Book.create!(:chapters => [chapter1, chapter2, chapter3]) }
|
239
239
|
else
|
@@ -243,22 +243,22 @@ module MongoModel
|
|
243
243
|
let(:book) { Book.new(:chapters => [chapter1, chapter2, chapter3]) }
|
244
244
|
subject { Bookshelf.create!(:book => book) }
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
247
|
context "when the parent object is destroyed" do
|
248
248
|
it "does not call destroy on the child objects" do
|
249
249
|
chapter1.should_not_receive(:destroy)
|
250
250
|
chapter2.should_not_receive(:destroy)
|
251
251
|
chapter3.should_not_receive(:destroy)
|
252
|
-
|
252
|
+
|
253
253
|
subject.destroy
|
254
254
|
end
|
255
|
-
|
255
|
+
|
256
256
|
it "removes the child objects from their collection" do
|
257
257
|
subject.destroy
|
258
|
-
|
259
|
-
Chapter.exists?(chapter1.id).should
|
260
|
-
Chapter.exists?(chapter2.id).should
|
261
|
-
Chapter.exists?(chapter3.id).should
|
258
|
+
|
259
|
+
Chapter.exists?(chapter1.id).should be false
|
260
|
+
Chapter.exists?(chapter2.id).should be false
|
261
|
+
Chapter.exists?(chapter3.id).should be false
|
262
262
|
end
|
263
263
|
end
|
264
264
|
end
|
@@ -5,39 +5,39 @@ module MongoModel
|
|
5
5
|
define_class(:TestDocument, described_class) do
|
6
6
|
property :foo, Date
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
subject { TestDocument.new }
|
10
|
-
|
10
|
+
|
11
11
|
describe "#read_attribute_before_type_cast" do
|
12
12
|
context "with property" do
|
13
13
|
it "returns the attribute before type casting" do
|
14
14
|
subject.attributes[:foo] = 'some date'
|
15
15
|
subject.read_attribute_before_type_cast(:foo).should == 'some date'
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "defines a reader method" do
|
19
19
|
subject.attributes[:foo] = 'some date'
|
20
20
|
subject.foo_before_type_cast.should == 'some date'
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
context "no property" do
|
25
25
|
it "returns the attribute without type casting" do
|
26
26
|
subject.attributes[:bar] = 'set bar'
|
27
27
|
subject.read_attribute_before_type_cast(:bar).should == 'set bar'
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "does not define a reader method" do
|
31
31
|
lambda { subject.bar_before_type_cast }.should raise_error(NoMethodError)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
describe "#attributes_before_type_cast" do
|
37
37
|
it "returns a hash of attributes before type casting" do
|
38
38
|
subject.attributes[:foo] = 'some date'
|
39
39
|
subject.attributes[:bar] = 'set bar'
|
40
|
-
|
40
|
+
|
41
41
|
subject.attributes_before_type_cast[:foo].should == 'some date'
|
42
42
|
subject.attributes_before_type_cast[:bar].should == 'set bar'
|
43
43
|
end
|
@@ -14,132 +14,136 @@ module MongoModel
|
|
14
14
|
property :foo, String
|
15
15
|
property :bar, String
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
define_class(:ParentDocument, Document) do
|
19
19
|
property :child, ChildDocument
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
let(:child) { ChildDocument.new(:foo => 'original foo') }
|
23
23
|
let(:parent) { ParentDocument.create!(:child => child) }
|
24
|
-
|
24
|
+
|
25
25
|
subject { parent.child }
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
def reset_subject!
|
29
|
+
subject.respond_to?(:restore_foo!) ? subject.restore_foo! : subject.reset_foo!
|
30
|
+
end
|
31
|
+
|
28
32
|
describe "#write_attribute" do
|
29
33
|
before(:each) do
|
30
34
|
subject.write_attribute(:foo, 'new foo')
|
31
35
|
end
|
32
|
-
|
36
|
+
|
33
37
|
it "adds the old attribute name to the changed attributes" do
|
34
38
|
subject.changed.should include("foo")
|
35
39
|
end
|
36
|
-
|
40
|
+
|
37
41
|
it "does not add other attributes to the changed attributes" do
|
38
42
|
subject.changed.should_not include("bar")
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
it "adds the changed attribute value to the changes hash" do
|
42
46
|
subject.changes["foo"].should == ['original foo', 'new foo']
|
43
47
|
end
|
44
|
-
|
48
|
+
|
45
49
|
context "when called twice" do
|
46
50
|
before(:each) do
|
47
51
|
subject.write_attribute(:foo, 'new foo #2')
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
it "keeps the original value as the old value in the changes hash" do
|
51
55
|
subject.changes["foo"].should == ['original foo', 'new foo #2']
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
55
|
-
|
59
|
+
|
56
60
|
context "with changed attributes" do
|
57
61
|
context "attribute set to a new value" do
|
58
62
|
before(:each) do
|
59
63
|
subject.foo = 'foo changed'
|
60
64
|
end
|
61
|
-
|
65
|
+
|
62
66
|
it { should be_changed }
|
63
|
-
|
67
|
+
|
64
68
|
it "has a changed attribute" do
|
65
69
|
subject.foo_changed?.should == true
|
66
70
|
end
|
67
|
-
|
71
|
+
|
68
72
|
it "tells what the attribute was" do
|
69
73
|
subject.foo_was.should == "original foo"
|
70
74
|
end
|
71
|
-
|
75
|
+
|
72
76
|
it "has an attribute change" do
|
73
77
|
subject.foo_change.should == ["original foo", "foo changed"]
|
74
78
|
end
|
75
|
-
|
76
|
-
it "is able to reset an attribute" do
|
77
|
-
|
79
|
+
|
80
|
+
it "is able to reset/restore an attribute" do
|
81
|
+
reset_subject!
|
78
82
|
subject.foo.should == "original foo"
|
79
83
|
subject.changed?.should == false
|
80
84
|
end
|
81
85
|
end
|
82
|
-
|
86
|
+
|
83
87
|
context "attribute set to the original value" do
|
84
88
|
before(:each) do
|
85
89
|
subject.foo = 'original foo'
|
86
90
|
end
|
87
|
-
|
91
|
+
|
88
92
|
it { should_not be_changed }
|
89
|
-
|
93
|
+
|
90
94
|
it "does not have a changed attribute" do
|
91
95
|
subject.foo_changed?.should == false
|
92
96
|
end
|
93
|
-
|
97
|
+
|
94
98
|
it "tells what the attribute was" do
|
95
99
|
subject.foo_was.should == "original foo"
|
96
100
|
end
|
97
|
-
|
101
|
+
|
98
102
|
it "does not have an attribute change" do
|
99
103
|
subject.foo_change.should == nil
|
100
104
|
end
|
101
|
-
|
102
|
-
it "is able to reset an attribute" do
|
103
|
-
|
105
|
+
|
106
|
+
it "is able to reset/restore an attribute" do
|
107
|
+
reset_subject!
|
104
108
|
subject.foo.should == "original foo"
|
105
109
|
subject.changed?.should == false
|
106
110
|
end
|
107
111
|
end
|
108
112
|
end
|
109
|
-
|
113
|
+
|
110
114
|
context "without changed attributes" do
|
111
115
|
it { should_not be_changed }
|
112
|
-
|
116
|
+
|
113
117
|
it "does not have a changed attribute" do
|
114
118
|
subject.foo_changed?.should == false
|
115
119
|
end
|
116
|
-
|
120
|
+
|
117
121
|
it "tells what the attribute was" do
|
118
122
|
subject.foo_was.should == "original foo"
|
119
123
|
end
|
120
|
-
|
124
|
+
|
121
125
|
it "does not have an attribute change" do
|
122
126
|
subject.foo_change.should == nil
|
123
127
|
end
|
124
|
-
|
125
|
-
it "is able to reset an attribute" do
|
126
|
-
|
128
|
+
|
129
|
+
it "is able to reset/restore an attribute" do
|
130
|
+
reset_subject!
|
127
131
|
subject.foo.should == "original foo"
|
128
132
|
subject.changed?.should == false
|
129
133
|
end
|
130
134
|
end
|
131
|
-
|
135
|
+
|
132
136
|
context "#original_attributes" do
|
133
137
|
context "with changes" do
|
134
138
|
before(:each) do
|
135
139
|
subject.foo = 'changed foo'
|
136
140
|
end
|
137
|
-
|
141
|
+
|
138
142
|
it "returns the attributes before changes" do
|
139
143
|
subject.original_attributes['foo'].should == 'original foo'
|
140
144
|
end
|
141
145
|
end
|
142
|
-
|
146
|
+
|
143
147
|
context "without changes" do
|
144
148
|
it "returns the attributes hash" do
|
145
149
|
subject.original_attributes.symbolize_keys.should == subject.attributes
|
@@ -147,26 +151,26 @@ module MongoModel
|
|
147
151
|
end
|
148
152
|
end
|
149
153
|
end
|
150
|
-
|
154
|
+
|
151
155
|
specs_for(Document) do
|
152
156
|
define_class(:TestDocument, Document) do
|
153
157
|
property :foo, String
|
154
158
|
end
|
155
|
-
|
159
|
+
|
156
160
|
subject { TestDocument.create!(:foo => 'original foo') }
|
157
|
-
|
161
|
+
|
158
162
|
context "when saved" do
|
159
163
|
before(:each) do
|
160
164
|
subject.foo = 'changed foo'
|
161
165
|
end
|
162
|
-
|
166
|
+
|
163
167
|
context "with save" do
|
164
168
|
it "resets the changed attributes" do
|
165
169
|
subject.save
|
166
170
|
subject.should_not be_changed
|
167
171
|
end
|
168
172
|
end
|
169
|
-
|
173
|
+
|
170
174
|
context "with save!" do
|
171
175
|
it "resets the changed attributes" do
|
172
176
|
subject.save!
|
@@ -174,7 +178,7 @@ module MongoModel
|
|
174
178
|
end
|
175
179
|
end
|
176
180
|
end
|
177
|
-
|
181
|
+
|
178
182
|
context "when instantiated from database" do
|
179
183
|
it "is not changed" do
|
180
184
|
instance = TestDocument.find(subject.id)
|
@@ -7,9 +7,9 @@ module MongoModel
|
|
7
7
|
property :datestamp, Date
|
8
8
|
property :datetime, DateTime
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
subject { TestDocument.new }
|
12
|
-
|
12
|
+
|
13
13
|
describe "multiparameter assignment from select" do
|
14
14
|
context "setting a Time" do
|
15
15
|
it "combines and assign parameters as Time" do
|
@@ -20,11 +20,11 @@ module MongoModel
|
|
20
20
|
"timestamp(4i)" => "14",
|
21
21
|
"timestamp(5i)" => "35"
|
22
22
|
}
|
23
|
-
|
23
|
+
|
24
24
|
subject.timestamp.should == Time.zone.local(2009, 10, 5, 14, 35)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
context "setting a Date" do
|
29
29
|
it "combines and assign parameters as Date" do
|
30
30
|
subject.attributes = {
|
@@ -32,11 +32,11 @@ module MongoModel
|
|
32
32
|
"datestamp(2i)" => "4",
|
33
33
|
"datestamp(3i)" => "9"
|
34
34
|
}
|
35
|
-
|
35
|
+
|
36
36
|
subject.datestamp.should == Date.new(2008, 4, 9)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
context "setting a DateTime" do
|
41
41
|
it "combines and assign parameters as DateTime" do
|
42
42
|
subject.attributes = {
|
@@ -46,7 +46,7 @@ module MongoModel
|
|
46
46
|
"datetime(4i)" => "14",
|
47
47
|
"datetime(5i)" => "35"
|
48
48
|
}
|
49
|
-
|
49
|
+
|
50
50
|
subject.datetime.should == DateTime.civil(2009, 10, 5, 14, 35)
|
51
51
|
end
|
52
52
|
end
|