ripple 0.8.3 → 0.9.0.beta
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.
- data/Rakefile +3 -3
- data/lib/ripple.rb +1 -0
- data/lib/ripple/document.rb +1 -0
- data/lib/ripple/document/bucket_access.rb +1 -1
- data/ripple.gemspec +6 -6
- data/spec/ripple/callbacks_spec.rb +5 -5
- data/spec/ripple/embedded_document/finders_spec.rb +0 -1
- data/spec/ripple/finders_spec.rb +29 -37
- data/spec/ripple/persistence_spec.rb +52 -16
- data/spec/ripple/timestamps_spec.rb +3 -4
- data/spec/ripple/validations_spec.rb +3 -2
- data/spec/spec_helper.rb +1 -1
- metadata +22 -11
data/Rakefile
CHANGED
@@ -156,18 +156,18 @@ require 'rspec/core'
|
|
156
156
|
require 'rspec/core/rake_task'
|
157
157
|
|
158
158
|
desc "Run Unit Specs Only"
|
159
|
-
|
159
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
160
160
|
spec.pattern = "spec/ripple/**/*_spec.rb"
|
161
161
|
end
|
162
162
|
|
163
163
|
namespace :spec do
|
164
164
|
desc "Run Integration Specs Only"
|
165
|
-
|
165
|
+
RSpec::Core::RakeTask.new(:integration) do |spec|
|
166
166
|
spec.pattern = "spec/integration/**/*_spec.rb"
|
167
167
|
end
|
168
168
|
|
169
169
|
desc "Run All Specs"
|
170
|
-
|
170
|
+
RSpec::Core::RakeTask.new(:all) do |spec|
|
171
171
|
spec.pattern = "spec/**/*_spec.rb"
|
172
172
|
end
|
173
173
|
end
|
data/lib/ripple.rb
CHANGED
data/lib/ripple/document.rb
CHANGED
data/ripple.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ripple}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.9.0.beta"
|
6
6
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sean Cribbs"]
|
9
|
-
s.date = %q{2010-12-
|
9
|
+
s.date = %q{2010-12-29}
|
10
10
|
s.description = %q{ripple is an object-mapper library for Riak, the distributed database by Basho. It uses ActiveModel to provide an experience that integrates well with Rails 3 applications.}
|
11
11
|
s.email = %q{sean@basho.com}
|
12
12
|
s.files = ["Gemfile", "lib/rails/generators/ripple/configuration/configuration_generator.rb", "lib/rails/generators/ripple/configuration/templates/ripple.yml", "lib/rails/generators/ripple/js/js_generator.rb", "lib/rails/generators/ripple/js/templates/js/contrib.js", "lib/rails/generators/ripple/js/templates/js/ripple.js", "lib/rails/generators/ripple/model/model_generator.rb", "lib/rails/generators/ripple/model/templates/model.rb", "lib/rails/generators/ripple/test/templates/test_server.rb", "lib/rails/generators/ripple/test/test_generator.rb", "lib/rails/generators/ripple_generator.rb", "lib/ripple/associations/embedded.rb", "lib/ripple/associations/instantiators.rb", "lib/ripple/associations/linked.rb", "lib/ripple/associations/many.rb", "lib/ripple/associations/many_embedded_proxy.rb", "lib/ripple/associations/many_linked_proxy.rb", "lib/ripple/associations/one.rb", "lib/ripple/associations/one_embedded_proxy.rb", "lib/ripple/associations/one_linked_proxy.rb", "lib/ripple/associations/proxy.rb", "lib/ripple/associations.rb", "lib/ripple/attribute_methods/dirty.rb", "lib/ripple/attribute_methods/query.rb", "lib/ripple/attribute_methods/read.rb", "lib/ripple/attribute_methods/write.rb", "lib/ripple/attribute_methods.rb", "lib/ripple/callbacks.rb", "lib/ripple/conversion.rb", "lib/ripple/core_ext/casting.rb", "lib/ripple/core_ext.rb", "lib/ripple/document/bucket_access.rb", "lib/ripple/document/finders.rb", "lib/ripple/document/key.rb", "lib/ripple/document/persistence.rb", "lib/ripple/document.rb", "lib/ripple/embedded_document/finders.rb", "lib/ripple/embedded_document/persistence.rb", "lib/ripple/embedded_document.rb", "lib/ripple/i18n.rb", "lib/ripple/inspection.rb", "lib/ripple/locale/en.yml", "lib/ripple/nested_attributes.rb", "lib/ripple/properties.rb", "lib/ripple/property_type_mismatch.rb", "lib/ripple/railtie.rb", "lib/ripple/timestamps.rb", "lib/ripple/translation.rb", "lib/ripple/validations/associated_validator.rb", "lib/ripple/validations.rb", "lib/ripple.rb", "Rakefile", "ripple.gemspec", "spec/fixtures/config.yml", "spec/integration/ripple/associations_spec.rb", "spec/integration/ripple/nested_attributes_spec.rb", "spec/integration/ripple/persistence_spec.rb", "spec/ripple/associations/many_embedded_proxy_spec.rb", "spec/ripple/associations/many_linked_proxy_spec.rb", "spec/ripple/associations/one_embedded_proxy_spec.rb", "spec/ripple/associations/one_linked_proxy_spec.rb", "spec/ripple/associations/proxy_spec.rb", "spec/ripple/associations_spec.rb", "spec/ripple/attribute_methods_spec.rb", "spec/ripple/bucket_access_spec.rb", "spec/ripple/callbacks_spec.rb", "spec/ripple/conversion_spec.rb", "spec/ripple/core_ext_spec.rb", "spec/ripple/document_spec.rb", "spec/ripple/embedded_document/finders_spec.rb", "spec/ripple/embedded_document/persistence_spec.rb", "spec/ripple/embedded_document_spec.rb", "spec/ripple/finders_spec.rb", "spec/ripple/inspection_spec.rb", "spec/ripple/key_spec.rb", "spec/ripple/persistence_spec.rb", "spec/ripple/properties_spec.rb", "spec/ripple/ripple_spec.rb", "spec/ripple/timestamps_spec.rb", "spec/ripple/validations_spec.rb", "spec/spec_helper.rb", "spec/support/associations/proxies.rb", "spec/support/mocks.rb", "spec/support/models/address.rb", "spec/support/models/box.rb", "spec/support/models/car.rb", "spec/support/models/cardboard_box.rb", "spec/support/models/clock.rb", "spec/support/models/customer.rb", "spec/support/models/driver.rb", "spec/support/models/email.rb", "spec/support/models/engine.rb", "spec/support/models/family.rb", "spec/support/models/favorite.rb", "spec/support/models/invoice.rb", "spec/support/models/late_invoice.rb", "spec/support/models/note.rb", "spec/support/models/page.rb", "spec/support/models/paid_invoice.rb", "spec/support/models/passenger.rb", "spec/support/models/seat.rb", "spec/support/models/tasks.rb", "spec/support/models/tree.rb", "spec/support/models/user.rb", "spec/support/models/wheel.rb", "spec/support/models/widget.rb", "spec/support/test_server.rb", "spec/support/test_server.yml.example"]
|
@@ -22,18 +22,18 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
24
24
|
s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
|
25
|
-
s.add_runtime_dependency(%q<riak-client>, ["~> 0.
|
25
|
+
s.add_runtime_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
|
26
26
|
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
|
27
27
|
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0.0"])
|
28
28
|
else
|
29
29
|
s.add_dependency(%q<rspec>, ["~> 2.0.0"])
|
30
|
-
s.add_dependency(%q<riak-client>, ["~> 0.
|
30
|
+
s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
|
31
31
|
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
32
32
|
s.add_dependency(%q<activemodel>, ["~> 3.0.0"])
|
33
33
|
end
|
34
34
|
else
|
35
35
|
s.add_dependency(%q<rspec>, ["~> 2.0.0"])
|
36
|
-
s.add_dependency(%q<riak-client>, ["~> 0.
|
36
|
+
s.add_dependency(%q<riak-client>, ["~> 0.9.0.beta"])
|
37
37
|
s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
|
38
38
|
s.add_dependency(%q<activemodel>, ["~> 3.0.0"])
|
39
39
|
end
|
@@ -35,8 +35,8 @@ describe Ripple::Callbacks do
|
|
35
35
|
before :each do
|
36
36
|
response = {:headers => {"content-type" => ["application/json"]}, :body => "{}"}
|
37
37
|
@client = Ripple.client
|
38
|
-
@
|
39
|
-
@client.stub!(:
|
38
|
+
@backend = mock("Backend", :store_object => true)
|
39
|
+
@client.stub!(:backend).and_return(@backend)
|
40
40
|
$pinger = mock("callback verifier")
|
41
41
|
end
|
42
42
|
|
@@ -76,7 +76,7 @@ describe Ripple::Callbacks do
|
|
76
76
|
@box = Box.new
|
77
77
|
@box.destroy
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
describe "validation callbacks" do
|
81
81
|
it "should call validation callbacks" do
|
82
82
|
Box.before_validation { $pinger.ping }
|
@@ -85,7 +85,7 @@ describe Ripple::Callbacks do
|
|
85
85
|
@box = Box.new
|
86
86
|
@box.valid?
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should call validation callbacks only if the document is new" do
|
90
90
|
Box.before_validation(:on => :create) { $pinger.ping }
|
91
91
|
Box.after_validation(:on => :create) { $pinger.ping }
|
@@ -101,7 +101,7 @@ describe Ripple::Callbacks do
|
|
101
101
|
@box = Box.new
|
102
102
|
@box.valid?
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should call validation callbacks only if the document is not new" do
|
106
106
|
Box.before_validation(:on => :update) { $pinger.ping }
|
107
107
|
Box.after_validation(:on => :update) { $pinger.ping }
|
data/spec/ripple/finders_spec.rb
CHANGED
@@ -18,11 +18,12 @@ describe Ripple::Document::Finders do
|
|
18
18
|
require 'support/models/cardboard_box'
|
19
19
|
|
20
20
|
before :each do
|
21
|
-
@
|
21
|
+
@backend = mock("Backend")
|
22
22
|
@client = Ripple.client
|
23
|
-
@client.stub!(:
|
24
|
-
@bucket =
|
25
|
-
|
23
|
+
@client.stub!(:backend).and_return(@backend)
|
24
|
+
@bucket = Ripple.client.bucket("boxes")
|
25
|
+
@plain = Riak::RObject.new(@bucket, "square"){|o| o.content_type = "application/json"; o.raw_data = '{"shape":"square"}'}
|
26
|
+
@cb = Riak::RObject.new(@bucket, "rectangle"){|o| o.content_type = "application/json"; o.raw_data = '{"shape":"rectangle"}'}
|
26
27
|
end
|
27
28
|
|
28
29
|
it "should return nil if no keys are passed to find" do
|
@@ -39,8 +40,12 @@ describe Ripple::Document::Finders do
|
|
39
40
|
end
|
40
41
|
|
41
42
|
describe "finding single documents" do
|
43
|
+
before do
|
44
|
+
@bucket.stub!(:get).with("square", {}).and_return(@plain)
|
45
|
+
end
|
46
|
+
|
42
47
|
it "should find a single document by key and assign its attributes" do
|
43
|
-
@
|
48
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
44
49
|
box = Box.find("square")
|
45
50
|
box.should be_kind_of(Box)
|
46
51
|
box.shape.should == "square"
|
@@ -67,50 +72,48 @@ describe Ripple::Document::Finders do
|
|
67
72
|
end
|
68
73
|
|
69
74
|
it "should not raise an exception when finding an existing document with find!" do
|
70
|
-
@http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
|
71
75
|
lambda { Box.find!("square") }.should_not raise_error(Ripple::DocumentNotFound)
|
72
76
|
end
|
73
77
|
|
74
78
|
it "should raise an exception when finding an existing document that has properties we don't know about" do
|
75
|
-
@
|
79
|
+
@plain.raw_data = '{"non_existent_property":"whatever"}'
|
76
80
|
lambda { Box.find("square") }.should raise_error
|
77
81
|
end
|
78
82
|
|
79
83
|
it "should return the document when calling find!" do
|
80
|
-
@http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
|
81
84
|
box = Box.find!("square")
|
82
85
|
box.should be_kind_of(Box)
|
83
86
|
end
|
84
87
|
|
85
88
|
it "should return nil when no object exists at that key" do
|
86
|
-
@
|
89
|
+
@bucket.should_receive(:get).with("square", {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
|
87
90
|
box = Box.find("square")
|
88
91
|
box.should be_nil
|
89
92
|
end
|
90
93
|
|
91
94
|
it "should raise DocumentNotFound when using find! if no object exists at that key" do
|
92
|
-
@
|
95
|
+
@bucket.should_receive(:get).with("square", {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
|
93
96
|
lambda { Box.find!("square") }.should raise_error(Ripple::DocumentNotFound, "Couldn't find document with key: square")
|
94
97
|
end
|
95
98
|
|
96
99
|
it "should re-raise the failed request exception if not a 404" do
|
97
|
-
@
|
100
|
+
@bucket.should_receive(:get).with("square", {}).and_raise(Riak::FailedRequest.new(:get, 200, 500, {}, "500 internal server error"))
|
98
101
|
lambda { Box.find("square") }.should raise_error(Riak::FailedRequest)
|
99
102
|
end
|
100
103
|
|
101
104
|
it "should handle a key with a nil value" do
|
102
|
-
@
|
105
|
+
@plain.raw_data = nil
|
106
|
+
@plain.data = nil
|
103
107
|
box = Box.find("square")
|
104
108
|
box.should be_kind_of(Box)
|
105
109
|
box.key.should == "square"
|
106
110
|
end
|
107
|
-
|
108
111
|
end
|
109
112
|
|
110
113
|
describe "finding multiple documents" do
|
111
114
|
it "should find multiple documents by the keys" do
|
112
|
-
@
|
113
|
-
@
|
115
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
116
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
|
114
117
|
boxes = Box.find("square", "rectangle")
|
115
118
|
boxes.should have(2).items
|
116
119
|
boxes.first.shape.should == "square"
|
@@ -119,8 +122,8 @@ describe Ripple::Document::Finders do
|
|
119
122
|
|
120
123
|
describe "when using find with missing keys" do
|
121
124
|
before :each do
|
122
|
-
@
|
123
|
-
@
|
125
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
126
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
|
124
127
|
end
|
125
128
|
|
126
129
|
it "should return nil for documents that no longer exist" do
|
@@ -139,8 +142,8 @@ describe Ripple::Document::Finders do
|
|
139
142
|
describe "finding all documents in the bucket" do
|
140
143
|
it "should load all objects in the bucket" do
|
141
144
|
@bucket.should_receive(:keys).and_return(["square", "rectangle"])
|
142
|
-
@
|
143
|
-
@
|
145
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
146
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
|
144
147
|
boxes = Box.all
|
145
148
|
boxes.should have(2).items
|
146
149
|
boxes.first.shape.should == "square"
|
@@ -149,29 +152,17 @@ describe Ripple::Document::Finders do
|
|
149
152
|
|
150
153
|
it "should exclude objects that are not found" do
|
151
154
|
@bucket.should_receive(:keys).and_return(["square", "rectangle"])
|
152
|
-
@
|
153
|
-
@
|
155
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
156
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
|
154
157
|
boxes = Box.all
|
155
158
|
boxes.should have(1).item
|
156
159
|
boxes.first.shape.should == "square"
|
157
160
|
end
|
158
161
|
|
159
|
-
it "should yield found objects to the passed block and return an empty array" do
|
160
|
-
@bucket.should_receive(:keys).and_yield(["square"]).and_yield(["rectangle"])
|
161
|
-
@http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
|
162
|
-
@http.should_receive(:get).with(200, "/riak/", "boxes", "rectangle", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"rectangle"}'})
|
163
|
-
@block = mock()
|
164
|
-
@block.should_receive(:ping).twice
|
165
|
-
Box.all do |box|
|
166
|
-
@block.ping
|
167
|
-
["square", "rectangle"].should include(box.shape)
|
168
|
-
end.should == []
|
169
|
-
end
|
170
|
-
|
171
162
|
it "should yield found objects to the passed block, excluding missing objects, and return an empty array" do
|
172
163
|
@bucket.should_receive(:keys).and_yield(["square"]).and_yield(["rectangle"])
|
173
|
-
@
|
174
|
-
@
|
164
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
165
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
|
175
166
|
@block = mock()
|
176
167
|
@block.should_receive(:ping).once
|
177
168
|
Box.all do |box|
|
@@ -183,8 +174,9 @@ describe Ripple::Document::Finders do
|
|
183
174
|
|
184
175
|
describe "single-bucket inheritance" do
|
185
176
|
it "should instantiate as the proper type if defined in the document" do
|
186
|
-
@
|
187
|
-
@
|
177
|
+
@cb.raw_data = '{"shape":"rectangle", "_type":"CardboardBox"}'
|
178
|
+
@bucket.should_receive(:get).with("square", {}).and_return(@plain)
|
179
|
+
@bucket.should_receive(:get).with("rectangle", {}).and_return(@cb)
|
188
180
|
boxes = Box.find("square", "rectangle")
|
189
181
|
boxes.should have(2).items
|
190
182
|
boxes.first.class.should == Box
|
@@ -17,17 +17,21 @@ describe Ripple::Document::Persistence do
|
|
17
17
|
require 'support/models/widget'
|
18
18
|
|
19
19
|
before :each do
|
20
|
-
@
|
20
|
+
@backend = mock("Backend")
|
21
21
|
@client = Ripple.client
|
22
|
-
@client.stub!(:
|
23
|
-
@bucket =
|
24
|
-
@client.stub!(:[]).and_return(@bucket)
|
22
|
+
@client.stub!(:backend).and_return(@backend)
|
23
|
+
@bucket = Ripple.client.bucket("widgets")
|
25
24
|
@widget = Widget.new(:size => 1000)
|
26
25
|
end
|
27
26
|
|
28
27
|
it "should save a new object to Riak" do
|
29
28
|
json = @widget.attributes.merge("_type" => "Widget").to_json
|
30
|
-
@
|
29
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
30
|
+
obj.raw_data.should == json
|
31
|
+
obj.key.should be_nil
|
32
|
+
# Simulate loading the response with the key
|
33
|
+
obj.key = "new_widget"
|
34
|
+
end
|
31
35
|
@widget.save
|
32
36
|
@widget.key.should == "new_widget"
|
33
37
|
@widget.should_not be_a_new_record
|
@@ -36,7 +40,12 @@ describe Ripple::Document::Persistence do
|
|
36
40
|
|
37
41
|
it "should modify attributes and save a new object" do
|
38
42
|
json = @widget.attributes.merge("_type" => "Widget", "size" => 5).to_json
|
39
|
-
@
|
43
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
44
|
+
obj.raw_data.should == json
|
45
|
+
obj.key.should be_nil
|
46
|
+
# Simulate loading the response with the key
|
47
|
+
obj.key = "new_widget"
|
48
|
+
end
|
40
49
|
@widget.update_attributes(:size => 5)
|
41
50
|
@widget.key.should == "new_widget"
|
42
51
|
@widget.should_not be_a_new_record
|
@@ -45,7 +54,12 @@ describe Ripple::Document::Persistence do
|
|
45
54
|
|
46
55
|
it "should modify a single attribute and save a new object" do
|
47
56
|
json = @widget.attributes.merge("_type" => "Widget", "size" => 5).to_json
|
48
|
-
@
|
57
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
58
|
+
obj.raw_data.should == json
|
59
|
+
obj.key.should be_nil
|
60
|
+
# Simulate loading the response with the key
|
61
|
+
obj.key = "new_widget"
|
62
|
+
end
|
49
63
|
@widget.update_attribute(:size, 5)
|
50
64
|
@widget.key.should == "new_widget"
|
51
65
|
@widget.should_not be_a_new_record
|
@@ -55,7 +69,12 @@ describe Ripple::Document::Persistence do
|
|
55
69
|
|
56
70
|
it "should instantiate and save a new object to riak" do
|
57
71
|
json = @widget.attributes.merge(:size => 10, :shipped_at => "Sat, 01 Jan 2000 20:15:01 -0000", :_type => 'Widget').to_json
|
58
|
-
@
|
72
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
73
|
+
obj.raw_data.should == json
|
74
|
+
obj.key.should be_nil
|
75
|
+
# Simulate loading the response with the key
|
76
|
+
obj.key = "new_widget"
|
77
|
+
end
|
59
78
|
@widget = Widget.create(:size => 10, :shipped_at => Time.utc(2000,"jan",1,20,15,1))
|
60
79
|
@widget.size.should == 10
|
61
80
|
@widget.shipped_at.should == Time.utc(2000,"jan",1,20,15,1)
|
@@ -64,7 +83,12 @@ describe Ripple::Document::Persistence do
|
|
64
83
|
|
65
84
|
it "should instantiate and save a new object to riak and allow its attributes to be set via a block" do
|
66
85
|
json = @widget.attributes.merge(:size => 10, :_type => 'Widget').to_json
|
67
|
-
@
|
86
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
87
|
+
obj.raw_data.should == json
|
88
|
+
obj.key.should be_nil
|
89
|
+
# Simulate loading the response with the key
|
90
|
+
obj.key = "new_widget"
|
91
|
+
end
|
68
92
|
@widget = Widget.create do |widget|
|
69
93
|
widget.size = 10
|
70
94
|
end
|
@@ -74,9 +98,17 @@ describe Ripple::Document::Persistence do
|
|
74
98
|
|
75
99
|
it "should reload a saved object" do
|
76
100
|
json = @widget.attributes.merge(:_type => "Widget").to_json
|
77
|
-
@
|
101
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
102
|
+
obj.raw_data.should == json
|
103
|
+
obj.key.should be_nil
|
104
|
+
# Simulate loading the response with the key
|
105
|
+
obj.key = "new_widget"
|
106
|
+
end
|
78
107
|
@widget.save
|
79
|
-
@
|
108
|
+
@backend.should_receive(:reload_object) do |obj, _|
|
109
|
+
obj.key.should == "new_widget"
|
110
|
+
obj.raw_data = '{"name":"spring","size":10,"shipped_at":"Sat, 01 Jan 2000 20:15:01 -0000","_type":"Widget"}'
|
111
|
+
end
|
80
112
|
@widget.reload
|
81
113
|
@widget.changes.should be_blank
|
82
114
|
@widget.name.should == "spring"
|
@@ -85,9 +117,11 @@ describe Ripple::Document::Persistence do
|
|
85
117
|
end
|
86
118
|
|
87
119
|
it "should destroy a saved object" do
|
88
|
-
@
|
120
|
+
@backend.should_receive(:store_object).and_return(true)
|
121
|
+
@widget.key = "foo"
|
89
122
|
@widget.save
|
90
|
-
@
|
123
|
+
@widget.should_not be_new
|
124
|
+
@backend.should_receive(:delete_object).and_return(true)
|
91
125
|
@widget.destroy.should be_true
|
92
126
|
@widget.should be_frozen
|
93
127
|
end
|
@@ -99,7 +133,7 @@ describe Ripple::Document::Persistence do
|
|
99
133
|
end
|
100
134
|
|
101
135
|
it "should freeze an unsaved object when destroying" do
|
102
|
-
@
|
136
|
+
@backend.should_not_receive(:delete_object)
|
103
137
|
@widget.destroy.should be_true
|
104
138
|
@widget.should be_frozen
|
105
139
|
end
|
@@ -115,11 +149,13 @@ describe Ripple::Document::Persistence do
|
|
115
149
|
|
116
150
|
it "should store the _type field as the class name" do
|
117
151
|
json = @cog.attributes.merge("_type" => "Cog").to_json
|
118
|
-
@
|
152
|
+
@backend.should_receive(:store_object) do |obj, _, _, _|
|
153
|
+
obj.raw_data.should == json
|
154
|
+
obj.key = "new_widget"
|
155
|
+
end
|
119
156
|
@cog.save
|
120
157
|
@cog.should_not be_new_record
|
121
158
|
end
|
122
|
-
|
123
159
|
end
|
124
160
|
|
125
161
|
describe "modifying the default quorum values" do
|
@@ -20,8 +20,8 @@ describe Ripple::Timestamps do
|
|
20
20
|
before :each do
|
21
21
|
response = {:headers => {"content-type" => ["application/json"]}, :body => "{}"}
|
22
22
|
@client = Ripple.client
|
23
|
-
@
|
24
|
-
@client.stub!(:
|
23
|
+
@backend = mock("Backend", :store_object => true)
|
24
|
+
@client.stub!(:backend).and_return(@backend)
|
25
25
|
@clock = Clock.new
|
26
26
|
end
|
27
27
|
|
@@ -51,6 +51,5 @@ describe Ripple::Timestamps do
|
|
51
51
|
start = @clock.updated_at
|
52
52
|
@clock.save
|
53
53
|
@clock.updated_at.should > start
|
54
|
-
end
|
55
|
-
|
54
|
+
end
|
56
55
|
end
|
@@ -18,6 +18,8 @@ describe Ripple::Validations do
|
|
18
18
|
|
19
19
|
before :each do
|
20
20
|
@box = Box.new
|
21
|
+
@client = Ripple.client
|
22
|
+
@client.stub!(:backend).and_return(mock("Backend", :store_object => true))
|
21
23
|
end
|
22
24
|
|
23
25
|
it "should add validation declarations to the class" do
|
@@ -103,6 +105,5 @@ describe Ripple::Validations do
|
|
103
105
|
|
104
106
|
after :each do
|
105
107
|
Box.reset_callbacks(:validate)
|
106
|
-
end
|
107
|
-
|
108
|
+
end
|
108
109
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31098121
|
5
|
+
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
version: 0.9.0.beta
|
10
12
|
platform: ruby
|
11
13
|
authors:
|
12
14
|
- Sean Cribbs
|
@@ -14,7 +16,7 @@ autorequire:
|
|
14
16
|
bindir: bin
|
15
17
|
cert_chain: []
|
16
18
|
|
17
|
-
date: 2010-12-
|
19
|
+
date: 2010-12-29 00:00:00 -06:00
|
18
20
|
default_executable:
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +27,7 @@ dependencies:
|
|
25
27
|
requirements:
|
26
28
|
- - ~>
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 15
|
28
31
|
segments:
|
29
32
|
- 2
|
30
33
|
- 0
|
@@ -40,11 +43,13 @@ dependencies:
|
|
40
43
|
requirements:
|
41
44
|
- - ~>
|
42
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 31098121
|
43
47
|
segments:
|
44
48
|
- 0
|
45
|
-
-
|
46
|
-
-
|
47
|
-
|
49
|
+
- 9
|
50
|
+
- 0
|
51
|
+
- beta
|
52
|
+
version: 0.9.0.beta
|
48
53
|
type: :runtime
|
49
54
|
version_requirements: *id002
|
50
55
|
- !ruby/object:Gem::Dependency
|
@@ -55,6 +60,7 @@ dependencies:
|
|
55
60
|
requirements:
|
56
61
|
- - ~>
|
57
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 7
|
58
64
|
segments:
|
59
65
|
- 3
|
60
66
|
- 0
|
@@ -70,6 +76,7 @@ dependencies:
|
|
70
76
|
requirements:
|
71
77
|
- - ~>
|
72
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 7
|
73
80
|
segments:
|
74
81
|
- 3
|
75
82
|
- 0
|
@@ -208,17 +215,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
215
|
requirements:
|
209
216
|
- - ">="
|
210
217
|
- !ruby/object:Gem::Version
|
218
|
+
hash: 3
|
211
219
|
segments:
|
212
220
|
- 0
|
213
221
|
version: "0"
|
214
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
223
|
none: false
|
216
224
|
requirements:
|
217
|
-
- - "
|
225
|
+
- - ">"
|
218
226
|
- !ruby/object:Gem::Version
|
227
|
+
hash: 25
|
219
228
|
segments:
|
220
|
-
-
|
221
|
-
|
229
|
+
- 1
|
230
|
+
- 3
|
231
|
+
- 1
|
232
|
+
version: 1.3.1
|
222
233
|
requirements: []
|
223
234
|
|
224
235
|
rubyforge_project:
|