test/helper.rb in createsend-2.5.1 vs test/helper.rb in createsend-3.0.0
- old
+ new
@@ -1,11 +1,10 @@
require 'test/unit'
require 'pathname'
require 'shoulda'
require 'matchy'
-require 'mocha/setup'
require 'fakeweb'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'createsend'
@@ -16,21 +15,55 @@
return '' if filename == ''
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
File.read(file_path)
end
-def createsend_url(api_key, url)
- api_key.nil? ? url : url =~ /^http/ ? url : "https://#{api_key}:x@api.createsend.com/api/v3/#{url}"
+def createsend_url(auth, url)
+ if not url =~ /^http/
+ auth_section = ''
+ auth_section = "#{auth[:api_key]}:x@" if auth and auth.has_key? :api_key
+ result = "https://#{auth_section}api.createsend.com/api/v3/#{url}"
+ else
+ result = url
+ end
+ result
end
-def stub_request(method, api_key, url, filename, status=nil)
+def stub_request(method, auth, url, filename, status=nil)
options = {:body => ""}
options.merge!({:body => fixture_file(filename)}) if filename
options.merge!({:status => status}) if status
options.merge!(:content_type => "application/json; charset=utf-8")
- FakeWeb.register_uri(method, createsend_url(api_key, url), options)
+ FakeWeb.register_uri(method, createsend_url(auth, url), options)
end
def stub_get(*args); stub_request(:get, *args) end
def stub_post(*args); stub_request(:post, *args) end
def stub_put(*args); stub_request(:put, *args) end
def stub_delete(*args); stub_request(:delete, *args) end
+
+def multiple_contexts(*contexts, &blk)
+ contexts.each do |context|
+ send(context, &blk)
+ end
+end
+
+def authenticated_using_oauth_context(&blk)
+ context "when an api caller is authenticated using oauth" do
+ setup do
+ @access_token = 'joidjo2i3joi3je'
+ @refresh_token = 'j89u98eu9e8ufe'
+ @auth = {:access_token => @access_token, :refresh_token => @refresh_token}
+ end
+ merge_block(&blk)
+ end
+end
+
+def authenticated_using_api_key_context(&blk)
+ context "when an api caller is authenticated using an api key" do
+ setup do
+ @api_key = '123123123123123123123'
+ @auth = {:api_key => @api_key}
+ end
+ merge_block(&blk)
+ end
+end
\ No newline at end of file