./spec/animoto/client_spec.rb in animoto-0.0.0.alpha9 vs ./spec/animoto/client_spec.rb in animoto-0.1.0.beta0

- old
+ new

@@ -117,40 +117,64 @@ body = client.response_parser.unparse(hash) stub_request(:get, @url).to_return(:body => body, :status => [200,"OK"]) end it "should make a GET request to the given url" do - client.find(Animoto::Storyboard, @url) + client.find(Animoto::Resources::Storyboard, @url) WebMock.should have_requested(:get, @url) end it "should ask for a response in the proper format" do - client.find(Animoto::Storyboard, @url) + client.find(Animoto::Resources::Storyboard, @url) WebMock.should have_requested(:get, @url).with(:headers => { 'Accept' => "application/vnd.animoto.storyboard-v1+json" }) end it "should not sent a request body" do - client.find(Animoto::Storyboard, @url) + client.find(Animoto::Resources::Storyboard, @url) WebMock.should have_requested(:get, @url).with(:body => "") end it "should return an instance of the correct resource type" do - client.find(Animoto::Storyboard, @url).should be_an_instance_of(Animoto::Storyboard) + client.find(Animoto::Resources::Storyboard, @url).should be_an_instance_of(Animoto::Resources::Storyboard) end end describe "reloading an instance" do before do @url = 'https://joe:secret@api.animoto.com/jobs/directing/1' - @job = Animoto::DirectingJob.new :state => 'initial', :url => @url + @job = Animoto::Resources::Jobs::Directing.new :state => 'initial', :url => @url hash = {'response'=>{'status'=>{'code'=>200},'payload'=>{'directing_job'=>{'state'=>'retrieving_assets','links'=>{'self'=>@url,'storyboard'=>'http://api.animoto.com/storyboards/1'}}}}} body = client.response_parser.unparse(hash) stub_request(:get, @url).to_return(:body => body, :status => [200,"OK"]) @job.state.should == 'initial' # sanity check end it "should update the resource's attributes" do client.reload!(@job) @job.state.should == 'retrieving_assets' + end + end + + describe "processing a callback" do + before do + @body = %Q({"response":{"payload":{"base_callback":{"state":"failed","links":{"self":"https://api.animoto.com/things/123"}}},"status":{"errors":[{"code":"COLLAPSING_HRUNG_DISASTER","message":"A hrung has chosen to collapse disastrously."},{"code":"TOTAL_EXISTENCE_FAILURE","message":"The server is suffering from Total Existence Failure."}]}}}) + @callback = client.process_callback(Animoto::Callbacks::Base, @body) + end + + it "should return a callback instance" do + @callback.should be_an_instance_of(Animoto::Callbacks::Base) + end + + it "should set the state" do + @callback.state.should == "failed" + end + + it "should set the url" do + @callback.url.should == "https://api.animoto.com/things/123" + end + + it "should set the errors" do + @callback.errors.should be_an_instance_of(Array) + @callback.errors.should_not be_empty end end end \ No newline at end of file