mongomodel 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +23 -11
  3. data/gemfiles/rails-3.2.gemfile +2 -2
  4. data/gemfiles/rails-4-observers.gemfile +1 -1
  5. data/gemfiles/rails-4.1.gemfile +2 -2
  6. data/gemfiles/{mongoid.gemfile → rails-4.2.gemfile} +2 -3
  7. data/gemfiles/{mongo_mapper.gemfile → rails-5.0.gemfile} +2 -3
  8. data/gemfiles/rails-5.1.gemfile +10 -0
  9. data/gemfiles/rails-5.2.gemfile +10 -0
  10. data/lib/mongomodel.rb +15 -15
  11. data/lib/mongomodel/attributes/mongo.rb +7 -7
  12. data/lib/mongomodel/attributes/store.rb +4 -4
  13. data/lib/mongomodel/attributes/typecasting.rb +7 -7
  14. data/lib/mongomodel/compatibility/mongo_mapper.rb +3 -3
  15. data/lib/mongomodel/compatibility/mongoid.rb +3 -3
  16. data/lib/mongomodel/concerns/abstract_class.rb +3 -3
  17. data/lib/mongomodel/concerns/activemodel.rb +4 -4
  18. data/lib/mongomodel/concerns/associations.rb +8 -8
  19. data/lib/mongomodel/concerns/associations/base/association.rb +5 -5
  20. data/lib/mongomodel/concerns/associations/base/definition.rb +4 -4
  21. data/lib/mongomodel/concerns/associations/base/proxy.rb +1 -1
  22. data/lib/mongomodel/concerns/associations/belongs_to.rb +19 -19
  23. data/lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb +36 -36
  24. data/lib/mongomodel/concerns/associations/has_many_by_ids.rb +34 -34
  25. data/lib/mongomodel/concerns/attribute_methods.rb +10 -10
  26. data/lib/mongomodel/concerns/attribute_methods/before_type_cast.rb +4 -4
  27. data/lib/mongomodel/concerns/attribute_methods/dirty.rb +95 -13
  28. data/lib/mongomodel/concerns/attribute_methods/forbidden.rb +1 -1
  29. data/lib/mongomodel/concerns/attribute_methods/multi_parameter_assignment.rb +6 -6
  30. data/lib/mongomodel/concerns/attribute_methods/nested.rb +18 -18
  31. data/lib/mongomodel/concerns/attribute_methods/protected.rb +3 -3
  32. data/lib/mongomodel/concerns/attribute_methods/query.rb +3 -3
  33. data/lib/mongomodel/concerns/attribute_methods/read.rb +4 -4
  34. data/lib/mongomodel/concerns/attribute_methods/write.rb +4 -4
  35. data/lib/mongomodel/concerns/attributes.rb +18 -18
  36. data/lib/mongomodel/concerns/callbacks.rb +7 -7
  37. data/lib/mongomodel/concerns/document_parent.rb +2 -2
  38. data/lib/mongomodel/concerns/logging.rb +2 -2
  39. data/lib/mongomodel/concerns/map_reduce.rb +11 -11
  40. data/lib/mongomodel/concerns/pretty_inspect.rb +3 -3
  41. data/lib/mongomodel/concerns/properties.rb +18 -18
  42. data/lib/mongomodel/concerns/record_status.rb +9 -13
  43. data/lib/mongomodel/concerns/serialization.rb +4 -4
  44. data/lib/mongomodel/concerns/timestamps.rb +4 -4
  45. data/lib/mongomodel/concerns/translation.rb +2 -2
  46. data/lib/mongomodel/concerns/validations.rb +5 -5
  47. data/lib/mongomodel/concerns/validations/associated.rb +1 -1
  48. data/lib/mongomodel/document.rb +6 -6
  49. data/lib/mongomodel/document/callbacks.rb +15 -21
  50. data/lib/mongomodel/document/collection_modifiers.rb +5 -5
  51. data/lib/mongomodel/document/dynamic_finders.rb +1 -1
  52. data/lib/mongomodel/document/indexes.rb +19 -19
  53. data/lib/mongomodel/document/optimistic_locking.rb +7 -7
  54. data/lib/mongomodel/document/persistence.rb +23 -23
  55. data/lib/mongomodel/document/scopes.rb +20 -20
  56. data/lib/mongomodel/document/validations.rb +6 -6
  57. data/lib/mongomodel/document/validations/uniqueness.rb +11 -11
  58. data/lib/mongomodel/embedded_document.rb +11 -11
  59. data/lib/mongomodel/locale/en.yml +0 -1
  60. data/lib/mongomodel/log_subscriber.rb +5 -5
  61. data/lib/mongomodel/railtie.rb +13 -13
  62. data/lib/mongomodel/support/collection.rb +31 -31
  63. data/lib/mongomodel/support/configuration.rb +11 -11
  64. data/lib/mongomodel/support/core_extensions.rb +1 -1
  65. data/lib/mongomodel/support/dynamic_finder.rb +12 -12
  66. data/lib/mongomodel/support/exceptions.rb +6 -6
  67. data/lib/mongomodel/support/instrumented_collection.rb +20 -20
  68. data/lib/mongomodel/support/map.rb +33 -33
  69. data/lib/mongomodel/support/mongo_operator.rb +6 -6
  70. data/lib/mongomodel/support/mongo_options.rb +18 -18
  71. data/lib/mongomodel/support/mongo_order.rb +16 -16
  72. data/lib/mongomodel/support/paginator.rb +8 -8
  73. data/lib/mongomodel/support/reference.rb +10 -10
  74. data/lib/mongomodel/support/scope.rb +37 -37
  75. data/lib/mongomodel/support/scope/array_methods.rb +1 -1
  76. data/lib/mongomodel/support/scope/batches.rb +1 -1
  77. data/lib/mongomodel/support/scope/dynamic_finders.rb +1 -1
  78. data/lib/mongomodel/support/scope/finder_methods.rb +7 -7
  79. data/lib/mongomodel/support/scope/load_methods.rb +1 -1
  80. data/lib/mongomodel/support/scope/pagination.rb +1 -1
  81. data/lib/mongomodel/support/scope/query_methods.rb +6 -6
  82. data/lib/mongomodel/support/scope/spawn_methods.rb +8 -8
  83. data/lib/mongomodel/support/types.rb +2 -2
  84. data/lib/mongomodel/support/types/array.rb +1 -1
  85. data/lib/mongomodel/support/types/boolean.rb +3 -3
  86. data/lib/mongomodel/support/types/custom.rb +3 -3
  87. data/lib/mongomodel/support/types/date.rb +2 -2
  88. data/lib/mongomodel/support/types/date_time.rb +6 -16
  89. data/lib/mongomodel/support/types/float.rb +1 -1
  90. data/lib/mongomodel/support/types/hash.rb +1 -1
  91. data/lib/mongomodel/support/types/integer.rb +13 -10
  92. data/lib/mongomodel/support/types/object.rb +5 -5
  93. data/lib/mongomodel/support/types/rational.rb +3 -3
  94. data/lib/mongomodel/support/types/time.rb +2 -2
  95. data/lib/mongomodel/version.rb +1 -1
  96. data/lib/rails/generators/mongo_model/config/templates/mongomodel.yml +3 -4
  97. data/lib/rails/generators/mongo_model/model/model_generator.rb +3 -3
  98. data/mongomodel.gemspec +5 -4
  99. data/spec/mongomodel/attributes/store_spec.rb +21 -21
  100. data/spec/mongomodel/concerns/activemodel_spec.rb +4 -4
  101. data/spec/mongomodel/concerns/associations/base/association_spec.rb +12 -12
  102. data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +34 -21
  103. data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +53 -53
  104. data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +30 -30
  105. data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +7 -7
  106. data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +45 -41
  107. data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +7 -7
  108. data/spec/mongomodel/concerns/attribute_methods/nested_spec.rb +31 -31
  109. data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +15 -15
  110. data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +19 -19
  111. data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +9 -9
  112. data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +6 -6
  113. data/spec/mongomodel/concerns/attribute_methods_spec.rb +13 -13
  114. data/spec/mongomodel/concerns/attributes_spec.rb +34 -34
  115. data/spec/mongomodel/concerns/callbacks_spec.rb +25 -21
  116. data/spec/mongomodel/concerns/logging_spec.rb +5 -3
  117. data/spec/mongomodel/concerns/map_reduce_spec.rb +19 -19
  118. data/spec/mongomodel/concerns/observing_spec.rb +3 -3
  119. data/spec/mongomodel/concerns/pretty_inspect_spec.rb +10 -10
  120. data/spec/mongomodel/concerns/properties_spec.rb +11 -11
  121. data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +13 -13
  122. data/spec/mongomodel/concerns/timestamps_spec.rb +39 -39
  123. data/spec/mongomodel/concerns/validations_spec.rb +41 -38
  124. data/spec/mongomodel/document/callbacks_spec.rb +20 -16
  125. data/spec/mongomodel/document/collection_modifiers_spec.rb +16 -16
  126. data/spec/mongomodel/document/dynamic_finders_spec.rb +46 -46
  127. data/spec/mongomodel/document/finders_spec.rb +15 -15
  128. data/spec/mongomodel/document/indexes_spec.rb +29 -29
  129. data/spec/mongomodel/document/optimistic_locking_spec.rb +16 -16
  130. data/spec/mongomodel/document/persistence_spec.rb +39 -39
  131. data/spec/mongomodel/document/scopes_spec.rb +17 -17
  132. data/spec/mongomodel/document/validations/uniqueness_spec.rb +46 -46
  133. data/spec/mongomodel/document/validations_spec.rb +35 -35
  134. data/spec/mongomodel/document_spec.rb +19 -19
  135. data/spec/mongomodel/embedded_document_spec.rb +19 -19
  136. data/spec/mongomodel/mongomodel_spec.rb +7 -6
  137. data/spec/mongomodel/support/collection_spec.rb +54 -54
  138. data/spec/mongomodel/support/configuration_spec.rb +1 -1
  139. data/spec/mongomodel/support/map_spec.rb +66 -66
  140. data/spec/mongomodel/support/mongo_operator_spec.rb +5 -5
  141. data/spec/mongomodel/support/mongo_options_spec.rb +42 -42
  142. data/spec/mongomodel/support/mongo_order_spec.rb +24 -24
  143. data/spec/mongomodel/support/paginator_spec.rb +15 -15
  144. data/spec/mongomodel/support/property_spec.rb +29 -23
  145. data/spec/mongomodel/support/scope_spec.rb +205 -204
  146. data/spec/spec_helper.rb +13 -2
  147. data/spec/support/callbacks.rb +3 -8
  148. data/spec/support/helpers/define_class.rb +7 -7
  149. data/spec/support/helpers/document_finder_stubs.rb +6 -6
  150. data/spec/support/helpers/specs_for.rb +1 -1
  151. data/spec/support/helpers/validations.rb +1 -1
  152. data/spec/support/matchers/find_with.rb +8 -8
  153. data/spec/support/matchers/respond_to_boolean.rb +3 -3
  154. data/spec/support/matchers/run_callbacks.rb +6 -9
  155. data/spec/support/models.rb +5 -5
  156. metadata +23 -7
@@ -8,7 +8,7 @@ module MongoModel
8
8
  property :age, Integer
9
9
  end
10
10
  end
11
-
11
+
12
12
  describe ".accepts_nested_attributes_for" do
13
13
  describe "single embedded property" do
14
14
  define_user(EmbeddedDocument)
@@ -16,15 +16,15 @@ module MongoModel
16
16
  property :owner, User
17
17
  accepts_nested_attributes_for :owner
18
18
  end
19
-
19
+
20
20
  subject { Account.new }
21
-
21
+
22
22
  it "creates new model when property is blank" do
23
23
  subject.owner_attributes = { :name => "John Smith", :age => 35 }
24
24
  subject.owner.name.should == "John Smith"
25
25
  subject.owner.age.should == 35
26
26
  end
27
-
27
+
28
28
  it "sets existing model attributes when property exists" do
29
29
  subject.owner = User.new(:name => "Jane Doe")
30
30
  subject.owner_attributes = { :age => 22 }
@@ -32,85 +32,85 @@ module MongoModel
32
32
  subject.owner.age.should == 22
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe "embedded collection" do
37
37
  define_user(EmbeddedDocument)
38
38
  define_class(:Account, described_class) do
39
39
  property :owners, Collection[User]
40
40
  accepts_nested_attributes_for :owners
41
41
  end
42
-
42
+
43
43
  subject { Account.new }
44
-
44
+
45
45
  it "accepts an array of hashes" do
46
46
  subject.owners_attributes = [
47
47
  { :name => "Fred", :age => 35 },
48
48
  { :name => "Mary", :age => 22 }
49
49
  ]
50
-
50
+
51
51
  subject.owners[0].name.should == "Fred"
52
52
  subject.owners[0].age.should == 35
53
53
  subject.owners[1].name.should == "Mary"
54
54
  subject.owners[1].age.should == 22
55
55
  end
56
-
56
+
57
57
  it "accepts a hash keyed by indexes" do
58
58
  subject.owners_attributes = {
59
59
  "1" => { :name => "Joe", :age => 15 },
60
60
  "0" => { :name => "Peter", :age => 44 }
61
61
  }
62
-
62
+
63
63
  subject.owners[0].name.should == "Peter"
64
64
  subject.owners[0].age.should == 44
65
65
  subject.owners[1].name.should == "Joe"
66
66
  subject.owners[1].age.should == 15
67
67
  end
68
-
68
+
69
69
  it "modifies existing collection" do
70
70
  subject.owners << User.new(:name => "John")
71
71
  subject.owners_attributes = [
72
72
  { :age => 18 },
73
73
  { :name => "Max", :age => 10 }
74
74
  ]
75
-
75
+
76
76
  subject.owners[0].name.should == "John"
77
77
  subject.owners[0].age.should == 18
78
78
  subject.owners[1].name.should == "Max"
79
79
  subject.owners[1].age.should == 10
80
80
  end
81
81
  end
82
-
82
+
83
83
  describe "embedded collection with limit" do
84
84
  define_user(EmbeddedDocument)
85
85
  define_class(:Account, described_class) do
86
86
  property :owners, Collection[User]
87
87
  accepts_nested_attributes_for :owners, :limit => 2
88
88
  end
89
-
89
+
90
90
  subject { Account.new }
91
-
91
+
92
92
  it "raises a TooManyDocuments error if number of documents exceeds limit" do
93
93
  lambda {
94
94
  subject.owners_attributes = [{}, {}, {}]
95
95
  }.should raise_error(MongoModel::TooManyDocuments, "Maximum 2 documents are allowed. Got 3 documents instead.")
96
96
  end
97
97
  end
98
-
98
+
99
99
  describe "embedded collection with :clear => true" do
100
100
  define_user(EmbeddedDocument)
101
101
  define_class(:Account, described_class) do
102
102
  property :owners, Collection[User]
103
103
  accepts_nested_attributes_for :owners, :clear => true
104
104
  end
105
-
105
+
106
106
  subject { Account.new(:owners => [User.new, User.new]) }
107
-
107
+
108
108
  it "clears the collection first when assigning attributes" do
109
109
  subject.owners_attributes = [{ :age => 18 }]
110
110
  subject.owners.size.should == 1
111
111
  end
112
112
  end
113
-
113
+
114
114
  describe "belongs_to association" do
115
115
  define_user(Document)
116
116
  define_class(:Account, described_class) do
@@ -135,68 +135,68 @@ module MongoModel
135
135
  end
136
136
  end
137
137
  end
138
-
138
+
139
139
  specs_for(Document) do
140
140
  define_class(:User, Document) do
141
141
  property :name, String
142
142
  property :age, Integer
143
143
  end
144
-
144
+
145
145
  describe ".accepts_nested_attributes_for" do
146
146
  describe "has_many association" do
147
147
  define_class(:Account, described_class) do
148
148
  has_many :owners, :class => User
149
149
  accepts_nested_attributes_for :owners
150
150
  end
151
-
151
+
152
152
  subject { Account.new }
153
-
153
+
154
154
  it "accepts an array of hashes" do
155
155
  subject.owners_attributes = [
156
156
  { :name => "Fred", :age => 35 },
157
157
  { :name => "Mary", :age => 22 }
158
158
  ]
159
-
159
+
160
160
  subject.owners[0].name.should == "Fred"
161
161
  subject.owners[0].age.should == 35
162
162
  subject.owners[1].name.should == "Mary"
163
163
  subject.owners[1].age.should == 22
164
164
  end
165
-
165
+
166
166
  it "accepts a hash keyed by indexes" do
167
167
  subject.owners_attributes = {
168
168
  "1" => { :name => "Joe", :age => 15 },
169
169
  "0" => { :name => "Peter", :age => 44 }
170
170
  }
171
-
171
+
172
172
  subject.owners[0].name.should == "Peter"
173
173
  subject.owners[0].age.should == 44
174
174
  subject.owners[1].name.should == "Joe"
175
175
  subject.owners[1].age.should == 15
176
176
  end
177
177
  end
178
-
178
+
179
179
  describe "has_many association with limit" do
180
180
  define_class(:Account, described_class) do
181
181
  has_many :owners, :class => User
182
182
  accepts_nested_attributes_for :owners, :limit => 2
183
183
  end
184
-
184
+
185
185
  subject { Account.new }
186
-
186
+
187
187
  it "raises a TooManyDocuments error if number of documents exceeds limit" do
188
188
  lambda {
189
189
  subject.owners_attributes = [{}, {}, {}]
190
190
  }.should raise_error(MongoModel::TooManyDocuments, "Maximum 2 documents are allowed. Got 3 documents instead.")
191
191
  end
192
192
  end
193
-
193
+
194
194
  describe "has_many association with :clear => true" do
195
195
  define_class(:Account, described_class) do
196
196
  has_many :owners, :class => User
197
197
  accepts_nested_attributes_for :owners, :clear => true
198
198
  end
199
-
199
+
200
200
  subject { Account.new(:owners => [User.new, User.new]) }
201
201
 
202
202
  it "clears the collection first when assigning attributes" do
@@ -6,67 +6,67 @@ module MongoModel
6
6
  property :foo, String
7
7
  property :bar, String
8
8
  end
9
-
9
+
10
10
  subject { TestDocument.new }
11
-
11
+
12
12
  describe "#attr_protected" do
13
13
  before(:each) do
14
14
  TestDocument.attr_protected :foo
15
15
  end
16
-
16
+
17
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
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
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
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' }
36
36
  subject.foo.should be_nil
37
37
  subject.bar.should be_nil
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe "#attr_accessible" do
42
42
  before(:each) do
43
43
  TestDocument.attr_accessible :foo
44
44
  end
45
-
45
+
46
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
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
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
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' }
65
65
  subject.foo.should == 'value of foo'
66
66
  subject.bar.should == 'value of bar'
67
67
  end
68
68
  end
69
-
69
+
70
70
  describe "#property" do
71
71
  context "with :protected option" do
72
72
  it "makes the attribute protected" do
@@ -74,7 +74,7 @@ module MongoModel
74
74
  TestDocument.property :baz, String, :protected => true
75
75
  end
76
76
  end
77
-
77
+
78
78
  context "with :accessible option" do
79
79
  it "makes the attribute accessible" do
80
80
  TestDocument.should_receive(:attr_accessible).with(:baz)
@@ -6,47 +6,47 @@ module MongoModel
6
6
  property :foo, String
7
7
  property :boolean, Boolean
8
8
  end
9
-
9
+
10
10
  subject { TestDocument.new }
11
-
11
+
12
12
  describe "#query_attribute" do
13
13
  context "string attribute" do
14
14
  it "returns true if the attribute is not blank" do
15
15
  subject.foo = 'set foo'
16
- subject.query_attribute(:foo).should be_true
17
- subject.foo?.should be_true
16
+ subject.query_attribute(:foo).should be true
17
+ subject.foo?.should be true
18
18
  end
19
-
19
+
20
20
  it "returns false if the attribute is nil" do
21
21
  subject.foo = nil
22
- subject.query_attribute(:foo).should be_false
23
- subject.foo?.should be_false
22
+ subject.query_attribute(:foo).should be false
23
+ subject.foo?.should be false
24
24
  end
25
-
25
+
26
26
  it "returns false if the attribute is blank" do
27
27
  subject.foo = ''
28
- subject.query_attribute(:foo).should be_false
29
- subject.foo?.should be_false
28
+ subject.query_attribute(:foo).should be false
29
+ subject.foo?.should be false
30
30
  end
31
31
  end
32
-
32
+
33
33
  context "boolean attribute" do
34
34
  it "returns true if the attribute is true" do
35
35
  subject.boolean = true
36
- subject.query_attribute(:boolean).should be_true
37
- subject.boolean?.should be_true
36
+ subject.query_attribute(:boolean).should be true
37
+ subject.boolean?.should be true
38
38
  end
39
-
39
+
40
40
  it "returns false if the attribute is nil" do
41
41
  subject.boolean = nil
42
- subject.query_attribute(:boolean).should be_false
43
- subject.boolean?.should be_false
42
+ subject.query_attribute(:boolean).should be false
43
+ subject.boolean?.should be false
44
44
  end
45
-
45
+
46
46
  it "returns false if the attribute is false" do
47
47
  subject.boolean = false
48
- subject.query_attribute(:boolean).should be_false
49
- subject.boolean?.should be_false
48
+ subject.query_attribute(:boolean).should be false
49
+ subject.boolean?.should be false
50
50
  end
51
51
  end
52
52
  end
@@ -5,31 +5,31 @@ module MongoModel
5
5
  define_class(:TestDocument, described_class) do
6
6
  property :foo, String
7
7
  end
8
-
8
+
9
9
  subject { TestDocument.new(:foo => 'value of foo', :bar => 'value of bar') }
10
-
10
+
11
11
  describe "#read_attribute" do
12
12
  context "valid property" do
13
13
  it "returns the attribute value" do
14
14
  subject.read_attribute(:foo).should == 'value of foo'
15
15
  end
16
-
16
+
17
17
  it "defines a reader method" do
18
18
  subject.foo.should == 'value of foo'
19
19
  end
20
20
  end
21
-
21
+
22
22
  context "no property" do
23
23
  it "returns the attribute value" do
24
24
  subject.read_attribute(:bar).should == 'value of bar'
25
25
  end
26
-
26
+
27
27
  it "does not define a reader method" do
28
28
  lambda { subject.bar }.should raise_error(NoMethodError)
29
29
  end
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "#[]" do
34
34
  it "reads the given attribute" do
35
35
  subject.should_receive(:read_attribute).with(:foo).and_return('value of foo')
@@ -37,12 +37,12 @@ module MongoModel
37
37
  end
38
38
  end
39
39
  end
40
-
40
+
41
41
  specs_for(Document) do
42
42
  define_class(:TestDocument, Document)
43
-
43
+
44
44
  subject { TestDocument.new }
45
-
45
+
46
46
  describe "#id" do
47
47
  it "returns id from attributes" do
48
48
  subject.id.should == subject.attributes[:id]
@@ -5,34 +5,34 @@ module MongoModel
5
5
  define_class(:TestDocument, described_class) do
6
6
  property :foo, String
7
7
  end
8
-
8
+
9
9
  subject { TestDocument.new }
10
-
10
+
11
11
  describe "#write_attribute" do
12
12
  context "with property" do
13
13
  it "sets the attribute hash" do
14
14
  subject.write_attribute(:foo, 'set foo')
15
15
  subject.attributes[:foo].should == 'set foo'
16
16
  end
17
-
17
+
18
18
  it "defines a writer method" do
19
19
  subject.foo = 'set foo'
20
20
  subject.attributes[:foo].should == 'set foo'
21
21
  end
22
22
  end
23
-
23
+
24
24
  context "no property" do
25
25
  it "sets the attribute hash" do
26
26
  subject.write_attribute(:bar, 'set bar')
27
27
  subject.attributes[:bar].should == 'set bar'
28
28
  end
29
-
29
+
30
30
  it "does not define a writer method" do
31
31
  lambda { subject.bar = 'set bar' }.should raise_error(NoMethodError)
32
32
  end
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe "#[]=" do
37
37
  it "writes the given attribute" do
38
38
  subject.should_receive(:write_attribute).with(:foo, 'value of foo')