spec/examples/post_spec.rb in tumblr_client-0.8.2 vs spec/examples/post_spec.rb in tumblr_client-0.8.3
- old
+ new
@@ -26,19 +26,68 @@
end
end
describe :edit do
+ [:photo, :audio, :video].each do |type|
+ describe type do
+ context 'when passing data as an array of filepaths' do
+ before do
+ fakefile = OpenStruct.new :read => file_data
+ File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
+ client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ 'data[0]' => kind_of(Faraday::UploadIO),
+ :id => 123,
+ :type => type
+ }).and_return('response')
+ end
+ it 'should be able to pass data as an array of filepaths' do
+ r = client.edit blog_name, :data => [file_path + ".jpg"], :id => 123, :type => type
+ r.should == 'response'
+ end
+
+ it 'should be able to pass data as an array of uploadios' do
+ r = client.edit blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')], :id => 123, :type => type
+ r.should == 'response'
+ end
+
+ end
+
+ context 'when passing data different ways' do
+
+ before do
+ fakefile = OpenStruct.new :read => file_data
+ File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
+ client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ 'data' => kind_of(Faraday::UploadIO),
+ :id => 123,
+ :type => type
+ }).and_return('response')
+ end
+
+ it 'should be able to pass data as a single filepath' do
+ r = client.edit blog_name, :data => file_path + ".jpg", :id => 123, :type => type
+ r.should == 'response'
+ end
+
+ it 'should be able to pass data as a single uploadio' do
+ r = client.edit blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg'), :id => 123, :type => type
+ r.should == 'response'
+ end
+
+ end
+ end
+ end
+
it 'should make the correct call' do
client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
:id => 123
}).and_return('response')
r = client.edit blog_name, :id => 123
r.should == 'response'
end
-
end
describe :reblog do
it 'should make the correct call' do
@@ -87,10 +136,39 @@
end
end
+ describe :create_post do
+
+ let(:blog_name) { 'seejohnrun' }
+ let(:args) { { :source => 'somesource' } }
+
+ context 'with a valid post type' do
+
+ before do
+ client.should_receive(:photo).with(blog_name, args).and_return 'hi'
+ end
+
+ it 'should call the right method and grab the return' do
+ client.create_post(:photo, blog_name, args).should == 'hi'
+ end
+
+ end
+
+ context 'with an invalid post type' do
+
+ it 'should raise an error' do
+ lambda do
+ client.create_post(:fake, blog_name, args)
+ end.should raise_error ArgumentError, '"fake" is not a valid post type'
+ end
+
+ end
+
+ end
+
# Complex post types
[:photo, :audio, :video].each do |type|
describe type do
@@ -117,10 +195,15 @@
it 'should be able to pass data as an array of filepaths' do
r = client.send type, blog_name, :data => [file_path + ".jpg"]
r.should == 'post'
end
+ it 'should be able to pass data as an array of uploadios' do
+ r = client.send type, blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')]
+ r.should == 'post'
+ end
+
end
context 'when passing data different ways' do
before do
@@ -132,9 +215,14 @@
}).and_return('post')
end
it 'should be able to pass data as a single filepath' do
r = client.send type, blog_name, :data => file_path + ".jpg"
+ r.should == 'post'
+ end
+
+ it 'should be able to pass data as a single uploadio' do
+ r = client.send type, blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg')
r.should == 'post'
end
end