Skip to content
This repository
Browse code

Make #save return false when errors are present (fixes #36)

  • Loading branch information...
commit 711bde3bdbcdd51e6b8e202f00fe26474a61ec23 1 parent 61688ef
Rémi Prévost authored November 02, 2012
3  lib/her/model/orm.rb
@@ -114,8 +114,11 @@ def save # {{{
114 114
             self.data = parsed_data[:data]
115 115
             self.metadata = parsed_data[:metadata]
116 116
             self.errors = parsed_data[:errors]
  117
+
  118
+            return false if self.errors.any?
117 119
           end
118 120
         end
  121
+
119 122
         self
120 123
       end # }}}
121 124
 
9  spec/model/orm_spec.rb
@@ -236,10 +236,12 @@ def organization=(organization)
236 236
         builder.use Faraday::Request::UrlEncoded
237 237
         builder.adapter :test do |stub|
238 238
           stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
  239
+          stub.post("/companies") { |env| [200, {}, { :errors => ["name is required"] }.to_json] }
239 240
         end
240 241
       end
241 242
 
242 243
       spawn_model "Foo::User"
  244
+      spawn_model "Foo::Company"
243 245
     end # }}}
244 246
 
245 247
     it "handle one-line resource creation" do # {{{
@@ -250,9 +252,14 @@ def organization=(organization)
250 252
 
251 253
     it "handle resource creation through Model.new + #save" do # {{{
252 254
       @user = Foo::User.new(:fullname => "Tobias Fünke")
253  
-      @user.save
  255
+      @user.save.should be_true
254 256
       @user.fullname.should == "Tobias Fünke"
255 257
     end # }}}
  258
+
  259
+    it "returns false when #save gets errors" do # {{{
  260
+      @company = Foo::Company.new
  261
+      @company.save.should be_false
  262
+    end # }}}
256 263
   end
257 264
 
258 265
   context "updating resources" do

0 notes on commit 711bde3

Please sign in to comment.
Something went wrong with that request. Please try again.