Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change UrlShortener::Response::Expand.url to use long_url

method caught by method_missing to call longUrl. The url 
method is kept just to keep backward compatibility
  • Loading branch information...
commit 34a141b6fb2709a3579e9881c8bf7d9ec292f078 1 parent 4cb0b0e
nas authored
View
17 lib/url_shortener/response/expand.rb
@@ -7,21 +7,16 @@ def initialize(response)
end
def url
- return unless result_present?
- return unless key_present?
- url_hash = result.keys.first
- result[url_hash]['longUrl']
+ long_url
end
private
- def result_present?
- result && !result.empty?
- end
-
- def key_present?
- result_present?
- result.keys && !result.keys.empty?
+ def base_element
+ return unless attributes
+ return unless attributes.first
+ return unless attributes.first.is_a?(Array)
+ attributes.first.last
end
end
View
49 spec/url_shortener/response/expand_spec.rb
@@ -6,54 +6,11 @@
before(:each) do
@result_hash = {"1RmnUT" => {"longUrl" => "http://google.com"}}
@expand = UrlShortener::Response::Expand.new(@result_hash)
- @expand.stub!(:result).and_return(@result_hash)
- @keys = ['1RmnUT']
- @key = '1RmnUT'
- @result_hash.stub!(:keys).and_return(@keys)
- @keys.stub!(:first).and_return(@key)
- @expand.stub!(:result_present?).and_return(true)
- @expand.stub!(:key_present?).and_return(true)
+ @expand.stub!(:long_url).and_return('http://google.com')
end
- it "should check if keys are present when results are present" do
- @expand.stub!(:result_present?).and_return(true)
- @expand.should_receive(:key_present?)
- @expand.url.should
- end
-
- it "should not check if keys are present when results are not present" do
- @expand.stub!(:result_present?).and_return(false)
- @expand.should_receive(:key_present?).never
- @expand.url.should
- end
-
- it "should return nil if there are no keys" do
- @expand.stub!(:key_present?).and_return(nil)
- @expand.url.should eql(nil)
- end
-
- it "should check if results are present" do
- @expand.should_receive(:result_present?)
- @expand.url.should
- end
-
- it "should return nil is result is not present" do
- @expand.stub!(:result_present?).and_return(nil)
- @expand.url.should eql(nil)
- end
-
- it "should get the result" do
- @expand.should_receive(:result).and_return(@result_hash)
- @expand.url
- end
-
- it "should find the keys in the result returned from bitley" do
- @result_hash.should_receive(:keys).and_return(@keys)
- @expand.url
- end
-
- it "should get first key as there will be only key returning from bitly" do
- @keys.should_receive(:first).and_return(@key)
+ it "should get the long_url" do
+ @expand.should_receive(:long_url)
@expand.url
end
Please sign in to comment.
Something went wrong with that request. Please try again.