Browse files

Remove UrlShortener::Response::Stats#clicks, #user_clicks and

add #hash

 * the removed methods are now being caught by the method missing
 * #hash is added because hashie adds its own #hash method to 
   its objects which returns different values compared to what 
   is expected
  • Loading branch information...
1 parent 34a141b commit 0314b49622ae5c116af43fe0bcf0d2bec544654d nas committed Nov 19, 2009
Showing with 4 additions and 62 deletions.
  1. +4 −6 lib/url_shortener/response/stats.rb
  2. +0 −56 spec/url_shortener/response/stats_spec.rb
View
10 lib/url_shortener/response/stats.rb
@@ -5,12 +5,10 @@ def initialize(response)
super
end
- def clicks
- attributes.clicks
- end
-
- def user_clicks
- attributes.userClicks
+ # Just to override the hash method provided by hashie
+ # that adds some other hash value
+ def hash
+ result['hash']
end
def referrers
View
56 spec/url_shortener/response/stats_spec.rb
@@ -2,62 +2,6 @@
describe UrlShortener::Response::Stats do
- describe "#clicks" do
- before(:each) do
- @hashie = stub('Hashie::Mash')
- @response = {:referrers => {:key => :val}, :clicks => '23'}
- @stats = UrlShortener::Response::Stats.new(@response)
- @stats.stub!(:attributes).and_return(@hashie)
- @hashie.stub!(:clicks)
- end
-
- it "should get the hash attributes" do
- @stats.should_receive(:attributes).and_return(@hashie)
- @stats.clicks
- end
-
- it "should get the clicks from the hash attributes" do
- @hashie.should_receive(:clicks)
- @stats.clicks
- end
-
- it "should return nil when response is empty" do
- response = {}
- @stats = UrlShortener::Response::Stats.new(response)
- @stats.clicks.should eql(nil)
- end
- end
-
- describe "#user_clicks" do
- before(:each) do
- @hashie = stub('Hashie::Mash')
- @response = {:referrers => {:key => :val}, :clicks => '23', :userClicks => '233'}
- @stats = UrlShortener::Response::Stats.new(@response)
- @stats.stub!(:attributes).and_return(@hashie)
- @hashie.stub!(:userClicks).and_return('233')
- end
-
- it "should get the hash attributes" do
- @stats.should_receive(:attributes).and_return(@hashie)
- @stats.user_clicks
- end
-
- it "should get the user clicks from the hash attributes" do
- @hashie.should_receive(:userClicks)
- @stats.user_clicks
- end
-
- it "should return userClicks" do
- @stats.user_clicks.should eql('233')
- end
-
- it "should return nil when response is empty" do
- response = {}
- @stats = UrlShortener::Response::Stats.new(response)
- @stats.user_clicks.should eql(nil)
- end
- end
-
describe "#referrers" do
before(:each) do
@response = {:referrers => {:nodeKeyVal => {:nodeKey => 'val'}}}

0 comments on commit 0314b49

Please sign in to comment.