Permalink
Browse files

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

  • Loading branch information...
1 parent 61688ef commit 711bde3bdbcdd51e6b8e202f00fe26474a61ec23 @remiprev committed Nov 2, 2012
Showing with 11 additions and 1 deletion.
  1. +3 −0 lib/her/model/orm.rb
  2. +8 −1 spec/model/orm_spec.rb
View
@@ -114,8 +114,11 @@ def save # {{{
self.data = parsed_data[:data]
self.metadata = parsed_data[:metadata]
self.errors = parsed_data[:errors]
+
+ return false if self.errors.any?
end
end
+
self
end # }}}
View
@@ -236,10 +236,12 @@ def organization=(organization)
builder.use Faraday::Request::UrlEncoded
builder.adapter :test do |stub|
stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
+ stub.post("/companies") { |env| [200, {}, { :errors => ["name is required"] }.to_json] }
end
end
spawn_model "Foo::User"
+ spawn_model "Foo::Company"
end # }}}
it "handle one-line resource creation" do # {{{
@@ -250,9 +252,14 @@ def organization=(organization)
it "handle resource creation through Model.new + #save" do # {{{
@user = Foo::User.new(:fullname => "Tobias Fünke")
- @user.save
+ @user.save.should be_true
@user.fullname.should == "Tobias Fünke"
end # }}}
+
+ it "returns false when #save gets errors" do # {{{
+ @company = Foo::Company.new
+ @company.save.should be_false
+ end # }}}
end
context "updating resources" do

0 comments on commit 711bde3

Please sign in to comment.