ripple 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/Rakefile +61 -48
  2. data/lib/ripple.rb +5 -1
  3. data/lib/ripple/core_ext/casting.rb +3 -0
  4. data/lib/ripple/document.rb +6 -2
  5. data/lib/ripple/document/associations.rb +154 -0
  6. data/lib/ripple/document/{persistence/callbacks.rb → associations/embedded.rb} +20 -24
  7. data/lib/ripple/document/associations/instantiators.rb +41 -0
  8. data/lib/{riak/util/translation.rb → ripple/document/associations/linked.rb} +14 -11
  9. data/lib/ripple/document/associations/many.rb +52 -0
  10. data/lib/ripple/document/associations/many_embedded_proxy.rb +49 -0
  11. data/lib/{riak/i18n.rb → ripple/document/associations/one.rb} +18 -2
  12. data/lib/ripple/document/associations/one_embedded_proxy.rb +41 -0
  13. data/lib/ripple/document/associations/proxy.rb +125 -0
  14. data/lib/ripple/document/attribute_methods.rb +8 -1
  15. data/lib/ripple/document/attribute_methods/read.rb +4 -0
  16. data/lib/ripple/document/attribute_methods/write.rb +4 -0
  17. data/lib/ripple/document/bucket_access.rb +1 -1
  18. data/lib/ripple/document/callbacks.rb +75 -0
  19. data/lib/ripple/document/finders.rb +50 -3
  20. data/lib/ripple/document/persistence.rb +14 -6
  21. data/lib/ripple/document/validations.rb +35 -7
  22. data/lib/ripple/document/validations/associated_validator.rb +37 -0
  23. data/lib/ripple/embedded_document.rb +8 -2
  24. data/lib/{riak/map_reduce_error.rb → ripple/embedded_document/conversion.rb} +19 -5
  25. data/lib/{riak/invalid_response.rb → ripple/embedded_document/finders.rb} +17 -8
  26. data/lib/ripple/embedded_document/persistence.rb +75 -13
  27. data/lib/ripple/locale/en.yml +7 -1
  28. data/{spec/riak/net_http_backend_spec.rb → lib/ripple/railtie.rb} +17 -13
  29. data/spec/fixtures/config.yml +3 -0
  30. data/spec/integration/ripple/associations_spec.rb +81 -0
  31. data/spec/integration/ripple/persistence_spec.rb +54 -0
  32. data/spec/ripple/associations/many_embedded_proxy_spec.rb +124 -0
  33. data/spec/ripple/associations/one_embedded_proxy_spec.rb +130 -0
  34. data/spec/ripple/associations/proxy_spec.rb +78 -0
  35. data/spec/ripple/associations_spec.rb +111 -0
  36. data/spec/ripple/attribute_methods_spec.rb +37 -16
  37. data/spec/ripple/bucket_access_spec.rb +3 -14
  38. data/spec/ripple/callbacks_spec.rb +53 -9
  39. data/spec/ripple/document_spec.rb +22 -6
  40. data/spec/ripple/embedded_document/conversion_spec.rb +35 -0
  41. data/spec/{riak/headers_spec.rb → ripple/embedded_document/finders_spec.rb} +17 -14
  42. data/spec/ripple/embedded_document/persistence_spec.rb +86 -0
  43. data/spec/ripple/embedded_document_spec.rb +1 -26
  44. data/spec/ripple/finders_spec.rb +66 -30
  45. data/spec/ripple/persistence_spec.rb +33 -21
  46. data/spec/ripple/properties_spec.rb +1 -7
  47. data/spec/ripple/ripple_spec.rb +10 -0
  48. data/spec/ripple/timestamps_spec.rb +12 -19
  49. data/spec/ripple/validations_spec.rb +48 -6
  50. data/spec/spec_helper.rb +4 -10
  51. data/spec/support/associations/proxies.rb +16 -0
  52. data/spec/support/integration.rb +4 -0
  53. data/spec/support/mocks.rb +3 -0
  54. data/spec/support/models/address.rb +8 -0
  55. data/spec/support/models/box.rb +6 -0
  56. data/spec/support/models/cardboard_box.rb +3 -0
  57. data/spec/support/models/clock.rb +6 -0
  58. data/spec/support/models/customer.rb +4 -0
  59. data/spec/support/models/email.rb +4 -0
  60. data/spec/support/models/family.rb +14 -0
  61. data/spec/support/models/favorite.rb +4 -0
  62. data/spec/support/models/invoice.rb +6 -0
  63. data/spec/support/models/late_invoice.rb +3 -0
  64. data/spec/support/models/note.rb +4 -0
  65. data/spec/support/models/page.rb +4 -0
  66. data/spec/support/models/paid_invoice.rb +4 -0
  67. data/spec/support/models/tree.rb +3 -0
  68. data/spec/support/models/user.rb +6 -0
  69. data/spec/support/models/widget.rb +6 -0
  70. metadata +111 -138
  71. data/.document +0 -5
  72. data/.gitignore +0 -26
  73. data/CONTRIBUTORS.textile +0 -5
  74. data/LICENSE +0 -13
  75. data/README.textile +0 -128
  76. data/RELEASE_NOTES.textile +0 -68
  77. data/VERSION +0 -1
  78. data/lib/riak.rb +0 -46
  79. data/lib/riak/bucket.rb +0 -157
  80. data/lib/riak/client.rb +0 -139
  81. data/lib/riak/client/curb_backend.rb +0 -82
  82. data/lib/riak/client/http_backend.rb +0 -209
  83. data/lib/riak/client/net_http_backend.rb +0 -49
  84. data/lib/riak/failed_request.rb +0 -37
  85. data/lib/riak/link.rb +0 -73
  86. data/lib/riak/locale/en.yml +0 -37
  87. data/lib/riak/map_reduce.rb +0 -248
  88. data/lib/riak/robject.rb +0 -258
  89. data/lib/riak/util/escape.rb +0 -12
  90. data/lib/riak/util/fiber1.8.rb +0 -48
  91. data/lib/riak/util/headers.rb +0 -44
  92. data/lib/riak/util/multipart.rb +0 -52
  93. data/lib/riak/walk_spec.rb +0 -117
  94. data/ripple.gemspec +0 -169
  95. data/spec/fixtures/cat.jpg +0 -0
  96. data/spec/fixtures/multipart-blank.txt +0 -7
  97. data/spec/fixtures/multipart-with-body.txt +0 -16
  98. data/spec/riak/bucket_spec.rb +0 -230
  99. data/spec/riak/client_spec.rb +0 -174
  100. data/spec/riak/curb_backend_spec.rb +0 -50
  101. data/spec/riak/escape_spec.rb +0 -17
  102. data/spec/riak/http_backend_spec.rb +0 -131
  103. data/spec/riak/link_spec.rb +0 -82
  104. data/spec/riak/map_reduce_spec.rb +0 -352
  105. data/spec/riak/multipart_spec.rb +0 -36
  106. data/spec/riak/object_spec.rb +0 -532
  107. data/spec/riak/walk_spec_spec.rb +0 -208
  108. data/spec/spec.opts +0 -1
  109. data/spec/support/http_backend_implementation_examples.rb +0 -215
  110. data/spec/support/mock_server.rb +0 -58
@@ -14,9 +14,7 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::EmbeddedDocument do
17
- before :all do
18
- Object.module_eval { class Address; include Ripple::EmbeddedDocument; end }
19
- end
17
+ require 'support/models/address'
20
18
 
21
19
  it "should have a model name when included" do
22
20
  Address.should respond_to(:model_name)
@@ -26,27 +24,4 @@ describe Ripple::EmbeddedDocument do
26
24
  it "should be embeddable" do
27
25
  Address.should be_embeddable
28
26
  end
29
-
30
- describe "persistence" do
31
- before :each do
32
- @root = mock("root document")
33
- @root.stub!(:new?).and_return(true)
34
- @addr = Address.new
35
- @addr._root_document = @root
36
- end
37
-
38
- it "should delegate new? to the root document" do
39
- @root.should_receive(:new?).and_return(true)
40
- @addr.should be_new
41
- end
42
-
43
- it "should delegate save to the root document" do
44
- @root.should_receive(:save).and_return(true)
45
- @addr.save.should be_true
46
- end
47
- end
48
-
49
- after :all do
50
- Object.send(:remove_const, :Address)
51
- end
52
27
  end
@@ -14,15 +14,9 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::Document::Finders do
17
- before :all do
18
- Object.module_eval do
19
- class Box
20
- include Ripple::Document
21
- property :shape, String
22
- end
23
- end
24
- end
25
-
17
+ require 'support/models/box'
18
+ require 'support/models/cardboard_box'
19
+
26
20
  before :each do
27
21
  @http = mock("HTTP Backend")
28
22
  @client = Ripple.client
@@ -32,7 +26,11 @@ describe Ripple::Document::Finders do
32
26
  end
33
27
 
34
28
  it "should return an empty array if no keys are passed to find" do
35
- Box.find().should == []
29
+ Box.find().should be_nil
30
+ end
31
+
32
+ it "should raise Ripple::DocumentNotFound if an empty array is passed to find!" do
33
+ lambda { Box.find!() }.should raise_error(Ripple::DocumentNotFound, "Couldn't find document without a key")
36
34
  end
37
35
 
38
36
  describe "finding single documents" do
@@ -46,16 +44,57 @@ describe Ripple::Document::Finders do
46
44
  box.should_not be_new_record
47
45
  end
48
46
 
47
+ it "should find the first document using the first key with the bucket's keys" do
48
+ box = Box.new
49
+ keys = ['some_boxes_key']
50
+ Box.stub!(:find).and_return(box)
51
+ @bucket.stub!(:keys).and_return(keys)
52
+ @bucket.should_receive(:keys)
53
+ keys.should_receive(:first)
54
+ Box.first.should == box
55
+ end
56
+
57
+ it "should use find! when using first!" do
58
+ box = Box.new
59
+ Box.stub!(:find!).and_return(box)
60
+ @bucket.stub!(:keys).and_return(['key'])
61
+ Box.first!.should == box
62
+ end
63
+
64
+ it "should not raise an exception when finding an existing document with find!" do
65
+ @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
66
+ lambda { Box.find!("square") }.should_not raise_error(Ripple::DocumentNotFound)
67
+ end
68
+
69
+ it "should return the document when calling 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
+ box = Box.find!("square")
72
+ box.should be_kind_of(Box)
73
+ end
74
+
49
75
  it "should return nil when no object exists at that key" do
50
76
  @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
51
77
  box = Box.find("square")
52
78
  box.should be_nil
53
79
  end
54
80
 
81
+ it "should raise DocumentNotFound when using find! if no object exists at that key" do
82
+ @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
83
+ lambda { Box.find!("square") }.should raise_error(Ripple::DocumentNotFound, "Couldn't find document with key: square")
84
+ end
85
+
55
86
  it "should re-raise the failed request exception if not a 404" do
56
87
  @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 500, {}, "500 internal server error"))
57
88
  lambda { Box.find("square") }.should raise_error(Riak::FailedRequest)
58
89
  end
90
+
91
+ it "should handle a key with a nil value" do
92
+ @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => nil})
93
+ box = Box.find("square")
94
+ box.should be_kind_of(Box)
95
+ box.key.should == "square"
96
+ end
97
+
59
98
  end
60
99
 
61
100
  describe "finding multiple documents" do
@@ -68,13 +107,22 @@ describe Ripple::Document::Finders do
68
107
  boxes.last.shape.should == "rectangle"
69
108
  end
70
109
 
71
- it "should return nil for documents that no longer exist" do
72
- @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
73
- @http.should_receive(:get).with(200, "/riak/", "boxes", "rectangle", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
74
- boxes = Box.find("square", "rectangle")
75
- boxes.should have(2).items
76
- boxes.first.shape.should == "square"
77
- boxes.last.should be_nil
110
+ describe "when using find with missing keys" do
111
+ before :each do
112
+ @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
113
+ @http.should_receive(:get).with(200, "/riak/", "boxes", "rectangle", {}, {}).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "404 not found"))
114
+ end
115
+
116
+ it "should return nil for documents that no longer exist" do
117
+ boxes = Box.find("square", "rectangle")
118
+ boxes.should have(2).items
119
+ boxes.first.shape.should == "square"
120
+ boxes.last.should be_nil
121
+ end
122
+
123
+ it "should raise Ripple::DocumentNotFound when calling find! if some of the documents do not exist" do
124
+ lambda { Box.find!("square", "rectangle") }.should raise_error(Ripple::DocumentNotFound, "Couldn't find documents with keys: rectangle")
125
+ end
78
126
  end
79
127
  end
80
128
 
@@ -124,25 +172,13 @@ describe Ripple::Document::Finders do
124
172
  end
125
173
 
126
174
  describe "single-bucket inheritance" do
127
- before :all do
128
- Object.module_eval { class CardboardBox < Box; end }
129
- end
130
-
131
175
  it "should instantiate as the proper type if defined in the document" do
132
176
  @http.should_receive(:get).with(200, "/riak/", "boxes", "square", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"square"}'})
133
177
  @http.should_receive(:get).with(200, "/riak/", "boxes", "rectangle", {}, {}).and_return({:code => 200, :headers => {"content-type" => ["application/json"]}, :body => '{"shape":"rectangle", "_type":"CardboardBox"}'})
134
178
  boxes = Box.find("square", "rectangle")
135
179
  boxes.should have(2).items
136
- boxes.first.should_not be_kind_of(CardboardBox)
180
+ boxes.first.class.should == Box
137
181
  boxes.last.should be_kind_of(CardboardBox)
138
182
  end
139
-
140
- after :all do
141
- Object.send(:remove_const, :CardboardBox)
142
- end
143
- end
144
-
145
- after :all do
146
- Object.send(:remove_const, :Box)
147
183
  end
148
184
  end
@@ -14,15 +14,7 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::Document::Persistence do
17
- before :all do
18
- Object.module_eval {
19
- class Widget
20
- include Ripple::Document
21
- property :size, Integer
22
- property :name, String, :default => "widget"
23
- end
24
- }
25
- end
17
+ require 'support/models/widget'
26
18
 
27
19
  before :each do
28
20
  @http = mock("HTTP Backend")
@@ -38,9 +30,27 @@ describe Ripple::Document::Persistence do
38
30
  @http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
39
31
  @widget.save
40
32
  @widget.key.should == "new_widget"
41
- @widget.should_not be_new_record
33
+ @widget.should_not be_a_new_record
42
34
  @widget.changes.should be_blank
43
35
  end
36
+
37
+ it "should instantiate and save a new object to riak" do
38
+ json = @widget.attributes.merge(:size => 10, :_type => 'Widget').to_json
39
+ @http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
40
+ @widget = Widget.create(:size => 10)
41
+ @widget.size.should == 10
42
+ @widget.should_not be_a_new_record
43
+ end
44
+
45
+ it "should instantiate and save a new object to riak and allow its attributes to be set via a block" do
46
+ json = @widget.attributes.merge(:size => 10, :_type => 'Widget').to_json
47
+ @http.should_receive(:post).with(201, "/riak/", "widgets", an_instance_of(Hash), json, hash_including("Content-Type" => "application/json")).and_return(:code => 201, :headers => {'location' => ["/riak/widgets/new_widget"]})
48
+ @widget = Widget.create do |widget|
49
+ widget.size = 10
50
+ end
51
+ @widget.size.should == 10
52
+ @widget.should_not be_a_new_record
53
+ end
44
54
 
45
55
  it "should reload a saved object" do
46
56
  json = @widget.attributes.merge("_type" => "Widget").to_json
@@ -61,17 +71,26 @@ describe Ripple::Document::Persistence do
61
71
  @widget.should be_frozen
62
72
  end
63
73
 
74
+ it "should destroy all saved objects" do
75
+ @widget.should_receive(:destroy).and_return(true)
76
+ Widget.should_receive(:all).and_yield(@widget)
77
+ Widget.destroy_all.should be_true
78
+ end
79
+
64
80
  it "should freeze an unsaved object when destroying" do
65
81
  @http.should_not_receive(:delete)
66
82
  @widget.destroy.should be_true
67
83
  @widget.should be_frozen
68
84
  end
85
+
86
+ it "should be a root document" do
87
+ @widget._root_document.should == @widget
88
+ end
69
89
 
70
90
  describe "when storing a class using single-bucket inheritance" do
71
- before :all do
72
- Object.module_eval { class Cog < Widget; property :name, String, :default => "cog"; end }
73
- end
74
-
91
+
92
+ class Cog < Widget; property :name, String, :default => "cog"; end
93
+
75
94
  before :each do
76
95
  @cog = Cog.new(:size => 1000)
77
96
  end
@@ -83,12 +102,5 @@ describe Ripple::Document::Persistence do
83
102
  @cog.should_not be_new_record
84
103
  end
85
104
 
86
- after :all do
87
- Object.send(:remove_const, :Cog)
88
- end
89
- end
90
-
91
- after :all do
92
- Object.send(:remove_const, :Widget)
93
105
  end
94
106
  end
@@ -14,9 +14,7 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::Document::Properties do
17
- before :all do
18
- Object.module_eval { class Email; include Ripple::Document; end }
19
- end
17
+ require 'support/models/email'
20
18
 
21
19
  it "should make the model class have a property definition method" do
22
20
  Email.should respond_to(:property)
@@ -38,10 +36,6 @@ describe Ripple::Document::Properties do
38
36
  Forward.properties[:foo].should == "bar"
39
37
  end
40
38
 
41
-
42
- after :all do
43
- Object.send(:remove_const, :Email)
44
- end
45
39
  end
46
40
 
47
41
  describe Ripple::Document::Property do
@@ -41,4 +41,14 @@ describe Ripple do
41
41
  Ripple.client.should_not == c
42
42
  Ripple.client.port.should == 9000
43
43
  end
44
+
45
+ it "should raise No Such File or Directory when given a bad configuration file" do
46
+ lambda { Ripple.load_config('not-here') }.should raise_error(Errno::ENOENT)
47
+ end
48
+
49
+ it "should apply the configuration under the ripple key" do
50
+ Ripple.load_config(File.join(File.dirname(__FILE__), '..', 'fixtures', 'config.yml'))
51
+ Ripple.client.port.should == 9000
52
+ Ripple.client.host.should == 'localhost'
53
+ end
44
54
  end
@@ -1,49 +1,42 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Ripple::Document::Timestamps do
4
-
5
- before :all do
6
- Object.module_eval { class Box; include Ripple::Document; property :shape, String; timestamps! end }
7
- end
4
+ require 'support/models/clock'
8
5
 
9
6
  before :each do
10
7
  response = {:headers => {"content-type" => ["application/json"]}, :body => "{}"}
11
8
  @client = Ripple.client
12
9
  @http = mock("HTTP Backend", :get => response, :put => response, :post => response, :delete => response)
13
10
  @client.stub!(:http).and_return(@http)
14
- @box = Box.new
11
+ @clock = Clock.new
15
12
  end
16
13
 
17
14
  it "should add a created_at property" do
18
- @box.should respond_to(:created_at)
15
+ @clock.should respond_to(:created_at)
19
16
  end
20
17
 
21
18
  it "should add an updated_at property" do
22
- @box.should respond_to(:updated_at)
19
+ @clock.should respond_to(:updated_at)
23
20
  end
24
21
 
25
22
  it "should set the created_at timestamp when the object is initialized" do
26
- @box.created_at.should_not be_nil
23
+ @clock.created_at.should_not be_nil
27
24
  end
28
25
 
29
26
  it "should not set the updated_at timestamp when the object is initialized" do
30
- @box.updated_at.should be_nil
27
+ @clock.updated_at.should be_nil
31
28
  end
32
29
 
33
30
  it "should set the updated_at timestamp when the object is created" do
34
- @box.save
35
- @box.updated_at.should_not be_nil
31
+ @clock.save
32
+ @clock.updated_at.should_not be_nil
36
33
  end
37
34
 
38
35
  it "should update the updated_at timestamp when the object is updated" do
39
- @box.save
40
- start = @box.updated_at
41
- @box.save
42
- @box.updated_at.should > start
43
- end
44
-
45
- after :all do
46
- Object.send(:remove_const, :Box)
36
+ @clock.save
37
+ start = @clock.updated_at
38
+ @clock.save
39
+ @clock.updated_at.should > start
47
40
  end
48
41
 
49
42
  end
@@ -14,9 +14,7 @@
14
14
  require File.expand_path("../../spec_helper", __FILE__)
15
15
 
16
16
  describe Ripple::Document::Validations do
17
- before :all do
18
- Object.module_eval { class Box; include Ripple::Document; property :shape, String end }
19
- end
17
+ require 'support/models/box'
20
18
 
21
19
  before :each do
22
20
  @box = Box.new
@@ -41,6 +39,53 @@ describe Ripple::Document::Validations do
41
39
  @box.should_receive(:valid?).and_return(false)
42
40
  @box.save.should be_false
43
41
  end
42
+
43
+ it "should allow skipping validations by passing save :validate => false" do
44
+ Ripple.client.http.stub!(:perform).and_return(mock_response)
45
+ @box.should_not_receive(:valid?)
46
+ @box.save(:validate => false).should be_true
47
+ end
48
+
49
+ describe "when using save! on an invalid record" do
50
+ before(:each) { @box.stub!(:valid?).and_return(false) }
51
+
52
+ it "should raise DocumentInvalid" do
53
+ lambda { @box.save! }.should raise_error(Ripple::DocumentInvalid)
54
+ end
55
+
56
+ it "should raise an exception that has the invalid document" do
57
+ begin
58
+ @box.save!
59
+ rescue Ripple::DocumentInvalid => invalid
60
+ invalid.document.should == @box
61
+ end
62
+ end
63
+ end
64
+
65
+ it "should not raise an error when save! is called and the document is valid" do
66
+ @box.stub!(:save).and_return(true)
67
+ @box.stub!(:valid?).and_return(true)
68
+ lambda { @box.save! }.should_not raise_error(Ripple::DocumentInvalid)
69
+ end
70
+
71
+ it "should return true from save! when no exception is raised" do
72
+ @box.stub!(:save).and_return(true)
73
+ @box.stub!(:valid?).and_return(true)
74
+ @box.save!.should be_true
75
+ end
76
+
77
+ it "should not raise an error when creating a box with create! succeeds" do
78
+ @box.stub!(:new?).and_return(false)
79
+ Box.stub(:create).and_return(@box)
80
+ lambda { @new_box = Box.create! }.should_not raise_error(Ripple::DocumentInvalid)
81
+ @new_box.should == @box
82
+ end
83
+
84
+ it "should raise an error when creating a box with create! fails" do
85
+ @box.stub!(:new?).and_return(true)
86
+ Box.stub(:create).and_return(@box)
87
+ lambda { Box.create! }.should raise_error(Ripple::DocumentInvalid)
88
+ end
44
89
 
45
90
  it "should automatically add validations from property options" do
46
91
  Box.property :size, Integer, :inclusion => {:in => 1..30 }
@@ -60,7 +105,4 @@ describe Ripple::Document::Validations do
60
105
  Box.reset_callbacks(:validate)
61
106
  end
62
107
 
63
- after :all do
64
- Object.send(:remove_const, :Box)
65
- end
66
108
  end
@@ -13,20 +13,14 @@
13
13
  # limitations under the License.
14
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
15
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'riak','lib'))
16
17
 
17
18
  require 'rubygems' # Use the gems path only for the spec suite
18
19
  require 'ripple'
19
- require 'spec'
20
- require 'spec/autorun'
21
- require 'fakeweb'
20
+ require 'rspec/autorun'
22
21
 
23
22
  Dir[File.join(File.dirname(__FILE__), "support", "*.rb")].each {|f| require f }
24
23
 
25
- $server = MockServer.new
26
- at_exit { $server.stop }
27
-
28
- Spec::Runner.configure do |config|
29
- config.before(:each) do
30
- FakeWeb.clean_registry
31
- end
24
+ Rspec.configure do |config|
25
+ config.mock_with :rspec
32
26
  end