Skip to content

Commit

Permalink
Remove UrlShortener::Response::Stats#clicks, #user_clicks and
Browse files Browse the repository at this point in the history
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
nas committed Nov 19, 2009
1 parent 34a141b commit 0314b49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
10 changes: 4 additions & 6 deletions lib/url_shortener/response/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 0 additions & 56 deletions spec/url_shortener/response/stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}}
Expand Down

0 comments on commit 0314b49

Please sign in to comment.