Permalink
Browse files

Update presenter with errors from its object on save

  • Loading branch information...
1 parent 0396af2 commit af9488a8fd9da150c4b05c8e677a553ae743be67 Bantik committed Sep 18, 2012
Showing with 15 additions and 6 deletions.
  1. +2 −2 Rakefile
  2. +3 −1 lib/faceted/presenter.rb
  3. +10 −3 spec/presenter_spec.rb
View
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
gem.name = "faceted"
gem.homepage = "http://github.com/trunkclub/faceted"
gem.license = "MIT"
- gem.summary = %Q{Provides useful tools for API implementations.}
- gem.description = %Q{Provides useful tools for API implementations.}
+ gem.summary = %Q{Faceted provides set of tools, patterns, and modules for use in API implementations.}
+ gem.description = %Q{Faceted provides set of tools, patterns, and modules for use in API implementations.}
gem.email = "corey@trunkclub.com"
gem.authors = ["Corey Ehmke", "Max Thom Stahl"]
# dependencies defined in Gemfile
View
@@ -96,7 +96,9 @@ def initialize(args={})
def save
schema_fields.each{ |k| object.send("#{k}=", self.send(k)) if object.respond_to?("#{k}=") }
- object.save!
+ self.success = object.save
+ self.errors = object.errors && object.errors.full_messages
+ self.success
end
def to_hash
View
@@ -57,17 +57,24 @@ class Musician
it 'successfully' do
musician = MyApi::Musician.new(:id => 1)
- @ar_musician.should_receive(:save!) { true }
+ @ar_musician.should_receive(:save) { true }
musician.save.should be_true
end
it 'handling failure' do
musician = MyApi::Musician.new(:id => 1)
- @ar_musician.should_receive(:save!) { false }
+ @ar_musician.should_receive(:save) { false }
musician.save.should be_false
end
- it 'failing and populating its errors'
+ it 'failing and populating its errors' do
+ musician = MyApi::Musician.new(:id => 1)
+ @ar_musician.should_receive(:save) { false }
+ @ar_musician.stub_chain(:errors, :full_messages) { ["Something went wrong", "Terribly wrong"] }
+ musician.save
+ musician.errors.count.should == 2
+ musician.errors.last.should == "Terribly wrong"
+ end
end

0 comments on commit af9488a

Please sign in to comment.