Sha256: 2c74e52e0477e9ca0d3e50537fd194a71a723e2887b0d7f5d3f4fccf12d067c2

Contents?: true

Size: 1.32 KB

Versions: 27

Compression:

Stored size: 1.32 KB

Contents

module Spree
  module Api
    module TestingSupport
      module Helpers
        def json_response
          case body = JSON.parse(response.body)
          when Hash
            body.with_indifferent_access
          when Array
            body
          end
        end

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

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

        def stub_authentication!
          allow(Spree.user_class).to receive(: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, 'image/jpg')
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
solidus_api-1.0.7 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.6 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.5 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.4 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.3 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.2 lib/spree/api/testing_support/helpers.rb
spree_api-2.4.10 lib/spree/api/testing_support/helpers.rb
spree_api-2.3.13 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.1 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0.rc2 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0.rc1 lib/spree/api/testing_support/helpers.rb
spree_api-2.4.9 lib/spree/api/testing_support/helpers.rb
spree_api-2.3.12 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0.pre3 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0.pre2 lib/spree/api/testing_support/helpers.rb
spree_api-2.4.8 lib/spree/api/testing_support/helpers.rb
spree_api-2.3.11 lib/spree/api/testing_support/helpers.rb
solidus_api-1.0.0.pre lib/spree/api/testing_support/helpers.rb
spree_api-2.4.7 lib/spree/api/testing_support/helpers.rb