ripple 0.9.5 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/.gitignore +32 -0
  2. data/Gemfile +10 -9
  3. data/Guardfile +15 -0
  4. data/Rakefile +11 -40
  5. data/lib/rails/generators/ripple/configuration/configuration_generator.rb +0 -13
  6. data/lib/rails/generators/ripple/configuration/templates/ripple.yml +4 -4
  7. data/lib/rails/generators/ripple/js/js_generator.rb +0 -13
  8. data/lib/rails/generators/ripple/js/templates/js/contrib.js +0 -17
  9. data/lib/rails/generators/ripple/js/templates/js/ripple.js +0 -13
  10. data/lib/rails/generators/ripple/model/model_generator.rb +0 -14
  11. data/lib/rails/generators/ripple/model/templates/model.rb +1 -1
  12. data/lib/rails/generators/ripple/observer/observer_generator.rb +0 -14
  13. data/lib/rails/generators/ripple/test/test_generator.rb +7 -19
  14. data/lib/rails/generators/ripple_generator.rb +1 -14
  15. data/lib/ripple.rb +7 -14
  16. data/lib/ripple/associations.rb +129 -26
  17. data/lib/ripple/associations/embedded.rb +1 -15
  18. data/lib/ripple/associations/instantiators.rb +0 -13
  19. data/lib/ripple/associations/linked.rb +41 -19
  20. data/lib/ripple/associations/many.rb +0 -14
  21. data/lib/ripple/associations/many_embedded_proxy.rb +0 -14
  22. data/lib/ripple/associations/many_linked_proxy.rb +39 -18
  23. data/lib/ripple/associations/many_reference_proxy.rb +93 -0
  24. data/lib/ripple/associations/many_stored_key_proxy.rb +76 -0
  25. data/lib/ripple/associations/one.rb +1 -15
  26. data/lib/ripple/associations/one_embedded_proxy.rb +0 -14
  27. data/lib/ripple/associations/one_key_proxy.rb +58 -0
  28. data/lib/ripple/associations/one_linked_proxy.rb +4 -14
  29. data/lib/ripple/associations/one_stored_key_proxy.rb +43 -0
  30. data/lib/ripple/associations/proxy.rb +8 -14
  31. data/lib/ripple/attribute_methods.rb +19 -17
  32. data/lib/ripple/attribute_methods/dirty.rb +19 -15
  33. data/lib/ripple/attribute_methods/query.rb +0 -14
  34. data/lib/ripple/attribute_methods/read.rb +0 -14
  35. data/lib/ripple/attribute_methods/write.rb +0 -14
  36. data/lib/ripple/callbacks.rb +10 -16
  37. data/lib/ripple/conflict/basic_resolver.rb +82 -0
  38. data/lib/ripple/conflict/document_hooks.rb +20 -0
  39. data/lib/ripple/conflict/resolver.rb +71 -0
  40. data/lib/ripple/conflict/test_helper.rb +33 -0
  41. data/lib/ripple/conversion.rb +0 -14
  42. data/lib/ripple/core_ext.rb +1 -14
  43. data/lib/ripple/core_ext/casting.rb +19 -19
  44. data/lib/ripple/core_ext/object.rb +8 -0
  45. data/lib/ripple/document.rb +21 -16
  46. data/lib/ripple/document/bucket_access.rb +0 -14
  47. data/lib/ripple/document/finders.rb +17 -23
  48. data/lib/ripple/document/key.rb +8 -28
  49. data/lib/ripple/document/link.rb +30 -0
  50. data/lib/ripple/document/persistence.rb +12 -20
  51. data/lib/ripple/embedded_document.rb +10 -15
  52. data/lib/ripple/embedded_document/around_callbacks.rb +18 -0
  53. data/lib/ripple/embedded_document/finders.rb +7 -18
  54. data/lib/ripple/embedded_document/persistence.rb +5 -17
  55. data/lib/ripple/i18n.rb +0 -14
  56. data/lib/ripple/inspection.rb +21 -15
  57. data/lib/ripple/locale/en.yml +9 -13
  58. data/lib/ripple/nested_attributes.rb +33 -39
  59. data/lib/ripple/observable.rb +0 -13
  60. data/lib/ripple/properties.rb +1 -14
  61. data/lib/ripple/property_type_mismatch.rb +0 -14
  62. data/lib/ripple/railtie.rb +4 -14
  63. data/lib/ripple/railties/ripple.rake +86 -0
  64. data/lib/ripple/serialization.rb +11 -11
  65. data/lib/ripple/test_server.rb +36 -0
  66. data/lib/ripple/timestamps.rb +0 -13
  67. data/lib/ripple/translation.rb +4 -14
  68. data/lib/ripple/validations.rb +1 -15
  69. data/lib/ripple/validations/associated_validator.rb +26 -17
  70. data/lib/ripple/version.rb +3 -0
  71. data/ripple.gemspec +24 -35
  72. data/spec/integration/ripple/associations_spec.rb +89 -58
  73. data/spec/integration/ripple/conflict_resolution_spec.rb +298 -0
  74. data/spec/integration/ripple/nested_attributes_spec.rb +19 -19
  75. data/spec/integration/ripple/persistence_spec.rb +15 -34
  76. data/spec/integration/ripple/search_associations_spec.rb +31 -0
  77. data/spec/ripple/associations/many_embedded_proxy_spec.rb +23 -36
  78. data/spec/ripple/associations/many_linked_proxy_spec.rb +133 -45
  79. data/spec/ripple/associations/many_reference_proxy_spec.rb +170 -0
  80. data/spec/ripple/associations/many_stored_key_proxy_spec.rb +158 -0
  81. data/spec/ripple/associations/one_embedded_proxy_spec.rb +24 -37
  82. data/spec/ripple/associations/one_key_proxy_spec.rb +82 -0
  83. data/spec/ripple/associations/one_linked_proxy_spec.rb +22 -23
  84. data/spec/ripple/associations/one_stored_key_proxy_spec.rb +72 -0
  85. data/spec/ripple/associations/proxy_spec.rb +21 -15
  86. data/spec/ripple/associations_spec.rb +54 -23
  87. data/spec/ripple/attribute_methods/dirty_spec.rb +56 -5
  88. data/spec/ripple/attribute_methods_spec.rb +47 -21
  89. data/spec/ripple/bucket_access_spec.rb +4 -17
  90. data/spec/ripple/callbacks_spec.rb +52 -15
  91. data/spec/ripple/conflict/resolver_spec.rb +42 -0
  92. data/spec/ripple/conversion_spec.rb +2 -15
  93. data/spec/ripple/core_ext_spec.rb +12 -15
  94. data/spec/ripple/document/link_spec.rb +67 -0
  95. data/spec/ripple/document_spec.rb +34 -19
  96. data/spec/ripple/embedded_document/finders_spec.rb +12 -19
  97. data/spec/ripple/embedded_document/persistence_spec.rb +20 -26
  98. data/spec/ripple/embedded_document_spec.rb +44 -34
  99. data/spec/ripple/finders_spec.rb +58 -29
  100. data/spec/ripple/inspection_spec.rb +40 -37
  101. data/spec/ripple/key_spec.rb +5 -17
  102. data/spec/ripple/observable_spec.rb +3 -16
  103. data/spec/ripple/persistence_spec.rb +134 -18
  104. data/spec/ripple/properties_spec.rb +21 -15
  105. data/spec/ripple/ripple_spec.rb +1 -14
  106. data/spec/ripple/serialization_spec.rb +16 -17
  107. data/spec/ripple/timestamps_spec.rb +73 -52
  108. data/spec/ripple/validations/associated_validator_spec.rb +69 -25
  109. data/spec/ripple/validations_spec.rb +3 -16
  110. data/spec/spec_helper.rb +17 -18
  111. data/spec/support/associations.rb +1 -1
  112. data/spec/support/associations/proxies.rb +0 -13
  113. data/spec/support/integration_setup.rb +11 -0
  114. data/spec/support/mocks.rb +0 -13
  115. data/spec/support/models.rb +33 -2
  116. data/spec/support/models/address.rb +1 -16
  117. data/spec/support/models/box.rb +7 -14
  118. data/spec/support/models/car.rb +27 -1
  119. data/spec/support/models/cardboard_box.rb +0 -14
  120. data/spec/support/models/clock.rb +6 -15
  121. data/spec/support/models/clock_observer.rb +0 -14
  122. data/spec/support/models/credit_card.rb +5 -0
  123. data/spec/support/models/customer.rb +0 -14
  124. data/spec/support/models/email.rb +0 -14
  125. data/spec/support/models/family.rb +1 -13
  126. data/spec/support/models/favorite.rb +0 -14
  127. data/spec/support/models/invoice.rb +0 -14
  128. data/spec/support/models/late_invoice.rb +0 -14
  129. data/spec/support/models/nested.rb +12 -0
  130. data/spec/support/models/ninja.rb +7 -0
  131. data/spec/support/models/note.rb +0 -14
  132. data/spec/support/models/page.rb +1 -15
  133. data/spec/support/models/paid_invoice.rb +0 -14
  134. data/spec/support/models/post.rb +12 -0
  135. data/spec/support/models/profile.rb +7 -0
  136. data/spec/support/models/subscription.rb +26 -0
  137. data/spec/support/models/tasks.rb +0 -18
  138. data/spec/support/models/team.rb +11 -0
  139. data/spec/support/models/transactions.rb +17 -0
  140. data/spec/support/models/tree.rb +2 -16
  141. data/spec/support/models/user.rb +14 -16
  142. data/spec/support/models/widget.rb +8 -14
  143. data/spec/support/search.rb +14 -0
  144. data/spec/support/test_server.rb +22 -12
  145. data/spec/support/test_server.yml.example +14 -2
  146. metadata +223 -59
  147. data/lib/rails/generators/ripple/test/templates/test_server.rb +0 -46
  148. data/spec/support/models/driver.rb +0 -5
  149. data/spec/support/models/engine.rb +0 -4
  150. data/spec/support/models/passenger.rb +0 -5
  151. data/spec/support/models/seat.rb +0 -4
  152. data/spec/support/models/wheel.rb +0 -5
@@ -1,36 +1,29 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../../../spec_helper", __FILE__)
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::EmbeddedDocument::Finders do
17
- require 'support/models/address'
18
- require 'support/models/favorite'
4
+ # require 'support/models/address'
5
+ # require 'support/models/favorite'
19
6
 
20
7
  before :each do
21
- @addr = Address.new
8
+ @address = Address.new
22
9
  end
23
10
 
24
11
  it "should instantiate a document" do
25
12
  Address.stub!(:new).and_return(@address)
26
13
  Address.instantiate('_type' => 'Address').should == @address
27
14
  end
28
-
15
+
29
16
  it "should instantiate a class of _type if present in attrs" do
30
17
  Favorite.instantiate('_type' => 'Address').class.should == Address
31
18
  end
32
-
19
+
33
20
  it "should use self if being called from a class including Ripple::EmbeddedDocument and _type is not present" do
34
21
  Address.instantiate({}).class.should == Address
35
22
  end
23
+
24
+ it 'initializes the document with no changes' do
25
+ a = Address.instantiate('_type' => 'Address', 'street' => 'Pine St')
26
+ a.should_not be_changed
27
+ a.changes.should be_empty
28
+ end
36
29
  end
@@ -1,25 +1,12 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../../../spec_helper", __FILE__)
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::EmbeddedDocument::Persistence do
17
- require 'support/models/user'
18
- require 'support/models/address'
19
-
4
+ # require 'support/models/user'
5
+ # require 'support/models/address'
6
+
20
7
  before :each do
21
8
  @root = User.new
22
- @addr = Address.new(:street => "196 Broadway")
9
+ @addr = Address.new(:street => "196 Broadway", :kind => "Home")
23
10
  @addr._parent_document = @root
24
11
  end
25
12
 
@@ -32,17 +19,17 @@ describe Ripple::EmbeddedDocument::Persistence do
32
19
  @root.should_receive(:save).and_return(true)
33
20
  @addr.save.should be_true
34
21
  end
35
-
22
+
36
23
  it "should delegate save! to the root document" do
37
24
  @root.should_receive(:save).and_return(true)
38
25
  @addr.save!.should be_true
39
26
  end
40
-
27
+
41
28
  it "should raise NoRootDocument when calling save without a root document" do
42
29
  @addr._parent_document = nil
43
30
  lambda { @addr.save }.should raise_error(Ripple::NoRootDocument)
44
31
  end
45
-
32
+
46
33
  it "should raise NoRootDocument when calling save! without a root document" do
47
34
  @addr._parent_document = nil
48
35
  lambda { @addr.save! }.should raise_error(Ripple::NoRootDocument)
@@ -51,25 +38,32 @@ describe Ripple::EmbeddedDocument::Persistence do
51
38
  it "should have a root document" do
52
39
  @addr._root_document.should == @root
53
40
  end
54
-
41
+
55
42
  it "should have a parent document" do
56
43
  @addr._parent_document.should == @root
57
44
  end
58
-
45
+
59
46
  it "should respond to new_record?" do
60
47
  @addr.should respond_to(:new_record?)
61
48
  @addr.should be_a_new_record
62
49
  end
63
-
50
+
64
51
  it "should respond to persisted" do
65
52
  @addr.should respond_to(:persisted?)
66
53
  @addr.should_not be_persisted
67
54
  end
68
-
55
+
69
56
  it "should properly create embedded attributes for persistence" do
70
57
  @addr = Address.new
71
58
  @root.addresses << @addr
72
- @root.attributes_for_persistence.should == {'_type' => 'User', 'addresses' => [{'_type' => 'Address', 'street' => nil}]}
59
+ @root.attributes_for_persistence.should == {'_type' => 'User', 'email' => nil, 'addresses' => [{'_type' => 'Address', 'street' => nil, 'kind' => nil}]}
60
+ end
61
+
62
+ it "includes undefined properties in the attributes for persistence" do
63
+ addr = Address.new
64
+ addr['some_undefined_prop'] = 17
65
+ @root.addresses << addr
66
+ @root.attributes_for_persistence['addresses'].first.should include('some_undefined_prop' => 17)
73
67
  end
74
68
 
75
69
  it "should modify its attributes and save" do
@@ -1,21 +1,8 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../../spec_helper", __FILE__)
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::EmbeddedDocument do
17
- require 'support/models/address'
18
- require 'support/models/user'
4
+ # require 'support/models/address'
5
+ # require 'support/models/user'
19
6
 
20
7
  it "should have a model name when included" do
21
8
  Address.should respond_to(:model_name)
@@ -26,9 +13,9 @@ describe Ripple::EmbeddedDocument do
26
13
  Address.should be_embeddable
27
14
  end
28
15
 
29
- describe "#==" do
30
- let(:user_1) { User.create! }
31
- let(:user_2) { User.create! }
16
+ describe "equality" do
17
+ let(:user_1) { User.new {|u| u.key = "u1"} }
18
+ let(:user_2) { User.new {|u| u.key = "u2"} }
32
19
  let(:street_1) { '123 Somewhere St' }
33
20
  let(:street_2) { '123 Somewhere Ave' }
34
21
  let(:address_1) { Address.new(:street => street_1) }
@@ -39,36 +26,59 @@ describe Ripple::EmbeddedDocument do
39
26
  address_2._parent_document = user_1
40
27
  end
41
28
 
42
- it "returns true when the documents have the same classes, parents and attributes" do
29
+ def should_be_equal
43
30
  (address_1 == address_2).should be_true
31
+ address_1.eql?(address_2).should be_true
32
+
44
33
  (address_2 == address_1).should be_true
34
+ address_2.eql?(address_1).should be_true
35
+
36
+ address_1.hash.should == address_2.hash
45
37
  end
46
38
 
47
- it "returns true when the documents match and only one of them includes the _type attribute" do
48
- attrs = address_1.attributes
49
- address_1.stub(:attributes => attrs.merge('_type' => 'Address'))
39
+ def should_not_be_equal(other_address = address_2)
40
+ (address_1 == other_address).should be_false
41
+ address_1.eql?(other_address).should be_false
50
42
 
51
- (address_1 == address_2).should be_true
52
- (address_2 == address_1).should be_true
43
+ (other_address == address_1).should be_false
44
+ address_1.eql?(other_address).should be_false
45
+
46
+ address_1.hash.should_not == other_address.hash
47
+ end
48
+
49
+ specify "two document are equal when they have the same classes, parents and attributes" do
50
+ should_be_equal
53
51
  end
54
52
 
55
- it "returns false when the parents are different (even if the attributes and classes are the same)" do
53
+ specify "two documents are not equal when the parents are different (even if the attributes and classes are the same)" do
56
54
  address_2._parent_document = user_2
57
- (address_1 == address_2).should be_false
58
- (address_2 == address_1).should be_false
55
+ should_not_be_equal
59
56
  end
60
57
 
61
- it "returns false when the attributes are different (even if the parents and classes are the same)" do
58
+ specify "two documents are not equal when the attributes are different (even if the parents and classes are the same)" do
62
59
  address_2.street = street_2
63
- (address_1 == address_2).should be_false
64
- (address_2 == address_1).should be_false
60
+ should_not_be_equal
65
61
  end
66
62
 
67
- it "returns false then the classes are different (even if the parents and attributes are the same)" do
63
+ specify "two documents are not equal when the classes are different (even if the parents and attributes are the same)" do
68
64
  special_address = SpecialAddress.new(address_1.attributes)
69
65
  special_address._parent_document = address_1._parent_document
70
- (address_1 == special_address).should be_false
71
- (special_address == address_1).should be_false
66
+
67
+ should_not_be_equal(special_address)
68
+ end
69
+
70
+ specify "two documents are not equal when their embedded documents are not equal (even if they are identical otherwise)" do
71
+ address_1.notes << Note.new(:text => 'Bob lives here')
72
+ address_2.notes << Note.new(:text => 'Jill lives here')
73
+
74
+ should_not_be_equal
75
+ end
76
+
77
+ specify "two documents can be equal when their embedded doc objects are different instances but are equal" do
78
+ address_1.notes << Note.new(:text => 'Bob lives here')
79
+ address_2.notes << Note.new(:text => 'Bob lives here')
80
+
81
+ should_be_equal
72
82
  end
73
83
  end
74
84
  end
@@ -1,22 +1,9 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../../spec_helper", __FILE__)
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::Document::Finders do
17
- require 'support/models/box'
18
- require 'support/models/cardboard_box'
19
-
4
+ # require 'support/models/box'
5
+ # require 'support/models/cardboard_box'
6
+
20
7
  before :each do
21
8
  @backend = mock("Backend")
22
9
  @client = Ripple.client
@@ -34,7 +21,7 @@ describe Ripple::Document::Finders do
34
21
  Box.find(nil).should be_nil
35
22
  Box.find("").should be_nil
36
23
  end
37
-
24
+
38
25
  it "should raise Ripple::DocumentNotFound if an empty array is passed to find!" do
39
26
  lambda { Box.find!() }.should raise_error(Ripple::DocumentNotFound, "Couldn't find document without a key")
40
27
  end
@@ -43,7 +30,7 @@ describe Ripple::Document::Finders do
43
30
  before do
44
31
  @bucket.stub!(:get).with("square", {}).and_return(@plain)
45
32
  end
46
-
33
+
47
34
  it "should find a single document by key and assign its attributes" do
48
35
  @bucket.should_receive(:get).with("square", {}).and_return(@plain)
49
36
  box = Box.find("square")
@@ -54,6 +41,11 @@ describe Ripple::Document::Finders do
54
41
  box.should_not be_new_record
55
42
  end
56
43
 
44
+ it "should have no changes after find" do
45
+ box = Box.find("square")
46
+ box.changes.should == {}
47
+ end
48
+
57
49
  it "should find the first document using the first key with the bucket's keys" do
58
50
  box = Box.new
59
51
  keys = ['some_boxes_key']
@@ -110,9 +102,15 @@ describe Ripple::Document::Finders do
110
102
  box.should be_kind_of(Box)
111
103
  box.key.should == "square"
112
104
  end
105
+
106
+ it 'initializes the document with no changed attributes' do
107
+ box = Box.find("square")
108
+ box.should_not be_changed
109
+ box.changes.should be_empty
110
+ end
113
111
  end
114
112
 
115
- describe "finding multiple documents" do
113
+ describe "finding multiple documents when given a splat of keys" do
116
114
  it "should find multiple documents by the keys" do
117
115
  @bucket.should_receive(:get).with("square", {}).and_return(@plain)
118
116
  @bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
@@ -141,12 +139,48 @@ describe Ripple::Document::Finders do
141
139
  end
142
140
  end
143
141
 
144
- describe "finding all documents in the bucket" do
142
+ describe "finding multiple documents when given an array" do
143
+ it "should find multiple documents by the keys" do
144
+ @bucket.should_receive(:get).with("square", {}).and_return(@plain)
145
+ @bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
146
+ boxes = Box.find(["square", "rectangle"])
147
+ boxes.should have(2).items
148
+ boxes.first.shape.should == "square"
149
+ boxes.last.shape.should == "rectangle"
150
+ end
151
+
152
+ it "should return an array of docs when given an array of one key" do
153
+ @bucket.should_receive(:get).with("square", {}).and_return(@plain)
154
+ boxes = Box.find(["square"])
155
+ boxes.should have(1).items
156
+ boxes.first.shape.should == "square"
157
+ end
158
+
159
+ it "should return an empty array when given an empty array" do
160
+ Box.find([ ]).should == []
161
+ end
162
+
163
+ describe "when using find with missing keys" do
164
+ before :each do
165
+ @bucket.should_receive(:get).with("square", {}).and_return(@plain)
166
+ @bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, "404 not found"))
167
+ end
168
+
169
+ it "should return nil for documents that no longer exist" do
170
+ boxes = Box.find(["square", "rectangle"])
171
+ boxes.should have(2).items
172
+ boxes.first.shape.should == "square"
173
+ boxes.last.should be_nil
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "listings all documents in the bucket" do
145
179
  it "should load all objects in the bucket" do
146
180
  @bucket.should_receive(:keys).and_return(["square", "rectangle"])
147
181
  @bucket.should_receive(:get).with("square", {}).and_return(@plain)
148
182
  @bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
149
- boxes = Box.all
183
+ boxes = Box.list
150
184
  boxes.should have(2).items
151
185
  boxes.first.shape.should == "square"
152
186
  boxes.last.shape.should == "rectangle"
@@ -156,7 +190,7 @@ describe Ripple::Document::Finders do
156
190
  @bucket.should_receive(:keys).and_return(["square", "rectangle"])
157
191
  @bucket.should_receive(:get).with("square", {}).and_return(@plain)
158
192
  @bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, "404 not found"))
159
- boxes = Box.all
193
+ boxes = Box.list
160
194
  boxes.should have(1).item
161
195
  boxes.first.shape.should == "square"
162
196
  end
@@ -167,16 +201,11 @@ describe Ripple::Document::Finders do
167
201
  @bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, "404 not found"))
168
202
  @block = mock()
169
203
  @block.should_receive(:ping).once
170
- Box.all do |box|
204
+ Box.list do |box|
171
205
  @block.ping
172
206
  ["square", "rectangle"].should include(box.shape)
173
207
  end.should == []
174
208
  end
175
-
176
- it "should pass any given options to the underlying Bucket#keys method" do
177
- @bucket.should_receive(:keys).with(:reload => true).and_return([])
178
- Box.all(:reload => true).should == []
179
- end
180
209
  end
181
210
 
182
211
  describe "single-bucket inheritance" do
@@ -1,48 +1,51 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../../spec_helper", __FILE__)
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::Inspection do
17
- require 'support/models/box'
18
- require 'support/models/address'
4
+ # require 'support/models/box'
5
+ # require 'support/models/address'
6
+
7
+ shared_examples_for 'an inspected document' do |method|
8
+
9
+ it "should include the class name in the inspect string" do
10
+ @box.send(method).should be_starts_with("<Box")
11
+ end
12
+
13
+ it "should include the key in the #{method} string for documents" do
14
+ @box.key = "square"
15
+ @box.send(method).should be_starts_with("<Box:square")
16
+ end
17
+
18
+ it "should indicate a new document when no key is specified" do
19
+ @box.send(method).should be_starts_with("<Box:[new]")
20
+ end
21
+
22
+ it "should not display a key for embedded documents" do
23
+ @address.send(method).should_not include("[new]")
24
+ end
25
+
26
+ end
19
27
 
20
28
  before :each do
21
29
  @box = Box.new
22
30
  @address = Address.new
23
31
  end
24
-
25
- it "should include the class name in the inspect string" do
26
- @box.inspect.should be_starts_with("<Box")
27
- end
28
-
29
- it "should include the key in the inspect string for documents" do
30
- @box.key = "square"
31
- @box.inspect.should be_starts_with("<Box:square")
32
- end
33
-
34
- it "should indicate a new document when no key is specified" do
35
- @box.inspect.should be_starts_with("<Box:[new]")
36
- end
37
32
 
38
- it "should enumerate the document's properties and their values" do
39
- @box.shape = "square"
40
- @box.inspect.should include("shape=\"square\"")
41
- @box.inspect.should include("created_at=")
42
- @box.inspect.should include("updated_at=")
33
+ describe '#inspect' do
34
+
35
+ it_should_behave_like 'an inspected document', :inspect
36
+
37
+ it "should enumerate the document's properties and their values" do
38
+ @box.shape = "square"
39
+ @box.inspect.should include("shape=\"square\"")
40
+ @box.inspect.should include("created_at=")
41
+ @box.inspect.should include("updated_at=")
42
+ end
43
+
43
44
  end
44
-
45
- it "should not display a key for embedded documents" do
46
- @address.inspect.should_not include("[new]")
45
+
46
+ describe '#to_s' do
47
+
48
+ it_should_behave_like 'an inspected document', :to_s
49
+
47
50
  end
48
51
  end