spec/unit/trello_wrapper_spec.rb in trollolo-0.0.6 vs spec/unit/trello_wrapper_spec.rb in trollolo-0.0.7

- old
+ new

@@ -72,6 +72,43 @@ path = given_file("attachment-data") subject.add_attachment("123", path) end end + + describe "#make_cover" do + let(:card_id) { "c133a484cff21c7a33ff031f" } + let(:image_id) { "484cff21c7a33ff031f997a" } + let(:image_name) { "passed.jpg" } + let(:client) { double } + let(:card_attachments_body) { <<-EOF + [ + { + "id":"78d86ae7f25c748559b37ca", + "name":"failed.jpg" + }, + { + "id":"484cff21c7a33ff031f997a", + "name":"passed.jpg" + } + ] +EOF + } + + before(:each) do + stub_request(:get, "https://api.trello.com/1/cards/#{card_id}/attachments?fields=name&key=mykey&token=mytoken"). + with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>'Ruby'}). + to_return(:status => 200, :body => card_attachments_body, :headers => {}) + stub_request(:put, "https://api.trello.com/1/cards/#{card_id}/idAttachmentCover?key=mykey&token=mytoken&value=#{image_id}"). + with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'0', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}) + end + + it "make the attachment with the file name passed.jpg the cover" do + subject.make_cover(card_id, image_name) + expect(WebMock).to have_requested(:put, "https://api.trello.com/1/cards/#{card_id}/idAttachmentCover?key=mykey&token=mytoken&value=#{image_id}") + end + + it "shows an error if the file was not found in the attachment list" do + expect { subject.make_cover(card_id, "non_existing_file.jpg") }.to raise_error(/non_existing_file.jpg/) + end + end end