mongo_doc 0.6.26 → 0.6.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/README.textile +14 -203
  2. data/Rakefile +0 -134
  3. data/lib/mongo_doc/collection.rb +4 -0
  4. data/lib/mongo_doc/finders.rb +1 -0
  5. data/lib/mongo_doc/timestamps.rb +4 -3
  6. data/lib/mongo_doc/version.rb +3 -0
  7. data/lib/mongo_doc.rb +0 -5
  8. metadata +25 -212
  9. data/.document +0 -5
  10. data/.gitignore +0 -8
  11. data/.rspec +0 -2
  12. data/.rvmrc +0 -1
  13. data/.watchr +0 -32
  14. data/Gemfile +0 -3
  15. data/Gemfile.lock +0 -72
  16. data/HISTORY.md +0 -11
  17. data/VERSION +0 -1
  18. data/examples/simple_document.rb +0 -46
  19. data/examples/simple_object.rb +0 -34
  20. data/features/collections.feature +0 -9
  21. data/features/connection.feature +0 -13
  22. data/features/db_references.feature +0 -21
  23. data/features/embed_hash.feature +0 -16
  24. data/features/finders.feature +0 -76
  25. data/features/indexes.feature +0 -28
  26. data/features/mongodb.yml +0 -7
  27. data/features/mongodoc_base.feature +0 -128
  28. data/features/new_record.feature +0 -36
  29. data/features/partial_updates.feature +0 -95
  30. data/features/polymorphic_collections.feature +0 -16
  31. data/features/references.feature +0 -28
  32. data/features/removing_documents.feature +0 -68
  33. data/features/saving_an_object.feature +0 -15
  34. data/features/scopes.feature +0 -66
  35. data/features/step_definitions/collection_steps.rb +0 -17
  36. data/features/step_definitions/connection_steps.rb +0 -13
  37. data/features/step_definitions/document_steps.rb +0 -155
  38. data/features/step_definitions/documents.rb +0 -61
  39. data/features/step_definitions/embed_hash_steps.rb +0 -6
  40. data/features/step_definitions/field_steps.rb +0 -28
  41. data/features/step_definitions/finder_steps.rb +0 -15
  42. data/features/step_definitions/index_steps.rb +0 -10
  43. data/features/step_definitions/json_steps.rb +0 -9
  44. data/features/step_definitions/object_steps.rb +0 -50
  45. data/features/step_definitions/objects.rb +0 -24
  46. data/features/step_definitions/partial_update_steps.rb +0 -31
  47. data/features/step_definitions/query_steps.rb +0 -69
  48. data/features/step_definitions/removing_documents_steps.rb +0 -14
  49. data/features/step_definitions/scope_steps.rb +0 -18
  50. data/features/step_definitions/string_casting_steps.rb +0 -29
  51. data/features/step_definitions/util_steps.rb +0 -7
  52. data/features/string_casting.feature +0 -10
  53. data/features/support/support.rb +0 -12
  54. data/features/timestamps.feature +0 -14
  55. data/features/using_criteria.feature +0 -148
  56. data/mongo_doc.gemspec +0 -272
  57. data/mongodb.example.yml +0 -14
  58. data/perf/mongo_doc_object.rb +0 -83
  59. data/perf/mongo_document.rb +0 -84
  60. data/perf/ruby_driver.rb +0 -49
  61. data/script/console +0 -8
  62. data/spec/active_model_behavior.rb +0 -64
  63. data/spec/array_including_argument_matcher.rb +0 -62
  64. data/spec/associations/collection_proxy_spec.rb +0 -233
  65. data/spec/associations/document_proxy_spec.rb +0 -45
  66. data/spec/associations/hash_proxy_spec.rb +0 -181
  67. data/spec/associations/proxy_base_spec.rb +0 -92
  68. data/spec/associations_spec.rb +0 -218
  69. data/spec/attributes_accessor_spec.rb +0 -39
  70. data/spec/attributes_spec.rb +0 -184
  71. data/spec/bson_matchers.rb +0 -54
  72. data/spec/bson_spec.rb +0 -196
  73. data/spec/collection_spec.rb +0 -169
  74. data/spec/connection_spec.rb +0 -169
  75. data/spec/contexts/ids_spec.rb +0 -49
  76. data/spec/contexts/mongo_spec.rb +0 -241
  77. data/spec/contexts_spec.rb +0 -56
  78. data/spec/criteria/optional_spec.rb +0 -26
  79. data/spec/criteria_spec.rb +0 -73
  80. data/spec/cursor_spec.rb +0 -91
  81. data/spec/database_cleaner_spec.rb +0 -24
  82. data/spec/document_ext.rb +0 -9
  83. data/spec/document_spec.rb +0 -569
  84. data/spec/embedded_save_spec.rb +0 -73
  85. data/spec/ext_spec.rb +0 -100
  86. data/spec/finders_spec.rb +0 -61
  87. data/spec/hash_matchers.rb +0 -29
  88. data/spec/index_spec.rb +0 -79
  89. data/spec/matchers_spec.rb +0 -342
  90. data/spec/mongodb.yml +0 -6
  91. data/spec/mongodb_pairs.yml +0 -8
  92. data/spec/new_record_spec.rb +0 -128
  93. data/spec/polymorphic_collection_spec.rb +0 -47
  94. data/spec/references_many_spec.rb +0 -214
  95. data/spec/references_spec.rb +0 -121
  96. data/spec/root_spec.rb +0 -41
  97. data/spec/scope_spec.rb +0 -88
  98. data/spec/spec_helper.rb +0 -16
  99. data/spec/timestamps_spec.rb +0 -154
  100. data/spec/update_spec.rb +0 -167
  101. data/spec/validations_spec.rb +0 -30
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe MongoDoc::Timestamps do
4
- class TimestampsTest
5
- include MongoDoc::Document
6
-
7
- attr_accessor :name
8
-
9
- timestamps!
10
- end
11
-
12
- let(:collection) { stub(:save => ::BSON::ObjectID.new, :update => true) }
13
- let(:document) { TimestampsTest.new }
14
-
15
- before do
16
- TimestampsTest.stub(:collection).and_return(collection)
17
- end
18
-
19
- it "has a created_at attribute" do
20
- document.should respond_to(:created_at)
21
- document.should respond_to(:created_at=)
22
- end
23
-
24
- it "has an updated_at attribute" do
25
- document.should respond_to(:updated_at)
26
- document.should respond_to(:updated_at=)
27
- end
28
-
29
- context "on initial save" do
30
- context "that suceeeds" do
31
- it "sets the created_at timestamp" do
32
- document.save
33
- document.created_at.should_not be_nil
34
- end
35
-
36
- it "sets the updated_at timestamp" do
37
- document.save
38
- document.updated_at.should_not be_nil
39
- end
40
-
41
- it "the created_at and updated_at timestamps are the same" do
42
- document.save
43
- document.created_at.should == document.updated_at
44
- end
45
-
46
- it "sets the timezone to UTC" do
47
- document.save
48
- document.created_at.zone.should == "UTC"
49
- end
50
- end
51
-
52
- context "that fails" do
53
- before do
54
- collection.stub(:save).and_raise(Mongo::MongoDBError.new)
55
- end
56
-
57
- it "does not set the created_at timestamp" do
58
- document.save rescue nil
59
- document.created_at.should be_nil
60
- end
61
-
62
- it "does not set the updated_at timestamp" do
63
- document.save rescue nil
64
- document.updated_at.should be_nil
65
- end
66
- end
67
- end
68
-
69
- context "on subsequent save" do
70
- before do
71
- document.save
72
- end
73
-
74
- context "that suceeeds" do
75
- let!(:original_created_at) { document.created_at }
76
-
77
- it "leaves the created_at timestamp unchanged" do
78
- document.save
79
- document.created_at.should == original_created_at
80
- end
81
-
82
- it "sets the updated_at timestamp" do
83
- document.save
84
- document.updated_at.should_not == original_created_at
85
- end
86
-
87
- it "the created_at and updated_at timestamps are not the same" do
88
- document.save
89
- document.created_at.should_not == document.updated_at
90
- end
91
- end
92
-
93
- context "that fails" do
94
- let!(:original_created_at) { document.created_at }
95
-
96
- before do
97
- collection.stub(:save).and_raise(Mongo::MongoDBError.new)
98
- end
99
-
100
- it "leaves the created_at timestamp unchanged" do
101
- document.save rescue nil
102
- document.created_at.should == original_created_at
103
- end
104
-
105
- it "leaves the updated_at timestamp unchanged" do
106
- document.save rescue nil
107
- document.updated_at.should == original_created_at
108
- end
109
- end
110
- end
111
-
112
- context "on update attributes" do
113
- before do
114
- document.save
115
- end
116
-
117
- context "that suceeeds" do
118
- let!(:original_created_at) { document.created_at }
119
-
120
- it "leaves the created_at timestamp unchanged" do
121
- document.update_attributes(:name => 'name')
122
- document.created_at.should == original_created_at
123
- end
124
-
125
- it "sets the updated_at timestamp" do
126
- document.update_attributes(:name => 'name')
127
- document.updated_at.should_not == original_created_at
128
- end
129
-
130
- it "the created_at and updated_at timestamps are not the same" do
131
- document.update_attributes(:name => 'name')
132
- document.created_at.should_not == document.updated_at
133
- end
134
- end
135
-
136
- context "that fails" do
137
- let!(:original_created_at) { document.created_at }
138
-
139
- before do
140
- collection.stub(:update).and_raise(Mongo::MongoDBError.new)
141
- end
142
-
143
- it "leaves the created_at timestamp unchanged" do
144
- document.update_attributes(:name => 'name') rescue nil
145
- document.created_at.should == original_created_at
146
- end
147
-
148
- it "leaves the updated_at timestamp unchanged" do
149
- document.update_attributes(:name => 'name') rescue nil
150
- document.updated_at.should == original_created_at
151
- end
152
- end
153
- end
154
- end
data/spec/update_spec.rb DELETED
@@ -1,167 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "MongoDoc::Document" do
4
-
5
- class UpdateAttributesChild
6
- include MongoDoc::Document
7
-
8
- attr_accessor :child_data
9
- attr_accessor :child_int, :type => Integer
10
- end
11
-
12
- class UpdateAttributes
13
- include MongoDoc::Document
14
-
15
- attr_accessor :data
16
- attr_accessor :int, :type => Integer
17
- embed :child
18
- end
19
-
20
- let(:collection) { stub(:save => nil, :update => nil) }
21
- let(:child) do
22
- child = UpdateAttributesChild.new
23
- child._id = 'child exists'
24
- existing_doc.child = child
25
- child
26
- end
27
- let(:existing_doc) do
28
- doc = UpdateAttributes.new
29
- doc._id = 'exists'
30
- doc.stub(:_collection).and_return(collection)
31
- doc
32
- end
33
- let(:new_child) do
34
- child = UpdateAttributesChild.new
35
- existing_doc.child = child
36
- child
37
- end
38
-
39
- let(:new_doc) { UpdateAttributes.new }
40
-
41
- describe "#update" do
42
- context "with a new doc" do
43
- it "delegates to save! if the doc is a new record" do
44
- new_doc.should_receive(:_save)
45
- new_doc.update(:data => 'data', :int => '1')
46
- end
47
-
48
- it "delegates to the root's save if the child is a new record" do
49
- existing_doc.should_receive(:_save)
50
- new_child.update(:child_data => 'data', :child_int => '1')
51
- end
52
- end
53
-
54
- context "with an existing doc" do
55
-
56
- subject { existing_doc.update(:data => 'data', :int => '1') }
57
-
58
- it "sets the attributes" do
59
- subject
60
- existing_doc.data.should == 'data'
61
- existing_doc.int.should == 1
62
- end
63
-
64
- it "delegates to collection update" do
65
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => false)
66
- subject
67
- end
68
-
69
- context "that is embedded" do
70
- it "delegates to the root's collection update" do
71
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => true)
72
- child.update_attributes!(:child_data => 'data', :child_int => '1')
73
- end
74
- end
75
- end
76
- end
77
-
78
- describe "#update_attributes" do
79
- it "delegates to save if the doc is a new record" do
80
- new_doc.should_receive(:save)
81
- new_doc.update_attributes(:data => 'data', :int => '1')
82
- end
83
-
84
- context "with an existing doc" do
85
-
86
- subject { existing_doc.update_attributes(:data => 'data', :int => '1') }
87
-
88
- it "sets the attributes" do
89
- subject
90
- existing_doc.data.should == 'data'
91
- existing_doc.int.should == 1
92
- end
93
-
94
- it "validates the doc" do
95
- existing_doc.should_receive(:valid?)
96
- subject
97
- end
98
-
99
- it "returns false if the doc is not valid" do
100
- existing_doc.stub(:valid?).and_return(false)
101
- should be_false
102
- end
103
-
104
- it "delegates to collection update" do
105
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => false)
106
- subject
107
- end
108
-
109
- context "that is embedded" do
110
- it "delegates to the root's collection update" do
111
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => false)
112
- child.update_attributes(:child_data => 'data', :child_int => '1')
113
- end
114
- end
115
- end
116
- end
117
-
118
- describe "#update_attributes!" do
119
- it "delegates to save! if the doc is a new record" do
120
- new_doc.should_receive(:save!)
121
- new_doc.update_attributes!(:data => 'data', :int => '1')
122
- end
123
-
124
- context "with an existing doc" do
125
-
126
- subject { existing_doc.update_attributes!(:data => 'data', :int => '1') }
127
-
128
- it "sets the attributes" do
129
- subject
130
- existing_doc.data.should == 'data'
131
- existing_doc.int.should == 1
132
- end
133
-
134
- it "validates the doc" do
135
- existing_doc.should_receive(:valid?).and_return(true)
136
- subject
137
- end
138
-
139
- it "raises if not valid" do
140
- existing_doc.stub(:valid?).and_return(false)
141
- expect do
142
- subject
143
- end.should raise_error(MongoDoc::DocumentInvalidError)
144
- end
145
-
146
- it "delegates to collection update" do
147
- collection.should_receive(:update).with({'_id' => existing_doc._id}, {'$set' => {:data => 'data', :int => 1}}, :safe => true)
148
- subject
149
- end
150
-
151
- context "that is embedded" do
152
- it "delegates to the root's collection update" do
153
- collection.should_receive(:update).with({'_id' => existing_doc._id, 'child._id' => child._id}, {'$set' => {'child.child_data' => 'data', 'child.child_int' => 1}}, :safe => true)
154
- child.update_attributes!(:child_data => 'data', :child_int => '1')
155
- end
156
- end
157
- end
158
- end
159
-
160
- describe "#hash_with_modifier_path_keys" do
161
- it "returns a hash with the keys prepended with the modifier path" do
162
- new_doc.stub(:_modifier_path).and_return('path.to.root')
163
- new_doc.send(:hash_with_modifier_path_keys, :name => 1).should == {'path.to.root.name' => 1}
164
- end
165
- end
166
-
167
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe MongoDoc::Validations do
4
-
5
- class ValidationTest
6
- include MongoDoc::Document
7
-
8
- attr_accessor :data
9
- validates_presence_of :data
10
- end
11
-
12
- context "requirements" do
13
- subject { ValidationTest.new }
14
-
15
- it { should respond_to(:valid?) }
16
- it { should respond_to(:errors) }
17
-
18
- it "is included by Document" do
19
- ::ActiveModel::Validations.should === subject
20
- end
21
- end
22
-
23
- context "validations" do
24
- it "valid? fails when a document is invalid" do
25
- doc = ValidationTest.new
26
- doc.should_not be_valid
27
- doc.should have(1).error_on(:data)
28
- end
29
- end
30
- end