mongomodel 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Appraisals +12 -0
  2. data/bin/console +1 -2
  3. data/gemfiles/mongo_mapper.gemfile +12 -0
  4. data/gemfiles/mongoid.gemfile +12 -0
  5. data/lib/mongomodel.rb +3 -0
  6. data/lib/mongomodel/compatibility/mongo_mapper.rb +23 -0
  7. data/lib/mongomodel/compatibility/mongoid.rb +17 -0
  8. data/lib/mongomodel/concerns/properties.rb +5 -0
  9. data/lib/mongomodel/concerns/validations.rb +5 -3
  10. data/lib/mongomodel/support/core_extensions.rb +4 -4
  11. data/lib/mongomodel/support/mongo_options.rb +4 -2
  12. data/lib/mongomodel/support/mongo_order.rb +4 -0
  13. data/lib/mongomodel/support/scope.rb +1 -1
  14. data/lib/mongomodel/version.rb +1 -1
  15. data/spec/mongomodel/attributes/store_spec.rb +12 -12
  16. data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +13 -13
  17. data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +25 -25
  18. data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +25 -25
  19. data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +5 -5
  20. data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +21 -21
  21. data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +3 -3
  22. data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +10 -10
  23. data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +6 -6
  24. data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +6 -6
  25. data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +5 -5
  26. data/spec/mongomodel/concerns/attribute_methods_spec.rb +5 -5
  27. data/spec/mongomodel/concerns/attributes_spec.rb +13 -13
  28. data/spec/mongomodel/concerns/callbacks_spec.rb +11 -11
  29. data/spec/mongomodel/concerns/logging_spec.rb +2 -2
  30. data/spec/mongomodel/concerns/observing_spec.rb +3 -3
  31. data/spec/mongomodel/concerns/pretty_inspect_spec.rb +5 -5
  32. data/spec/mongomodel/concerns/properties_spec.rb +6 -6
  33. data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +6 -6
  34. data/spec/mongomodel/concerns/timestamps_spec.rb +10 -10
  35. data/spec/mongomodel/concerns/translation_spec.rb +1 -1
  36. data/spec/mongomodel/concerns/validations_spec.rb +12 -4
  37. data/spec/mongomodel/document/callbacks_spec.rb +10 -10
  38. data/spec/mongomodel/document/collection_modifiers_spec.rb +1 -1
  39. data/spec/mongomodel/document/dynamic_finders_spec.rb +5 -5
  40. data/spec/mongomodel/document/finders_spec.rb +9 -9
  41. data/spec/mongomodel/document/indexes_spec.rb +19 -19
  42. data/spec/mongomodel/document/optimistic_locking_spec.rb +8 -8
  43. data/spec/mongomodel/document/persistence_spec.rb +38 -38
  44. data/spec/mongomodel/document/scopes_spec.rb +8 -8
  45. data/spec/mongomodel/document/validations/uniqueness_spec.rb +9 -9
  46. data/spec/mongomodel/document/validations_spec.rb +16 -16
  47. data/spec/mongomodel/document_spec.rb +11 -11
  48. data/spec/mongomodel/embedded_document_spec.rb +13 -13
  49. data/spec/mongomodel/mongomodel_spec.rb +4 -4
  50. data/spec/mongomodel/support/collection_spec.rb +40 -40
  51. data/spec/mongomodel/support/map_spec.rb +41 -41
  52. data/spec/mongomodel/support/mongo_operator_spec.rb +11 -9
  53. data/spec/mongomodel/support/mongo_options_spec.rb +17 -17
  54. data/spec/mongomodel/support/mongo_order_spec.rb +22 -22
  55. data/spec/mongomodel/support/property_spec.rb +21 -12
  56. data/spec/mongomodel/support/scope_spec.rb +134 -134
  57. data/spec/spec_helper.rb +1 -0
  58. data/spec/specdoc.opts +0 -3
  59. metadata +7 -5
@@ -7,92 +7,92 @@ module MongoModel
7
7
  has_many :chapters
8
8
  end
9
9
 
10
- it "should default to :by => :ids" do
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
  shared_examples_for "accessing and manipulating a has_many :by => :ids association" do
17
- it "should access chapters" do
17
+ it "accesses chapters" do
18
18
  subject.chapters.should == [chapter1, chapter2]
19
19
  end
20
20
 
21
- it "should access chapter ids through association" do
21
+ it "accesses chapter ids through association" do
22
22
  subject.chapters.ids.should == [chapter1.id, chapter2.id]
23
23
  end
24
24
 
25
- it "should have chapter ids" do
25
+ it "has chapter ids" do
26
26
  subject.chapter_ids.should == [chapter1.id, chapter2.id]
27
27
  end
28
28
 
29
- it "should add chapters with <<" do
29
+ it "adds chapters with <<" do
30
30
  subject.chapters << chapter3
31
31
  subject.chapters.should == [chapter1, chapter2, chapter3]
32
32
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter3.id]
33
33
  end
34
34
 
35
- it "should add/change chapters with []=" do
35
+ it "adds/change chapters with []=" do
36
36
  subject.chapters[2] = chapter3
37
37
  subject.chapters.should == [chapter1, chapter2, chapter3]
38
38
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter3.id]
39
39
  end
40
40
 
41
- it "should add chapters with concat" do
41
+ it "adds chapters with concat" do
42
42
  subject.chapters.concat([chapter3])
43
43
  subject.chapters.should == [chapter1, chapter2, chapter3]
44
44
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter3.id]
45
45
  end
46
46
 
47
- it "should insert chapters" do
47
+ it "inserts chapters" do
48
48
  subject.chapters.insert(1, chapter3)
49
49
  subject.chapters.should == [chapter1, chapter3, chapter2]
50
50
  subject.chapter_ids.should == [chapter1.id, chapter3.id, chapter2.id]
51
51
  end
52
52
 
53
- it "should replace chapters" do
53
+ it "replaces chapters" do
54
54
  subject.chapters.replace([chapter2, chapter3])
55
55
  subject.chapters.should == [chapter2, chapter3]
56
56
  subject.chapter_ids.should == [chapter2.id, chapter3.id]
57
57
  end
58
58
 
59
- it "should add chapters with push" do
59
+ it "adds chapters with push" do
60
60
  subject.chapters.push(chapter3)
61
61
  subject.chapters.should == [chapter1, chapter2, chapter3]
62
62
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter3.id]
63
63
  end
64
64
 
65
- it "should add chapters with unshift" do
65
+ it "adds chapters with unshift" do
66
66
  subject.chapters.unshift(chapter3)
67
67
  subject.chapters.should == [chapter3, chapter1, chapter2]
68
68
  subject.chapter_ids.should == [chapter3.id, chapter1.id, chapter2.id]
69
69
  end
70
70
 
71
- it "should clear chapters" do
71
+ it "clears chapters" do
72
72
  subject.chapters.clear
73
73
  subject.chapters.should be_empty
74
74
  subject.chapter_ids.should be_empty
75
75
  end
76
76
 
77
- it "should remove chapters with delete" do
77
+ it "removes chapters with delete" do
78
78
  subject.chapters.delete(chapter1)
79
79
  subject.chapters.should == [chapter2]
80
80
  subject.chapter_ids.should == [chapter2.id]
81
81
  end
82
82
 
83
- it "should remove chapters with delete_at" do
83
+ it "removes chapters with delete_at" do
84
84
  subject.chapters.delete_at(0)
85
85
  subject.chapters.should == [chapter2]
86
86
  subject.chapter_ids.should == [chapter2.id]
87
87
  end
88
88
 
89
- it "should remove chapters with delete_if" do
89
+ it "removes chapters with delete_if" do
90
90
  subject.chapters.delete_if { |c| c.id == chapter1.id }
91
91
  subject.chapters.should == [chapter2]
92
92
  subject.chapter_ids.should == [chapter2.id]
93
93
  end
94
94
 
95
- it "should build a chapter" do
95
+ it "builds a chapter" do
96
96
  chapter4 = subject.chapters.build(:id => '4')
97
97
  subject.chapters.should == [chapter1, chapter2, chapter4]
98
98
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter4.id]
@@ -101,7 +101,7 @@ module MongoModel
101
101
  chapter4.id.should == '4'
102
102
  end
103
103
 
104
- it "should create a chapter" do
104
+ it "creates a chapter" do
105
105
  chapter4 = subject.chapters.create(:id => '4')
106
106
  subject.chapters.should == [chapter1, chapter2, chapter4]
107
107
  subject.chapter_ids.should == [chapter1.id, chapter2.id, chapter4.id]
@@ -110,7 +110,7 @@ module MongoModel
110
110
  chapter4.id.should == '4'
111
111
  end
112
112
 
113
- it "should find chapters" do
113
+ it "finds chapters" do
114
114
  # Create bogus chapters
115
115
  Chapter.create!(:id => '999')
116
116
  Chapter.create!(:id => '998')
@@ -121,7 +121,7 @@ module MongoModel
121
121
 
122
122
  describe "adding a non-chapter" do
123
123
  def self.should_raise(message, &block)
124
- it "should raise an AsssociationTypeMismatch error when #{message}" do
124
+ it "raises an AsssociationTypeMismatch error when #{message}" do
125
125
  lambda { instance_eval(&block) }.should raise_error(AssociationTypeMismatch, "expected instance of Chapter but got NonChapter")
126
126
  end
127
127
  end
@@ -153,11 +153,11 @@ module MongoModel
153
153
  context "when uninitialized" do
154
154
  subject { Book.new }
155
155
 
156
- it "should be empty" do
156
+ it "is empty" do
157
157
  subject.chapters.should be_empty
158
158
  end
159
159
 
160
- it "should have an empty ids array" do
160
+ it "has an empty ids array" do
161
161
  subject.chapter_ids.should be_empty
162
162
  end
163
163
  end
@@ -204,7 +204,7 @@ module MongoModel
204
204
  end
205
205
 
206
206
  context "when the parent object is destroyed" do
207
- it "should call destroy on the child objects" do
207
+ it "calls destroy on the child objects" do
208
208
  chapter1.should_receive(:destroy)
209
209
  chapter2.should_receive(:destroy)
210
210
  chapter3.should_receive(:destroy)
@@ -212,7 +212,7 @@ module MongoModel
212
212
  subject.destroy
213
213
  end
214
214
 
215
- it "should remove the child objects from their collection" do
215
+ it "removes the child objects from their collection" do
216
216
  subject.destroy
217
217
 
218
218
  Chapter.exists?(chapter1.id).should be_false
@@ -238,7 +238,7 @@ module MongoModel
238
238
  end
239
239
 
240
240
  context "when the parent object is destroyed" do
241
- it "should not call destroy on the child objects" do
241
+ it "does not call destroy on the child objects" do
242
242
  chapter1.should_not_receive(:destroy)
243
243
  chapter2.should_not_receive(:destroy)
244
244
  chapter3.should_not_receive(:destroy)
@@ -246,7 +246,7 @@ module MongoModel
246
246
  subject.destroy
247
247
  end
248
248
 
249
- it "should remove the child objects from their collection" do
249
+ it "removes the child objects from their collection" do
250
250
  subject.destroy
251
251
 
252
252
  Chapter.exists?(chapter1.id).should be_false
@@ -10,31 +10,31 @@ module MongoModel
10
10
 
11
11
  describe "#read_attribute_before_type_cast" do
12
12
  context "with property" do
13
- it "should return the attribute before type casting" do
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
- it "should define a reader method" do
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
- it "should return the attribute without type casting" do
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
- it "should not define a reader method" do
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
- it "should return a hash of attributes before type casting" do
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
 
@@ -30,15 +30,15 @@ module MongoModel
30
30
  subject.write_attribute(:foo, 'new foo')
31
31
  end
32
32
 
33
- it "should add the old attribute name to the changed attributes" do
33
+ it "adds the old attribute name to the changed attributes" do
34
34
  subject.changed.should include("foo")
35
35
  end
36
36
 
37
- it "should not add other attributes to the changed attributes" do
37
+ it "does not add other attributes to the changed attributes" do
38
38
  subject.changed.should_not include("bar")
39
39
  end
40
40
 
41
- it "should add the changed attribute value to the changes hash" do
41
+ it "adds the changed attribute value to the changes hash" do
42
42
  subject.changes["foo"].should == ['original foo', 'new foo']
43
43
  end
44
44
 
@@ -47,7 +47,7 @@ module MongoModel
47
47
  subject.write_attribute(:foo, 'new foo #2')
48
48
  end
49
49
 
50
- it "should keep the original value as the old value in the changes hash" do
50
+ it "keeps the original value as the old value in the changes hash" do
51
51
  subject.changes["foo"].should == ['original foo', 'new foo #2']
52
52
  end
53
53
  end
@@ -61,19 +61,19 @@ module MongoModel
61
61
 
62
62
  it { should be_changed }
63
63
 
64
- it "should have a changed attribute" do
64
+ it "has a changed attribute" do
65
65
  subject.foo_changed?.should == true
66
66
  end
67
67
 
68
- it "should tell what the attribute was" do
68
+ it "tells what the attribute was" do
69
69
  subject.foo_was.should == "original foo"
70
70
  end
71
71
 
72
- it "should have an attribute change" do
72
+ it "has an attribute change" do
73
73
  subject.foo_change.should == ["original foo", "foo changed"]
74
74
  end
75
75
 
76
- it "should be able to reset an attribute" do
76
+ it "is able to reset an attribute" do
77
77
  subject.reset_foo!
78
78
  subject.foo.should == "original foo"
79
79
  subject.changed?.should == false
@@ -87,19 +87,19 @@ module MongoModel
87
87
 
88
88
  it { should_not be_changed }
89
89
 
90
- it "should not have a changed attribute" do
90
+ it "does not have a changed attribute" do
91
91
  subject.foo_changed?.should == false
92
92
  end
93
93
 
94
- it "should tell what the attribute was" do
94
+ it "tells what the attribute was" do
95
95
  subject.foo_was.should == "original foo"
96
96
  end
97
97
 
98
- it "should not have an attribute change" do
98
+ it "does not have an attribute change" do
99
99
  subject.foo_change.should == nil
100
100
  end
101
101
 
102
- it "should be able to reset an attribute" do
102
+ it "is able to reset an attribute" do
103
103
  subject.reset_foo!
104
104
  subject.foo.should == "original foo"
105
105
  subject.changed?.should == false
@@ -110,19 +110,19 @@ module MongoModel
110
110
  context "without changed attributes" do
111
111
  it { should_not be_changed }
112
112
 
113
- it "should not have a changed attribute" do
113
+ it "does not have a changed attribute" do
114
114
  subject.foo_changed?.should == false
115
115
  end
116
116
 
117
- it "should tell what the attribute was" do
117
+ it "tells what the attribute was" do
118
118
  subject.foo_was.should == "original foo"
119
119
  end
120
120
 
121
- it "should not have an attribute change" do
121
+ it "does not have an attribute change" do
122
122
  subject.foo_change.should == nil
123
123
  end
124
124
 
125
- it "should be able to reset an attribute" do
125
+ it "is able to reset an attribute" do
126
126
  subject.reset_foo!
127
127
  subject.foo.should == "original foo"
128
128
  subject.changed?.should == false
@@ -135,13 +135,13 @@ module MongoModel
135
135
  subject.foo = 'changed foo'
136
136
  end
137
137
 
138
- it "should return the attributes before changes" do
138
+ it "returns the attributes before changes" do
139
139
  subject.original_attributes['foo'].should == 'original foo'
140
140
  end
141
141
  end
142
142
 
143
143
  context "without changes" do
144
- it "should return the attributes hash" do
144
+ it "returns the attributes hash" do
145
145
  subject.original_attributes.symbolize_keys.should == subject.attributes
146
146
  end
147
147
  end
@@ -161,14 +161,14 @@ module MongoModel
161
161
  end
162
162
 
163
163
  context "with save" do
164
- it "should reset the changed attributes" do
164
+ it "resets the changed attributes" do
165
165
  subject.save
166
166
  subject.should_not be_changed
167
167
  end
168
168
  end
169
169
 
170
170
  context "with save!" do
171
- it "should reset the changed attributes" do
171
+ it "resets the changed attributes" do
172
172
  subject.save!
173
173
  subject.should_not be_changed
174
174
  end
@@ -176,7 +176,7 @@ module MongoModel
176
176
  end
177
177
 
178
178
  context "when instantiated from database" do
179
- it "should not be changed" do
179
+ it "is not changed" do
180
180
  instance = TestDocument.find(subject.id)
181
181
  instance.should_not be_changed
182
182
  end
@@ -12,7 +12,7 @@ module MongoModel
12
12
 
13
13
  describe "multiparameter assignment from select" do
14
14
  context "setting a Time" do
15
- it "should combine and assign parameters as Time" do
15
+ it "combines and assign parameters as Time" do
16
16
  subject.attributes = {
17
17
  "timestamp(1i)" => "2009",
18
18
  "timestamp(2i)" => "10",
@@ -26,7 +26,7 @@ module MongoModel
26
26
  end
27
27
 
28
28
  context "setting a Date" do
29
- it "should combine and assign parameters as Date" do
29
+ it "combines and assign parameters as Date" do
30
30
  subject.attributes = {
31
31
  "datestamp(1i)" => "2008",
32
32
  "datestamp(2i)" => "4",
@@ -38,7 +38,7 @@ module MongoModel
38
38
  end
39
39
 
40
40
  context "setting a DateTime" do
41
- it "should combine and assign parameters as DateTime" do
41
+ it "combines and assign parameters as DateTime" do
42
42
  subject.attributes = {
43
43
  "datetime(1i)" => "2009",
44
44
  "datetime(2i)" => "10",
@@ -14,22 +14,22 @@ module MongoModel
14
14
  TestDocument.attr_protected :foo
15
15
  end
16
16
 
17
- it "should disallow the attribute to be mass-assigned via attributes=" do
17
+ it "disallows the attribute to be mass-assigned via attributes=" do
18
18
  subject.attributes = { :foo => 'value of foo' }
19
19
  subject.foo.should be_nil
20
20
  end
21
21
 
22
- it "should not disallow the attribute to be assigned individually" do
22
+ it "does not disallow the attribute to be assigned individually" do
23
23
  subject.foo = 'value of foo'
24
24
  subject.foo.should == 'value of foo'
25
25
  end
26
26
 
27
- it "should not disallow other attributes to be mass-assigned via attributes=" do
27
+ it "does not disallow other attributes to be mass-assigned via attributes=" do
28
28
  subject.attributes = { :bar => 'value of bar' }
29
29
  subject.bar.should == 'value of bar'
30
30
  end
31
31
 
32
- it "should accept multiple attributes" do
32
+ it "accepts multiple attributes" do
33
33
  TestDocument.attr_protected :foo, :bar
34
34
 
35
35
  subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
@@ -43,22 +43,22 @@ module MongoModel
43
43
  TestDocument.attr_accessible :foo
44
44
  end
45
45
 
46
- it "should allow the attribute to be mass-assigned via attributes=" do
46
+ it "allows the attribute to be mass-assigned via attributes=" do
47
47
  subject.attributes = { :foo => 'value of foo' }
48
48
  subject.foo.should == 'value of foo'
49
49
  end
50
50
 
51
- it "should not disallow other attributes to be mass-assigned via attributes=" do
51
+ it "does not disallow other attributes to be mass-assigned via attributes=" do
52
52
  subject.attributes = { :bar => 'value of bar' }
53
53
  subject.bar.should be_nil
54
54
  end
55
55
 
56
- it "should not disallow others attributes to be assigned individually" do
56
+ it "does not disallow others attributes to be assigned individually" do
57
57
  subject.bar = 'value of bar'
58
58
  subject.bar.should == 'value of bar'
59
59
  end
60
60
 
61
- it "should accept multiple attributes" do
61
+ it "accepts multiple attributes" do
62
62
  TestDocument.attr_accessible :foo, :bar
63
63
 
64
64
  subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
@@ -69,14 +69,14 @@ module MongoModel
69
69
 
70
70
  describe "#property" do
71
71
  context "with :protected option" do
72
- it "should make the attribute protected" do
72
+ it "makes the attribute protected" do
73
73
  TestDocument.should_receive(:attr_protected).with(:baz)
74
74
  TestDocument.property :baz, String, :protected => true
75
75
  end
76
76
  end
77
77
 
78
78
  context "with :accessible option" do
79
- it "should make the attribute accessible" do
79
+ it "makes the attribute accessible" do
80
80
  TestDocument.should_receive(:attr_accessible).with(:baz)
81
81
  TestDocument.property :baz, String, :accessible => true
82
82
  end