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,20 +1,7 @@
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::AttributeMethods do
17
- require 'support/models/widget'
4
+ # require 'support/models/widget'
18
5
 
19
6
  before :each do
20
7
  @widget = Widget.new
@@ -59,6 +46,13 @@ describe Ripple::AttributeMethods do
59
46
  @widget.manufactured.should == false
60
47
  end
61
48
 
49
+ it "dups the default if it is duplicable so that two document do not share the same mutable value" do
50
+ widget2 = Widget.new
51
+ @widget.name.should_not be(widget2.name)
52
+ widget2.name.gsub!("w", "f")
53
+ @widget.name.should == "widget"
54
+ end
55
+
62
56
  it "should allow raw attribute access when accessing the document with []" do
63
57
  @widget['name'].should == 'widget'
64
58
  end
@@ -81,8 +75,9 @@ describe Ripple::AttributeMethods do
81
75
  end
82
76
 
83
77
  it "should allow assignment of undefined attributes when assigning to the document with []=" do
84
- @widget['name'] = 'sprocket'
85
- @widget.name.should == 'sprocket'
78
+ @widget.should_not respond_to(:shoe_size)
79
+ @widget['shoe_size'] = 8
80
+ @widget['shoe_size'].should == 8
86
81
  end
87
82
 
88
83
  it "should type cast assigned values automatically" do
@@ -143,8 +138,28 @@ describe Ripple::AttributeMethods do
143
138
  Widget.properties.delete(:start_date) # cleanup
144
139
  end
145
140
 
146
- it "should provide a hash representation of all of the attributes" do
147
- @widget.attributes.should == {"name" => "widget", "size" => nil, "manufactured" => false, "shipped_at" => nil}
141
+ describe "#attributes" do
142
+ it "it returns a hash representation of all of the attributes" do
143
+ @widget.attributes.should == {"name" => "widget", "size" => nil, "manufactured" => false, "shipped_at" => nil}
144
+ end
145
+
146
+ it "does not include ghost attributes (attributes that do not have a defined property)" do
147
+ @widget['some_undefined_prop'] = 3.14159
148
+ @widget.attributes.should_not include('some_undefined_prop')
149
+ end
150
+ end
151
+
152
+ describe "#raw_attributes" do
153
+ it "returns a hash representation, including attributes for undefined properties" do
154
+ @widget['some_undefined_prop'] = 17
155
+ @widget.raw_attributes.should == {
156
+ 'name' => 'widget',
157
+ 'size' => nil,
158
+ 'manufactured' => false,
159
+ 'shipped_at' => nil,
160
+ 'some_undefined_prop' => 17
161
+ }
162
+ end
148
163
  end
149
164
 
150
165
  it "should load attributes from mass assignment" do
@@ -196,9 +211,20 @@ describe Ripple::AttributeMethods do
196
211
  @widget.manufactured.should be_false
197
212
  end
198
213
 
199
- it "should allow protected attributes to be mass assigned" do
214
+ it "should allow protected attributes to be mass assigned via raw_attributes=" do
200
215
  @widget = Widget.new
201
- @widget.send(:attributes=, { :manufactured => true }, false)
216
+ @widget.send(:raw_attributes=, { :manufactured => true })
202
217
  @widget.manufactured.should be_true
203
218
  end
219
+
220
+ it "should allow mass assigning arbitrary attributes via raw_attributes" do
221
+ @widget = Widget.new
222
+ @widget.__send__(:raw_attributes=, :explode => '?BOOM')
223
+ @widget[:explode].should eq('?BOOM')
224
+ end
225
+
226
+ it "should raise an ArgumentError with an undefined property message when mass assigning a property that doesn't exist" do
227
+ lambda { @widget = Widget.new(:explode => '?BOOM') }.should raise_error(ArgumentError, %q[Undefined property :explode for class 'Widget'])
228
+ end
229
+
204
230
  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.dirname(__FILE__))
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::Document::BucketAccess do
17
- require 'support/models/invoice'
18
- require 'support/models/late_invoice'
19
- require 'support/models/paid_invoice'
4
+ # require 'support/models/invoice'
5
+ # require 'support/models/late_invoice'
6
+ # require 'support/models/paid_invoice'
20
7
 
21
8
  it "should use the plural model name as the bucket name" do
22
9
  Invoice.bucket_name.should == "invoices"
@@ -1,20 +1,7 @@
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::Callbacks do
17
- require 'support/models/box'
4
+ # require 'support/models/box'
18
5
 
19
6
  it "should add create, update, save, and destroy callback declarations" do
20
7
  [:save, :create, :update, :destroy].each do |event|
@@ -49,6 +36,55 @@ describe Ripple::Callbacks do
49
36
  @box.save
50
37
  end
51
38
 
39
+ it "propagates callbacks to embedded associated documents" do
40
+ Box.before_save { $pinger.ping }
41
+ BoxSide.before_save { $pinger.ping }
42
+ $pinger.should_receive(:ping).exactly(2).times
43
+ @box = Box.new
44
+ @box.sides << BoxSide.new
45
+ @box.save
46
+ end
47
+
48
+ it 'does not persist the object to riak multiple times when propagating callbacks' do
49
+ Box.before_save { }
50
+ BoxSide.before_save { }
51
+ @box = Box.new
52
+ @box.sides << BoxSide.new << BoxSide.new
53
+
54
+ @box.robject.should_receive(:store).once
55
+ @box.save
56
+ end
57
+
58
+ it 'invokes the before/after callbacks in the correct order on embedded associated documents' do
59
+ callbacks = []
60
+ BoxSide.before_save { callbacks << :before_save }
61
+ BoxSide.after_save { callbacks << :after_save }
62
+
63
+ @box = Box.new
64
+ @box.sides << BoxSide.new
65
+ @box.robject.stub(:store) do
66
+ callbacks << :save
67
+ end
68
+ @box.save
69
+
70
+ callbacks.should == [:before_save, :save, :after_save]
71
+ end
72
+
73
+ it 'does not allow around callbacks on embedded associated documents' do
74
+ expect {
75
+ BoxSide.around_save { }
76
+ }.to raise_error(/around_save callbacks are not supported/)
77
+ end
78
+
79
+ it 'does not propagate validation callbacks multiple times' do
80
+ Box.before_validation { $pinger.ping }
81
+ BoxSide.before_validation { $pinger.ping }
82
+ $pinger.should_receive(:ping).exactly(2).times
83
+ @box = Box.new
84
+ @box.sides << BoxSide.new
85
+ @box.valid?
86
+ end
87
+
52
88
  it "should call create callbacks on save when the document is new" do
53
89
  Box.before_create { $pinger.ping }
54
90
  Box.after_create { $pinger.ping }
@@ -133,6 +169,7 @@ describe Ripple::Callbacks do
133
169
  after :each do
134
170
  [:save, :create, :update, :destroy, :validation].each do |type|
135
171
  Box.reset_callbacks(type)
172
+ BoxSide.reset_callbacks(type)
136
173
  end
137
174
  end
138
175
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Ripple
4
+ module Conflict
5
+ describe Resolver do
6
+ it 'is registered as an on conflict hook with Riak::RObject' do
7
+ Riak::RObject.on_conflict_hooks.should include(described_class.to_proc)
8
+ end
9
+
10
+ describe 'calling the lambda returned by .to_proc' do
11
+ let(:sibling_1) { stub(:data => { '_type' => 'User' } ) }
12
+ let(:sibling_2) { stub(:data => { '_type' => 'User' } ) }
13
+ let(:user_siblings) { [sibling_1, sibling_2] }
14
+ let(:wheel_sibling) { stub(:data => { '_type' => 'Wheel' } ) }
15
+ let(:robject) { stub(:siblings => user_siblings) }
16
+ let(:resolved_robject) { stub("Resolved RObject") }
17
+ let(:resolved_document) { stub(:robject => resolved_robject) }
18
+
19
+ let!(:resolver) { described_class.new(robject, User) }
20
+
21
+ it 'creates a resolver for the appropriate model class, resolves the robject, and returns the resolved robject' do
22
+ described_class.
23
+ should_receive(:new).
24
+ with(robject, User).
25
+ and_return(resolver)
26
+
27
+ resolver.should_receive(:resolve)
28
+ resolver.stub(:document => resolved_document)
29
+
30
+ described_class.to_proc.call(robject).should be(resolved_robject)
31
+ end
32
+
33
+ it 'returns nil and does not attempt resolution when given an robject with siblings of different types' do
34
+ user_siblings << wheel_sibling
35
+ described_class.should_not_receive(:new)
36
+ described_class.to_proc.call(robject).should be_nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -1,20 +1,7 @@
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::Conversion do
17
- require 'support/models/box'
4
+ # require 'support/models/box'
18
5
 
19
6
  before :each do
20
7
  @box = Box.new { |a| a.key = 'some-key' }
@@ -1,17 +1,4 @@
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 Time do
17
4
  before { @date_format = Ripple.date_format }
@@ -46,7 +33,7 @@ describe DateTime do
46
33
  after { Ripple.date_format = @date_format }
47
34
 
48
35
  before :each do
49
- Time.zone = :utc
36
+ Time.zone = "UTC"
50
37
  end
51
38
 
52
39
  it "serializes to JSON in UTC, ISO 8601 format by default" do
@@ -104,3 +91,13 @@ describe "Boolean" do
104
91
  }.should_not raise_error(NameError)
105
92
  end
106
93
  end
94
+
95
+ describe Set do
96
+ describe "#as_json" do
97
+ it 'returns an array of the #as_json result of each element' do
98
+ set = Set.new([stub(:as_json => 's1'), stub(:as_json => 's2')])
99
+ set.as_json.should =~ ['s1', 's2']
100
+ end
101
+ end
102
+ end
103
+
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ module Ripple
4
+ module Document
5
+ describe self do
6
+ describe "#to_link" do
7
+ let(:tag) { 'invoices' }
8
+ let(:document) { Invoice.new }
9
+ let(:to_link) { document.to_link(tag) }
10
+
11
+ it "returns a #{described_class}::Link" do
12
+ to_link.should be_a(Link)
13
+ end
14
+
15
+ it "sets the document to this document" do
16
+ to_link.send(:document).should equal(document)
17
+ end
18
+
19
+ it "sets the tag to the given tag" do
20
+ to_link.tag.should == tag
21
+ end
22
+ end
23
+ end
24
+
25
+ describe Link do
26
+ let(:key) { 'the-invoice-key' }
27
+ let(:tag) { 'invoices' }
28
+ let(:document) { Invoice.new { |i| i.key = key } }
29
+ let(:link) { described_class.new(document, tag) }
30
+
31
+ it 'does not fetch the key immediately' do
32
+ document.should_not_receive(:key)
33
+ link
34
+ end
35
+
36
+ describe '#key' do
37
+ it "returns the document's key" do
38
+ link.key.should == key
39
+ end
40
+ end
41
+
42
+ describe '#bucket' do
43
+ it "returns the bucket name from the document class" do
44
+ link.bucket.should == Invoice.bucket_name
45
+ end
46
+ end
47
+
48
+ describe '#tag' do
49
+ it 'returns the tag passed to the constructor' do
50
+ link.tag.should == tag
51
+ end
52
+ end
53
+
54
+ describe "#hash" do
55
+ it 'does not use the key' do
56
+ document.should_not_receive(:key)
57
+ link.hash
58
+ end
59
+
60
+ it "uses the document's #hash" do
61
+ document.should_receive(:hash).and_return(1234)
62
+ link.hash.should == 1234
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,20 +1,7 @@
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.dirname(__FILE__))
1
+ require 'spec_helper'
15
2
 
16
3
  describe Ripple::Document do
17
- require 'support/models/page'
4
+ # require 'support/models/page'
18
5
 
19
6
  it "should add bucket access methods to classes when included" do
20
7
  (class << Page; self; end).included_modules.should include(Ripple::Document::BucketAccess)
@@ -38,22 +25,50 @@ describe Ripple::Document do
38
25
  [@doc,@doc2,@sub,@error].each {|d| d.key = "root"; d.stub!(:new?).and_return(false) }
39
26
  end
40
27
 
41
- it "should be equal if the same object" do
28
+ it "should be == and eql? if the same object, and have the same hash key" do
42
29
  @doc.should == @doc
30
+ @doc.should eql(@doc)
31
+ @doc.hash.should == @doc.hash
43
32
  end
44
33
 
45
- it "should be equal if instance of same class and key" do
34
+ it "should be == and eql? and have the same hash key if instance of same class and key" do
46
35
  @doc.should == @doc2
36
+ @doc2.should == @doc
37
+ @doc.should eql(@doc2)
38
+ @doc2.should eql(@doc)
39
+ @doc.hash.should == @doc2.hash
40
+ end
41
+
42
+ it "should be == but not eql? and have different hash keys if they have the same key but one is a subclass of the other" do
47
43
  @doc.should == @sub
44
+ @sub.should == @doc
45
+
46
+ @doc.should_not eql(@sub)
47
+ @sub.should_not eql(@doc)
48
+
49
+ @doc.hash.should_not == @sub.hash
48
50
  end
49
51
 
50
- it "should be equal if of the same bucket and key" do
52
+ it "should be == but not eql? and have different hash keys if of the same bucket and key" do
51
53
  @doc.should == @error
54
+ @error.should == @doc
55
+
56
+ @doc.should_not eql(@error)
57
+ @error.should_not eql(@doc)
58
+
59
+ @doc.hash.should_not == @error.hash
60
+ @error.hash.should_not == @doc.hash
52
61
  end
53
62
 
54
- it "should not be equal if new record" do
63
+ it "should not be == or eql? or have the same hash key if new record" do
55
64
  @doc2.stub!(:new?).and_return(true)
56
65
  @doc.should_not == @doc2
66
+ @doc2.should_not == @doc
67
+
68
+ @doc.should_not eql(@doc2)
69
+ @doc2.should_not eql(@doc)
70
+
71
+ @doc.hash.should_not == @doc2.hash
57
72
  end
58
73
  end
59
74