From 2da491308766e82c797c7801bdc3a440b7f8d719 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Wed, 8 Apr 2009 22:13:18 -0400 Subject: [PATCH] Fixed that mash doesn't hash stuff consistently and thus makes it hard to use mashed objects with set and such. (technomancy) --- lib/twitter/request.rb | 13 +++++++++++-- test/twitter/base_test.rb | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/twitter/request.rb b/lib/twitter/request.rb index 93956e470..4c09c0913 100644 --- a/lib/twitter/request.rb +++ b/lib/twitter/request.rb @@ -74,13 +74,22 @@ def parse(response) def mash(obj) if obj.is_a?(Array) - obj.map { |item| Mash.new(item) } + obj.map { |item| make_mash_with_consistent_hash(item) } elsif obj.is_a?(Hash) - Mash.new(obj) + make_mash_with_consistent_hash(obj) else obj end end + + # Lame workaround for the fact that mash doesn't hash correctly + def make_mash_with_consistent_hash(obj) + m = Mash.new(obj) + def m.hash + inspect.hash + end + return m + end def to_query(options) options.inject([]) do |collection, opt| diff --git a/test/twitter/base_test.rb b/test/twitter/base_test.rb index 2d682c86d..afdda9d67 100644 --- a/test/twitter/base_test.rb +++ b/test/twitter/base_test.rb @@ -69,6 +69,12 @@ class BaseTest < Test::Unit::TestCase first.user.name.should == '-oAk-' first.text.should == '@jnunemaker cold out today. cold yesterday. even colder today.' end + + should "correctly hash statuses" do + stub_get('/statuses/friends_timeline.json', 'friends_timeline.json') + hashes = @twitter.friends_timeline.map{ |s| s.hash } + hashes.should == @twitter.friends_timeline.map{ |s| s.hash } + end end end end \ No newline at end of file