From fc2fddc29b7b1e9fb725eba7157b4e5b986455a8 Mon Sep 17 00:00:00 2001 From: laserlemon Date: Mon, 11 Oct 2010 14:49:36 -0400 Subject: [PATCH] Add header initialization tests. --- test/helper.rb | 4 ++++ test/simple_oauth_test.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/helper.rb create mode 100644 test/simple_oauth_test.rb diff --git a/test/helper.rb b/test/helper.rb new file mode 100644 index 0000000..f2fa172 --- /dev/null +++ b/test/helper.rb @@ -0,0 +1,4 @@ +require 'test/unit' +require 'simple_oauth' +require 'rubygems' +require 'mocha' diff --git a/test/simple_oauth_test.rb b/test/simple_oauth_test.rb new file mode 100644 index 0000000..4d1e1a6 --- /dev/null +++ b/test/simple_oauth_test.rb @@ -0,0 +1,35 @@ +require 'helper' + +class SimpleOAuthTest < Test::Unit::TestCase + def test_initialization_argument_formatting + header = SimpleOAuth::Header.new(:get, 'HTTPS://api.TWITTER.com:443/statuses/friendships.json#anchor', {}) + + # HTTP method should be an uppercase string. + # + # See: http://oauth.net/core/1.0/#rfc.section.9.1.3 + assert_equal 'GET', header.method + + # Request URL should downcase the scheme and authority parts as well as + # remove the query and fragment parts. + # + # See: http://oauth.net/core/1.0/#rfc.section.9.1.2 + assert_equal 'https://api.twitter.com/statuses/friendships.json', header.url + end + + def test_default_options + # Default header options should change with each call due to generation of + # a unique "timestamp" and "nonce" value combination. + default_options = SimpleOAuth::Header.default_options + assert_not_equal default_options, SimpleOAuth::Header.default_options + + SimpleOAuth::Header.stubs(:default_options).returns(default_options) + header = SimpleOAuth::Header.new(:get, 'https://api.twitter.com/statuses/friendships.json', {}) + + # Given no options argument, header options defer to the default options. + assert_equal default_options, header.options + + # Default options should include a signature method and the OAuth version. + assert_equal 'HMAC-SHA1', default_options[:signature_method] + assert_equal '1.0', default_options[:version] + end +end