From e1ecd99f42a99ade21676328c3cd21ddb6b84e81 Mon Sep 17 00:00:00 2001 From: laserlemon Date: Mon, 11 Oct 2010 15:10:05 -0400 Subject: [PATCH] Test whether OAuth header attributes are parsed and re-keyed correctly. --- test/simple_oauth_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/simple_oauth_test.rb b/test/simple_oauth_test.rb index 4d1e1a6..351477c 100644 --- a/test/simple_oauth_test.rb +++ b/test/simple_oauth_test.rb @@ -32,4 +32,22 @@ class SimpleOAuthTest < Test::Unit::TestCase assert_equal 'HMAC-SHA1', default_options[:signature_method] assert_equal '1.0', default_options[:version] end + + def test_attributes + attribute_options = SimpleOAuth::Header::ATTRIBUTE_KEYS.inject({}){|o,a| o.merge(a => a.to_s.upcase) } + options = attribute_options.merge(:other => 'OTHER') + header = SimpleOAuth::Header.new(:get, 'https://api.twitter.com/statuses/friendships.json', {}, options) + attributes = header.send(:attributes) + + # OAuth header attributes are all to begin with the "oauth_" prefix. + assert attributes.all?{|k,v| k.to_s =~ /^oauth_/ } + + # Custom options not included in the list of valid attribute keys should + # not be included in the header attributes. + assert !attributes.key?(:oauth_other) + + # Valid attribute option values should be preserved. + assert_equal attribute_options.size, attributes.size + assert attributes.all?{|k,v| k.to_s == "oauth_#{v.downcase}" } + end end