From e059278a5ebaa2ccaf5547f328ecbefb06701655 Mon Sep 17 00:00:00 2001 From: Marc Florisson Date: Mon, 10 Dec 2012 17:26:01 +0100 Subject: refactor spec --- spec/support/api_key.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 spec/support/api_key.rb (limited to 'spec/support/api_key.rb') diff --git a/spec/support/api_key.rb b/spec/support/api_key.rb new file mode 100644 index 000000000..8c025bbad --- /dev/null +++ b/spec/support/api_key.rb @@ -0,0 +1,42 @@ +module ApiKeyHelper + + def get_api_key + Api::V1::ApiKey.create( referential.organisation, referential) + end + def config_formatted_request_with_authorization( format) + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( get_api_key.token) + request.accept = format + end + def config_formatted_request_with_dummy_authorization( format) + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( "dummy") + request.accept = format + end + def config_formatted_request_without_authorization( format) + request.env['HTTP_AUTHORIZATION'] = nil + request.accept = format + end + def json_xml_format? + request.accept == "application/json" || request.accept == "application/xml" + end + + def self.included(base) + base.class_eval do + extend ClassMethods + alias_method :api_key, :get_api_key + end + end + + module ClassMethods + def assign_api_key + before(:each) do + assign :api_key, api_key + end + end + end + +end + +RSpec.configure do |config| + config.include ApiKeyHelper +end + -- cgit v1.2.3