Sha256: 7949f3bffc4f7b4905a677e7ed7a6595799e95cf1cee01136528ecb7f645706b

Contents?: true

Size: 1020 Bytes

Versions: 16

Compression:

Stored size: 1020 Bytes

Contents

module Spree
  module Api
    module TestingSupport
      module Helpers
        def json_response
          JSON.parse(response.body)
        end

        def assert_unauthorized!
          json_response.should == { "error" => "You are not authorized to perform that action." }
          response.status.should == 401
        end

        def stub_authentication!
          controller.stub :check_for_api_key
          Spree::LegacyUser.stub :find_by_spree_api_key => current_api_user
        end

        # This method can be overriden (with a let block) inside a context
        # For instance, if you wanted to have an admin user instead.
        def current_api_user
          @current_api_user ||= stub_model(Spree::LegacyUser, :email => "spree@example.com")
        end

        def image(filename)
          File.open(Spree::Api::Engine.root + "spec/fixtures" + filename)
        end

        def upload_image(filename)
          fixture_file_upload(image(filename).path)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
spree_api-1.3.5 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.4 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.3 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.5 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.4 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.2 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.3 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.1 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.0 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.0.rc2 lib/spree/api/testing_support/helpers.rb
dup_spree_api-1.3.0.rc1 lib/spree/api/testing_support/helpers.rb
spree_api-1.3.0.rc1 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.2 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.0 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.0.rc2 lib/spree/api/testing_support/helpers.rb
spree_api-1.2.0.rc1 lib/spree/api/testing_support/helpers.rb