From d96194c0c3b17076e48faed1b05cd48d043a6778 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 24 Jun 2014 10:51:55 +0200 Subject: [PATCH] Make Twitter::User#profile_background_image_uri methods return a URI --- lib/twitter/user.rb | 1 + spec/twitter/user_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/twitter/user.rb b/lib/twitter/user.rb index 15630d513..8b630617e 100644 --- a/lib/twitter/user.rb +++ b/lib/twitter/user.rb @@ -34,6 +34,7 @@ class User < Twitter::BasicUser :profile_use_background_image, :suspended, :verified define_predicate_method :translator, :is_translator define_predicate_method :translation_enabled, :is_translation_enabled + uri_attr_reader :profile_background_image_uri, :profile_background_image_uri_https class << self private diff --git a/spec/twitter/user_spec.rb b/spec/twitter/user_spec.rb index a888658d9..8f3dff64b 100644 --- a/spec/twitter/user_spec.rb +++ b/spec/twitter/user_spec.rb @@ -107,6 +107,30 @@ end end + describe '#profile_background_image_uri' do + it 'returns the URI to the user' do + user = Twitter::User.new(:id => 7_505_382, :profile_background_image_url => 'http://pbs.twimg.com/profile_background_images/677717672/bb0b3653dcf0644e344823e0a2eb3382.png') + expect(user.profile_background_image_uri).to be_an Addressable::URI + expect(user.profile_background_image_uri.to_s).to eq('http://pbs.twimg.com/profile_background_images/677717672/bb0b3653dcf0644e344823e0a2eb3382.png') + end + it 'returns nil when the screen name is not set' do + user = Twitter::User.new(:id => 7_505_382) + expect(user.profile_background_image_uri).to be_nil + end + end + + describe '#profile_background_image_uri_https' do + it 'returns the URI to the user' do + user = Twitter::User.new(:id => 7_505_382, :profile_background_image_url_https => 'https://pbs.twimg.com/profile_background_images/677717672/bb0b3653dcf0644e344823e0a2eb3382.png') + expect(user.profile_background_image_uri_https).to be_an Addressable::URI + expect(user.profile_background_image_uri_https.to_s).to eq('https://pbs.twimg.com/profile_background_images/677717672/bb0b3653dcf0644e344823e0a2eb3382.png') + end + it 'returns nil when the screen name is not set' do + user = Twitter::User.new(:id => 7_505_382) + expect(user.profile_background_image_uri_https).to be_nil + end + end + describe '#profile_banner_uri' do it 'accepts utf8 urls' do user = Twitter::User.new(:id => 7_505_382, :profile_banner_url => 'https://si0.twimg.com/profile_banners/7_505_382/1348266581©_normal.png')