Skip to content

Commit

Permalink
added tests for update_with_media
Browse files Browse the repository at this point in the history
  • Loading branch information
stve committed Aug 29, 2011
1 parent 8e31749 commit d5acb4a
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/twitter/client/tweets.rb
Expand Up @@ -45,7 +45,7 @@ def update(status, options={})
response = post('statuses/update', options.merge(:status => status))
format.to_s.downcase == 'xml' ? response['status'] : response
end

# Updates with media the authenticating user's status
#
# @format :json, :xml
Expand All @@ -72,7 +72,7 @@ def update(status, options={})
# Twitter.update("I just posted a status update with a pic via the Twitter Ruby Gem!", {'io' => StringIO.new(pic), 'type' => 'jpg'})
def update_with_media(status, image, options={})
response = post('statuses/update_with_media', options.merge('media[]' => image, 'status' => status), format, media_endpoint)
format.to_s.downcase == 'xml' ? response['user'] : response
format.to_s.downcase == 'xml' ? response['status'] : response
end

# Destroys the specified status
Expand Down
104 changes: 104 additions & 0 deletions spec/fixtures/status_with_media.json
@@ -0,0 +1,104 @@
{
"in_reply_to_status_id": null,
"created_at": "Mon Aug 29 03:48:06 +0000 2011",
"geo": null,
"user": {
"profile_background_tile": true,
"protected": false,
"url": "http://www.beforeitwasround.com",
"listed_count": 21,
"name": "Steve Agalloco",
"profile_link_color": "009999",
"following": true,
"utc_offset": -18000,
"profile_sidebar_border_color": "eeeeee",
"description": "ruby, rails, node, nosql, husband, father, golfer. not necessarily in that order.",
"time_zone": "Eastern Time (US & Canada)",
"created_at": "Wed Aug 23 01:12:20 +0000 2006",
"friends_count": 380,
"profile_image_url": "http://a3.twimg.com/profile_images/1376908742/social_network_icon_normal.jpg",
"default_profile_image": false,
"show_all_inline_media": true,
"contributors_enabled": false,
"geo_enabled": true,
"profile_use_background_image": false,
"profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/140563920/116775_0147_ful.jpg",
"profile_background_color": "131516",
"screen_name": "anno",
"is_translator": false,
"profile_background_image_url": "http://a3.twimg.com/profile_background_images/140563920/116775_0147_ful.jpg",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1376908742/social_network_icon_normal.jpg",
"follow_request_sent": false,
"statuses_count": 2013,
"favourites_count": 383,
"id_str": "4618",
"lang": "en",
"verified": false,
"profile_text_color": "333333",
"location": "Charlotte, NC",
"id": 4618,
"default_profile": false,
"notifications": false,
"profile_sidebar_fill_color": "efefef",
"followers_count": 396
},
"in_reply_to_user_id": null,
"truncated": false,
"coordinates": null,
"favorited": false,
"possibly_sensitive": false,
"in_reply_to_status_id_str": null,
"in_reply_to_screen_name": null,
"source": "<a href=\"http://beforeitwasround.com\" rel=\"nofollow\">Tweetstreamie</a>",
"in_reply_to_user_id_str": null,
"id_str": "108023089715089408",
"entities": {
"hashtags": [],
"media": [
{
"type": "photo",
"url": "http://t.co/CBYa7Ri",
"media_url": "http://p.twimg.com/AX_GbYJCEAAldJ7.jpg",
"display_url": "pic.twitter.com/CBYa7Ri",
"expanded_url": "http://twitter.com/anno/status/108023089715089408/photo/1",
"media_url_https": "https://p.twimg.com/AX_GbYJCEAAldJ7.jpg",
"indices": [
24,
43
],
"sizes": {
"small": {
"h": 81,
"w": 94,
"resize": "fit"
},
"medium": {
"h": 81,
"w": 94,
"resize": "fit"
},
"large": {
"h": 81,
"w": 94,
"resize": "fit"
},
"thumb": {
"h": 81,
"w": 94,
"resize": "crop"
}
},
"id": 108023089719283710,
"id_str": "108023089719283712"
}
],
"urls": [],
"user_mentions": []
},
"id": 108023089715089400,
"contributors": null,
"place": null,
"retweeted": false,
"retweet_count": 0,
"text": "You always have options http://t.co/CBYa7Ri"
}
97 changes: 97 additions & 0 deletions spec/fixtures/status_with_media.xml
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>Mon Aug 29 03:48:06 +0000 2011</created_at>
<id>108023089715089408</id>
<text>You always have options http://t.co/CBYa7Ri</text>
<source>&lt;a href=&quot;http://beforeitwasround.com&quot; rel=&quot;nofollow&quot;&gt;Tweetstreamie&lt;/a&gt;</source>
<truncated>false</truncated>
<favorited>false</favorited>
<in_reply_to_status_id></in_reply_to_status_id>
<in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_screen_name></in_reply_to_screen_name>
<retweet_count>0</retweet_count>
<retweeted>false</retweeted>
<user>
<id>4618</id>
<name>Steve Agalloco</name>
<screen_name>anno</screen_name>
<location>Charlotte, NC</location>
<description>ruby, rails, node, nosql, husband, father, golfer. not necessarily in that order.</description>
<profile_image_url>http://a3.twimg.com/profile_images/1376908742/social_network_icon_normal.jpg</profile_image_url>
<profile_image_url_https>https://si0.twimg.com/profile_images/1376908742/social_network_icon_normal.jpg</profile_image_url_https>
<url>http://www.beforeitwasround.com</url>
<protected>false</protected>
<followers_count>396</followers_count>
<profile_background_color>131516</profile_background_color>
<profile_text_color>333333</profile_text_color>
<profile_link_color>009999</profile_link_color>
<profile_sidebar_fill_color>efefef</profile_sidebar_fill_color>
<profile_sidebar_border_color>eeeeee</profile_sidebar_border_color>
<friends_count>380</friends_count>
<created_at>Wed Aug 23 01:12:20 +0000 2006</created_at>
<favourites_count>383</favourites_count>
<utc_offset>-18000</utc_offset>
<time_zone>Eastern Time (US &amp; Canada)</time_zone>
<profile_background_image_url>http://a3.twimg.com/profile_background_images/140563920/116775_0147_ful.jpg</profile_background_image_url>
<profile_background_image_url_https>https://si0.twimg.com/profile_background_images/140563920/116775_0147_ful.jpg</profile_background_image_url_https>
<profile_background_tile>true</profile_background_tile>
<profile_use_background_image>false</profile_use_background_image>
<notifications>false</notifications>
<geo_enabled>true</geo_enabled>
<verified>false</verified>
<following>true</following>
<statuses_count>2013</statuses_count>
<lang>en</lang>
<contributors_enabled>false</contributors_enabled>
<follow_request_sent>false</follow_request_sent>
<listed_count>21</listed_count>
<show_all_inline_media>true</show_all_inline_media>
<default_profile>false</default_profile>
<default_profile_image>false</default_profile_image>
<is_translator>false</is_translator>
</user>
<geo/>
<coordinates/>
<place/>
<possibly_sensitive>false</possibly_sensitive>
<contributors/>
<entities>
<user_mentions/>
<media>
<creative end="43" start="24">
<media_url>http://p.twimg.com/AX_GbYJCEAAldJ7.jpg</media_url>
<url>http://t.co/CBYa7Ri</url>
<type>photo</type>
<display_url>pic.twitter.com/CBYa7Ri</display_url>
<media_url_https>https://p.twimg.com/AX_GbYJCEAAldJ7.jpg</media_url_https>
<expanded_url>http://twitter.com/anno/status/108023089715089408/photo/1</expanded_url>
<sizes>
<small>
<w>94</w>
<h>81</h>
<resize>fit</resize>
</small>
<medium>
<w>94</w>
<h>81</h>
<resize>fit</resize>
</medium>
<large>
<w>94</w>
<h>81</h>
<resize>fit</resize>
</large>
<thumb>
<w>94</w>
<h>81</h>
<resize>crop</resize>
</thumb>
</sizes>
<id_str>108023089719283712</id_str>
<id>108023089719283712</id>
</creative>
</media>
<urls/>
<hashtags/>
</entities>
</status>
32 changes: 16 additions & 16 deletions spec/helper.rb
Expand Up @@ -6,36 +6,36 @@
require 'rspec'
require 'webmock/rspec'

def a_delete(path)
a_request(:delete, Twitter.endpoint + path)
def a_delete(path, endpoint=Twitter.endpoint)
a_request(:delete, endpoint + path)
end

def a_get(path)
a_request(:get, Twitter.endpoint + path)
def a_get(path, endpoint=Twitter.endpoint)
a_request(:get, endpoint + path)
end

def a_post(path)
a_request(:post, Twitter.endpoint + path)
def a_post(path, endpoint=Twitter.endpoint)
a_request(:post, endpoint + path)
end

def a_put(path)
a_request(:put, Twitter.endpoint + path)
def a_put(path, endpoint=Twitter.endpoint)
a_request(:put, endpoint + path)
end

def stub_delete(path)
stub_request(:delete, Twitter.endpoint + path)
def stub_delete(path, endpoint=Twitter.endpoint)
stub_request(:delete, endpoint + path)
end

def stub_get(path)
stub_request(:get, Twitter.endpoint + path)
def stub_get(path, endpoint=Twitter.endpoint)
stub_request(:get, endpoint + path)
end

def stub_post(path)
stub_request(:post, Twitter.endpoint + path)
def stub_post(path, endpoint=Twitter.endpoint)
stub_request(:post, endpoint + path)
end

def stub_put(path)
stub_request(:put, Twitter.endpoint + path)
def stub_put(path, endpoint=Twitter.endpoint)
stub_request(:put, endpoint + path)
end

def fixture_path
Expand Down
25 changes: 25 additions & 0 deletions spec/twitter/client/tweets_spec.rb
Expand Up @@ -49,6 +49,31 @@

end

describe ".update_with_media" do

before do
stub_post("statuses/update_with_media.#{format}", Twitter.media_endpoint).
to_return(:body => fixture("status_with_media.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
end

it "should get the correct resource" do
@client.update_with_media("You always have options", fixture("me.jpeg"))
a_post("statuses/update_with_media.#{format}", Twitter.media_endpoint).
should have_been_made
end

it "should return a single status" do
status = @client.update_with_media("You always have options", fixture("me.jpeg"))
status.text.should include("You always have options")
end

it 'should return the media as an entity' do
status = @client.update_with_media("You always have options", fixture("me.jpeg"))
status.entities.media.should be
end

end

describe ".status_destroy" do

before do
Expand Down

0 comments on commit d5acb4a

Please sign in to comment.