Sha256: 54e926cf417a10518a1126c00c0bfb1c75dcdf609e756d1cab58ab5c5ba20ed0

Contents?: true

Size: 1.16 KB

Versions: 16

Compression:

Stored size: 1.16 KB

Contents

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

        def assert_not_found!
          json_response.should == { "error" => "The resource you were looking for could not be found." }
          response.status.should == 404
        end

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

        def stub_authentication!
          Spree::LegacyUser.stub(:find_by).with(hash_including(: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 & 1 rubygems

Version Path
spree_api-2.2.9 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.12 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.8 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.11 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.7 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.10 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.9 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.6 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.5 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.8 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.4 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.3 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.2 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.7 lib/spree/api/testing_support/helpers.rb
spree_api-2.1.6 lib/spree/api/testing_support/helpers.rb
spree_api-2.2.1 lib/spree/api/testing_support/helpers.rb