mongo_doc_rails2 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/.document +5 -0
  2. data/.gitignore +8 -0
  3. data/HISTORY.md +11 -0
  4. data/LICENSE +20 -0
  5. data/README.textile +185 -0
  6. data/Rakefile +188 -0
  7. data/TODO +40 -0
  8. data/VERSION +1 -0
  9. data/data/.gitignore +2 -0
  10. data/examples/simple_document.rb +46 -0
  11. data/examples/simple_object.rb +34 -0
  12. data/features/collections.feature +9 -0
  13. data/features/embed_hash.feature +16 -0
  14. data/features/finders.feature +76 -0
  15. data/features/indexes.feature +28 -0
  16. data/features/mongodb.yml +7 -0
  17. data/features/mongodoc_base.feature +128 -0
  18. data/features/new_record.feature +36 -0
  19. data/features/partial_updates.feature +95 -0
  20. data/features/removing_documents.feature +68 -0
  21. data/features/saving_an_object.feature +15 -0
  22. data/features/scopes.feature +66 -0
  23. data/features/step_definitions/collection_steps.rb +17 -0
  24. data/features/step_definitions/document_steps.rb +149 -0
  25. data/features/step_definitions/documents.rb +40 -0
  26. data/features/step_definitions/embed_hash_steps.rb +6 -0
  27. data/features/step_definitions/finder_steps.rb +15 -0
  28. data/features/step_definitions/index_steps.rb +10 -0
  29. data/features/step_definitions/json_steps.rb +9 -0
  30. data/features/step_definitions/object_steps.rb +50 -0
  31. data/features/step_definitions/objects.rb +24 -0
  32. data/features/step_definitions/partial_update_steps.rb +31 -0
  33. data/features/step_definitions/query_steps.rb +66 -0
  34. data/features/step_definitions/removing_documents_steps.rb +14 -0
  35. data/features/step_definitions/scope_steps.rb +18 -0
  36. data/features/step_definitions/string_casting_steps.rb +29 -0
  37. data/features/step_definitions/util_steps.rb +7 -0
  38. data/features/string_casting.feature +10 -0
  39. data/features/support/support.rb +10 -0
  40. data/features/using_criteria.feature +142 -0
  41. data/lib/mongo_doc.rb +12 -0
  42. data/lib/mongo_doc/associations.rb +109 -0
  43. data/lib/mongo_doc/associations/collection_proxy.rb +121 -0
  44. data/lib/mongo_doc/associations/document_proxy.rb +65 -0
  45. data/lib/mongo_doc/associations/hash_proxy.rb +102 -0
  46. data/lib/mongo_doc/associations/proxy_base.rb +48 -0
  47. data/lib/mongo_doc/attributes.rb +84 -0
  48. data/lib/mongo_doc/bson.rb +31 -0
  49. data/lib/mongo_doc/collection.rb +82 -0
  50. data/lib/mongo_doc/connection.rb +88 -0
  51. data/lib/mongo_doc/contexts.rb +31 -0
  52. data/lib/mongo_doc/contexts/ids.rb +41 -0
  53. data/lib/mongo_doc/contexts/mongo.rb +272 -0
  54. data/lib/mongo_doc/criteria.rb +70 -0
  55. data/lib/mongo_doc/cursor.rb +32 -0
  56. data/lib/mongo_doc/document.rb +205 -0
  57. data/lib/mongo_doc/ext.rb +16 -0
  58. data/lib/mongo_doc/ext/array.rb +5 -0
  59. data/lib/mongo_doc/ext/binary.rb +7 -0
  60. data/lib/mongo_doc/ext/boolean_class.rb +17 -0
  61. data/lib/mongo_doc/ext/date.rb +19 -0
  62. data/lib/mongo_doc/ext/date_time.rb +17 -0
  63. data/lib/mongo_doc/ext/dbref.rb +7 -0
  64. data/lib/mongo_doc/ext/hash.rb +7 -0
  65. data/lib/mongo_doc/ext/min_max_keys.rb +13 -0
  66. data/lib/mongo_doc/ext/nil_class.rb +5 -0
  67. data/lib/mongo_doc/ext/numeric.rb +17 -0
  68. data/lib/mongo_doc/ext/object.rb +19 -0
  69. data/lib/mongo_doc/ext/object_id.rb +7 -0
  70. data/lib/mongo_doc/ext/regexp.rb +5 -0
  71. data/lib/mongo_doc/ext/string.rb +5 -0
  72. data/lib/mongo_doc/ext/symbol.rb +5 -0
  73. data/lib/mongo_doc/ext/time.rb +9 -0
  74. data/lib/mongo_doc/finders.rb +38 -0
  75. data/lib/mongo_doc/index.rb +46 -0
  76. data/lib/mongo_doc/matchers.rb +35 -0
  77. data/lib/mongo_doc/root.rb +26 -0
  78. data/lib/mongo_doc/scope.rb +64 -0
  79. data/lib/mongo_doc/validations.rb +12 -0
  80. data/lib/mongo_doc/validations/macros.rb +11 -0
  81. data/lib/mongo_doc/validations/validates_embedded.rb +13 -0
  82. data/lib/mongoid/contexts/enumerable.rb +151 -0
  83. data/lib/mongoid/contexts/paging.rb +42 -0
  84. data/lib/mongoid/criteria.rb +239 -0
  85. data/lib/mongoid/criterion/complex.rb +21 -0
  86. data/lib/mongoid/criterion/exclusion.rb +65 -0
  87. data/lib/mongoid/criterion/inclusion.rb +93 -0
  88. data/lib/mongoid/criterion/optional.rb +136 -0
  89. data/lib/mongoid/extensions/hash/criteria_helpers.rb +20 -0
  90. data/lib/mongoid/extensions/symbol/inflections.rb +36 -0
  91. data/lib/mongoid/matchers/all.rb +11 -0
  92. data/lib/mongoid/matchers/default.rb +26 -0
  93. data/lib/mongoid/matchers/exists.rb +13 -0
  94. data/lib/mongoid/matchers/gt.rb +11 -0
  95. data/lib/mongoid/matchers/gte.rb +11 -0
  96. data/lib/mongoid/matchers/in.rb +11 -0
  97. data/lib/mongoid/matchers/lt.rb +11 -0
  98. data/lib/mongoid/matchers/lte.rb +11 -0
  99. data/lib/mongoid/matchers/ne.rb +11 -0
  100. data/lib/mongoid/matchers/nin.rb +11 -0
  101. data/lib/mongoid/matchers/size.rb +11 -0
  102. data/mongo_doc_rails2.gemspec +237 -0
  103. data/mongod.example.yml +2 -0
  104. data/mongodb.example.yml +14 -0
  105. data/perf/mongo_doc_object.rb +83 -0
  106. data/perf/mongo_document.rb +84 -0
  107. data/perf/ruby_driver.rb +49 -0
  108. data/script/console +8 -0
  109. data/spec/array_including_argument_matcher.rb +62 -0
  110. data/spec/associations/collection_proxy_spec.rb +233 -0
  111. data/spec/associations/document_proxy_spec.rb +45 -0
  112. data/spec/associations/hash_proxy_spec.rb +181 -0
  113. data/spec/associations/proxy_base_spec.rb +92 -0
  114. data/spec/associations_spec.rb +218 -0
  115. data/spec/attributes_accessor_spec.rb +33 -0
  116. data/spec/attributes_spec.rb +145 -0
  117. data/spec/bson_matchers.rb +54 -0
  118. data/spec/bson_spec.rb +196 -0
  119. data/spec/collection_spec.rb +169 -0
  120. data/spec/connection_spec.rb +147 -0
  121. data/spec/contexts/ids_spec.rb +49 -0
  122. data/spec/contexts/mongo_spec.rb +235 -0
  123. data/spec/contexts_spec.rb +56 -0
  124. data/spec/criteria_spec.rb +69 -0
  125. data/spec/cursor_spec.rb +91 -0
  126. data/spec/document_ext.rb +9 -0
  127. data/spec/document_spec.rb +553 -0
  128. data/spec/embedded_save_spec.rb +73 -0
  129. data/spec/ext_spec.rb +89 -0
  130. data/spec/finders_spec.rb +61 -0
  131. data/spec/hash_matchers.rb +27 -0
  132. data/spec/index_spec.rb +79 -0
  133. data/spec/matchers_spec.rb +342 -0
  134. data/spec/mongodb.yml +6 -0
  135. data/spec/mongodb_pairs.yml +8 -0
  136. data/spec/new_record_spec.rb +128 -0
  137. data/spec/root_spec.rb +41 -0
  138. data/spec/scope_spec.rb +79 -0
  139. data/spec/spec.opts +2 -0
  140. data/spec/spec_helper.rb +14 -0
  141. data/spec/validations_spec.rb +30 -0
  142. metadata +346 -0
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.1
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
@@ -0,0 +1,46 @@
1
+ require 'mongo_doc'
2
+
3
+ class Address
4
+ include MongoDoc::Document
5
+
6
+ attr_accessor :street
7
+ attr_accessor :city
8
+ attr_accessor :state
9
+ attr_accessor :zip_code
10
+ attr_accessor :phone_number
11
+ end
12
+
13
+ class Contact
14
+ include MongoDoc::Document
15
+
16
+ attr_accessor :name
17
+ attr_accessor :interests
18
+ embed_many :addresses
19
+
20
+ scope :in_state, lambda {|state| where('addresses.state' => state)}
21
+ end
22
+
23
+ Contact.collection.drop
24
+
25
+ contact = Contact.new(:name => 'Hashrocket', :interests => ['ruby', 'rails', 'agile'])
26
+ contact.addresses << Address.new(:street => '320 1st Street North, #712', :city => 'Jacksonville Beach', :state => 'FL', :zip_code => '32250', :phone_number => '877 885 8846')
27
+ contact.save
28
+
29
+ # Finders
30
+ Contact.find_all.each {|c| puts c.name}
31
+ puts contact.to_param
32
+ puts Contact.find_one(contact.to_param).addresses.first.street
33
+ Contact.find(contact.to_param).each {|c| puts c.name}
34
+
35
+ hashrocket_in_fl = Contact.in_state('FL').where(:name => /rocket/)
36
+
37
+ hashrocket_address = hashrocket_in_fl.first.addresses.first
38
+ hashrocket_address.update_attributes(:street => '320 First Street North, #712')
39
+
40
+ puts Contact.where(:name => 'Hashrocket').first.addresses.first.street
41
+
42
+ # Criteria behave like new AR3 AREL queries
43
+ hr = Contact.where(:name => 'Hashrocket')
44
+ hr_in = hr.where('addresses.state' => 'IN')
45
+ puts hr.count
46
+ puts hr_in.count
@@ -0,0 +1,34 @@
1
+ require 'mongo_doc'
2
+
3
+ class Contact
4
+ attr_accessor :name, :addresses, :interests
5
+ end
6
+
7
+ class Address
8
+ attr_accessor :street, :city, :state, :zip, :phone_number
9
+ end
10
+
11
+ collection = MongoDoc::Collection.new('contacts')
12
+ collection.drop
13
+
14
+ contact = Contact.new
15
+ contact.name = 'Hashrocket'
16
+ contact.interests = ['ruby', 'rails', 'agile']
17
+
18
+ address = Address.new
19
+ address.street = '320 First Street North, #712'
20
+ address.city = 'Jacksonville Beach'
21
+ address.state = 'FL'
22
+ address.zip = '32250'
23
+ address.phone_number = '877 885 8846'
24
+ contact.addresses = [address]
25
+
26
+ collection.save(contact)
27
+
28
+ in_florida = collection.where('addresses.state' => 'FL')
29
+ puts in_florida.first.addresses.first.phone_number
30
+ rocket_oid_names = collection.where('name' => /rocket/)
31
+ puts rocket_oid_names.first.addresses.first.phone_number
32
+ interested_in_ruby = collection.in('interests' => ['ruby'])
33
+ puts interested_in_ruby.first.addresses.first.phone_number
34
+
@@ -0,0 +1,9 @@
1
+ Feature: Collection with Criteria
2
+
3
+ Scenario: saving a ruby object
4
+ Given a new collection named 'test'
5
+ And an object 'movie'
6
+ When I save the object 'movie'
7
+ And I query the collection 'test' with the criteria where(:title => 'Gone with the Wind')
8
+ Then the query result has 1 documents
9
+
@@ -0,0 +1,16 @@
1
+ Feature: Embed Hash
2
+
3
+ Background:
4
+ Given a class Event
5
+
6
+ Scenario: Creating a new document
7
+ Given an Event document named 'event' :
8
+ | Name | Venue | Date |
9
+ | NoSQL Live | John Hancock Conference Center | 2010-03-11 |
10
+ And an Address document named 'address' :
11
+ | Street | City | State | Zip Code |
12
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
13
+ And I put the 'address' object on key 'office' of the 'addresses' hash of 'event'
14
+ When I save the document 'event'
15
+ Then the last return value is true
16
+ And the document 'event' roundtrips
@@ -0,0 +1,76 @@
1
+ Feature: Finders
2
+
3
+ Background:
4
+ Given an empty Contact document collection
5
+ And a Contact document named 'hashrocket' :
6
+ | Name | Type |
7
+ | Hashrocket | company |
8
+ And 'hashrocket' has interests, an array of:
9
+ | Interest |
10
+ | ruby |
11
+ | rails |
12
+ | employment |
13
+ | contract work |
14
+ | restaurants |
15
+ | hotels |
16
+ | flights |
17
+ | car rentals |
18
+ And 'hashrocket' has many addresses :
19
+ | Street | City | State | Zip Code |
20
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
21
+ | 1 Lake Michigan Street | Chicago | IL | 60611 |
22
+ | 1 Main Street | Santiago | Chile | |
23
+ And I save the document 'hashrocket'
24
+ And a Contact document named 'rocketeer' :
25
+ | Name |
26
+ | Rocketeer Mike |
27
+ And 'rocketeer' has interests, an array of:
28
+ | Interest |
29
+ | ruby |
30
+ | rails |
31
+ | restaurants |
32
+ | employment |
33
+ And 'rocketeer' has many addresses :
34
+ | Street | City | State | Zip Code |
35
+ | 1 Main Street | Atlantic Beach | FL | 32233 |
36
+ And I save the document 'rocketeer'
37
+ And a Contact document named 'contractor' :
38
+ | Name |
39
+ | Contractor Joe |
40
+ And 'contractor' has interests, an array of:
41
+ | Interest |
42
+ | ruby |
43
+ | rails |
44
+ | contract work |
45
+ | flights |
46
+ | car rentals |
47
+ | hotels |
48
+ | restaurants |
49
+ And 'contractor' has many addresses :
50
+ | Street | City | State | Zip Code |
51
+ | 1 Main St. | Jacksonville | FL | 32218 |
52
+ And I save the document 'contractor'
53
+
54
+ Scenario: All
55
+ When I query contacts with find_all
56
+ Then the query result has 3 documents
57
+
58
+ Scenario: Count
59
+ When I query contacts with count
60
+ Then the query result was 3 documents
61
+
62
+ Scenario: First
63
+ When I query contacts with first
64
+ Then the query result is the document 'hashrocket'
65
+
66
+ Scenario: Last
67
+ When I query contacts with last
68
+ Then the query result is the document 'contractor'
69
+
70
+ Scenario: Find One
71
+ When I query contacts to find_one with the id of the 'contractor' document
72
+ Then the query result is the document 'contractor'
73
+
74
+ Scenario: Find One by Param
75
+ When I query contacts to find_one with the to_param of the 'contractor' document
76
+ Then the query result is the document 'contractor'
@@ -0,0 +1,28 @@
1
+ Feature: Indexes
2
+
3
+ Background:
4
+ Given an empty Contact document collection
5
+ And a Contact document named 'hashrocket' :
6
+ | Name | Type |
7
+ | Hashrocket | company |
8
+ And 'hashrocket' has interests, an array of:
9
+ | Interest |
10
+ | ruby |
11
+ | rails |
12
+ | employment |
13
+ | contract work |
14
+ | restaurants |
15
+ | hotels |
16
+ | flights |
17
+ | car rentals |
18
+ And 'hashrocket' has many addresses :
19
+ | Street | City | State | Zip Code |
20
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
21
+ | 1 Lake Michigan Street | Chicago | IL | 60611 |
22
+ | 1 Main Street | Santiago | Chile | |
23
+ And I save the document 'hashrocket'
24
+
25
+ Scenario: Simple index
26
+ When I create an index named name on the Contact collection
27
+ Then there is an index on name on the Contact collection
28
+
@@ -0,0 +1,7 @@
1
+ cucumber:
2
+ name: cucumber
3
+ host: localhost
4
+ port: 27017
5
+ options:
6
+ auto_reconnect: true
7
+
@@ -0,0 +1,128 @@
1
+ Feature: MongoDoc::Base
2
+
3
+ Scenario: creating a simple document
4
+ Given an empty Address document collection
5
+ And a hash named 'hashrocket':
6
+ | Street | City | State | Zip Code |
7
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
8
+ When I create an Address 'address' from the hash 'hashrocket'
9
+ Then 'address' is not a new record
10
+ And the Address collection should have 1 document
11
+ And the document 'address' roundtrips
12
+
13
+ Scenario: saving a simple document
14
+ Given an empty Address document collection
15
+ And an Address document named 'hashrocket' :
16
+ | Street | City | State | Zip Code |
17
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
18
+ When I save the document 'hashrocket'
19
+ Then 'hashrocket' is not a new record
20
+ And the Address collection should have 1 document
21
+ And the document 'hashrocket' roundtrips
22
+
23
+ Scenario: updating an attribute of a simple document
24
+ Given an empty Address document collection
25
+ And an Address document named 'hashrocket' :
26
+ | Street | City | State | Zip Code |
27
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
28
+ And a hash named 'street':
29
+ | Street |
30
+ | 320 First St N |
31
+ And I save the document 'hashrocket'
32
+ When I update the document 'hashrocket' with the hash named 'street'
33
+ And the document 'hashrocket' roundtrips
34
+ Then the attribute 'street' of 'hashrocket' is '320 First St N'
35
+
36
+ Scenario: failing to update an attribute of a simple document
37
+ Given an empty Address document collection
38
+ And an Address document named 'hashrocket' :
39
+ | Street | City | State | Zip Code |
40
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
41
+ And a hash named 'street':
42
+ | Street |
43
+ | 320 First St N |
44
+ And I save the document 'hashrocket'
45
+ And I set the id on the document 'hashrocket' to 1
46
+ When I update the document 'hashrocket' with the hash named 'street'
47
+ Then the last return value is false
48
+
49
+ Scenario: saving a has_many document
50
+ Given an empty Contact document collection
51
+ And a Contact document named 'hashrocket' :
52
+ | Name |
53
+ | Hashrocket |
54
+ And 'hashrocket' has many addresses :
55
+ | Street | City | State | Zip Code |
56
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
57
+ | 1 Main Street | Santiago | Chile | |
58
+ When I save the document 'hashrocket'
59
+ Then 'hashrocket' is not a new record
60
+ And the Contact collection should have 1 document
61
+ And the document 'hashrocket' roundtrips
62
+
63
+ Scenario: saving from a child document
64
+ Given an empty Contact document collection
65
+ And a Contact document named 'hashrocket' :
66
+ | Name |
67
+ | Hashrocket |
68
+ And 'hashrocket' has many addresses :
69
+ | Street | City | State | Zip Code |
70
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
71
+ | 1 Main Street | Santiago | Chile | |
72
+ When I save the last document
73
+ Then 'hashrocket' is not a new record
74
+ And the Contact collection should have 1 document
75
+ And the document 'hashrocket' roundtrips
76
+
77
+ Scenario: Update attributes from a has_many child document
78
+ Given an empty Contact document collection
79
+ And a Contact document named 'hashrocket' :
80
+ | Name |
81
+ | Hashrocket |
82
+ And 'hashrocket' has many addresses :
83
+ | Street | City | State | Zip Code |
84
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
85
+ | 1 Main Street | Santiago | Chile | |
86
+ And I save the last document
87
+ And that @last is named 'chile'
88
+ And a hash named 'street':
89
+ | Street |
90
+ | 1a Calle |
91
+ When I update the document 'chile' with the hash named 'street'
92
+ Then the last return value is true
93
+ And the document 'hashrocket' roundtrips
94
+
95
+ Scenario: update attributes from a has_one child document
96
+ Given an empty Place document collection
97
+ And a Place document named 'hashrocket' :
98
+ | Name |
99
+ | Hashrocket |
100
+ And 'hashrocket' has one Address as address :
101
+ | Street | City | State | Zip Code |
102
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
103
+ And I save the last document
104
+ And that @last is named 'address'
105
+ And a hash named 'street':
106
+ | Street | City |
107
+ | 320 1st St. N. | Jax Bch |
108
+ When I update the document 'address' with the hash named 'street'
109
+ Then the Place collection should have 1 document
110
+ And the document 'hashrocket' roundtrips
111
+
112
+ Scenario: Class criteria
113
+ Given an empty Contact document collection
114
+ And a Contact document named 'hashrocket' :
115
+ | Name | Type |
116
+ | Hashrocket | company |
117
+ And I save the last document
118
+ When I query contacts with criteria where('type' => 'company')
119
+ Then the size of the last return value is 1
120
+
121
+ Scenario: Finder
122
+ Given an empty Contact document collection
123
+ And a Contact document named 'hashrocket' :
124
+ | Name | Type |
125
+ | Hashrocket | company |
126
+ And I save the document 'hashrocket'
127
+ When I find a contact using the id of 'hashrocket'
128
+ Then the size of the last return value is 1
@@ -0,0 +1,36 @@
1
+ Feature: New record
2
+
3
+ Scenario: saving a has_many children document
4
+ Given an empty Contact document collection
5
+ And a Contact document named 'hashrocket' :
6
+ | Name |
7
+ | Hashrocket |
8
+ And 'hashrocket' has many addresses :
9
+ | Street | City | State | Zip Code |
10
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
11
+ | 1 Main Street | Santiago | Chile | |
12
+ When I save the document 'hashrocket'
13
+ Then the first address of 'hashrocket' is not a new record
14
+
15
+ Scenario: saving a has_one child document
16
+ Given an empty Place document collection
17
+ And a Place document named 'hashrocket' :
18
+ | Name |
19
+ | Hashrocket |
20
+ And 'hashrocket' has one Address as address :
21
+ | Street | City | State | Zip Code |
22
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
23
+ When I save the document 'hashrocket'
24
+ Then the address of 'hashrocket' is not a new record
25
+
26
+ Scenario: id is roundtripped when saving a has_one child document
27
+ Given an empty Place document collection
28
+ And a Place document named 'hashrocket' :
29
+ | Name |
30
+ | Hashrocket |
31
+ And 'hashrocket' has one Address as address :
32
+ | Street | City | State | Zip Code |
33
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
34
+ When I save the document 'hashrocket'
35
+ Then the address of 'hashrocket' roundtrips
36
+
@@ -0,0 +1,95 @@
1
+ Feature: Partial Updates
2
+
3
+ Background:
4
+ Given an empty Contact document collection
5
+ And a Contact document named 'hashrocket' :
6
+ | Name | Type | Note |
7
+ | Hashrocket | company | Premier Rails development shop! |
8
+ And 'hashrocket' has interests, an array of:
9
+ | Interest |
10
+ | ruby |
11
+ | rails |
12
+ | employment |
13
+ | contract work |
14
+ | restaurants |
15
+ | hotels |
16
+ | flights |
17
+ | car rentals |
18
+ And 'hashrocket' has many addresses :
19
+ | Street | City | State | Zip Code |
20
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
21
+ | 1 Lake Michigan Street | Chicago | IL | 60611 |
22
+ | 1 Main Street | Santiago | Chile | |
23
+ And I save the document 'hashrocket'
24
+ And a Contact document named 'rocketeer' :
25
+ | Name | Note |
26
+ | Rocketeer Mike | Fantastic developer |
27
+ And 'rocketeer' has interests, an array of:
28
+ | Interest |
29
+ | ruby |
30
+ | rails |
31
+ | restaurants |
32
+ | employment |
33
+ And 'rocketeer' has many addresses :
34
+ | Street | City | State | Zip Code |
35
+ | 1 Main Street | Atlantic Beach | FL | 32233 |
36
+ And I save the document 'rocketeer'
37
+ And a Contact document named 'contractor' :
38
+ | Name | Note |
39
+ | Contractor Joe | Knows MongoDB |
40
+ And 'contractor' has interests, an array of:
41
+ | Interest |
42
+ | ruby |
43
+ | rails |
44
+ | contract work |
45
+ | flights |
46
+ | car rentals |
47
+ | hotels |
48
+ | restaurants |
49
+ And 'contractor' has many addresses :
50
+ | Street | City | State | Zip Code |
51
+ | 1 Main St. | Jacksonville | FL | 32218 |
52
+ And I save the document 'contractor'
53
+ And an empty Place document collection
54
+ And a Place document named 'hashrocket_hq' :
55
+ | Name | Type |
56
+ | Hashrocket | company |
57
+ And 'hashrocket_hq' has one Address as address (identified by 'hq_address'):
58
+ | Street | City | State | Zip Code |
59
+ | 1 Main St. | Jacksonville | FL | 32218 |
60
+ And I save the document 'hashrocket_hq'
61
+
62
+ Scenario: Update
63
+ When I update the 'note' for 'contractor' to 'Knows MongoDB and MongoDoc'
64
+ Then the last return value is true
65
+ And the document 'contractor' roundtrips
66
+
67
+ Scenario: Update on a has one
68
+ When I update the 'street' for 'hq_address' to '320 1st Street North'
69
+ Then the last return value is true
70
+ And the document 'hashrocket_hq' roundtrips
71
+
72
+ Scenario: Update on a has many
73
+ When 'hq_address' is the first address of 'hashrocket'
74
+ And I update the 'street' for 'hq_address' to '320 1st Street North'
75
+ Then the last return value is true
76
+ And the document 'hashrocket' roundtrips
77
+
78
+ Scenario: Failing Update on a has one
79
+ When someone else changes the Address 'address' of 'hashrocket_hq' to
80
+ | Street | City | State | Zip Code |
81
+ | 1 Ocean Blvd. | Jacksonville | FL | 32218 |
82
+ And I update the 'street' for 'hq_address' to '320 1st Street North'
83
+ Then the last return value is false
84
+ And the document 'hashrocket_hq' does not roundtrip
85
+
86
+ Scenario: Failing Update on a has many
87
+ When 'hq_address' is the first address of 'hashrocket'
88
+ And someone else changes the addresses of 'hashrocket':
89
+ | Street | City | State | Zip Code |
90
+ | 320 1st N, #712 | Jacksonville Beach | FL | 32250 |
91
+ | 1001 Mulligan Street | Chicago | IL | 60611 |
92
+ | 345 Avenida Grande | Santiago | Chile | |
93
+ And I update the 'street' for 'hq_address' to '320 1st Street North'
94
+ Then the last return value is false
95
+ And the document 'hashrocket' does not roundtrip