module Spree::Api::TestingSupport::Helpers
Public Instance Methods
assert_not_found!()
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 16 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
current_api_user()
click to toggle source
This method can be overridden (with a let block) inside a context For instance, if you wanted to have an admin user instead.
# File lib/spree/api/testing_support/helpers.rb, line 32 def current_api_user @current_api_user ||= stub_model(Spree::LegacyUser, email: "solidus@example.com", spree_roles: []) end
image(filename)
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 36 def image(filename) File.open( File.join( Spree::Core::Engine.root, "lib", "spree", "testing_support", "fixtures", filename ) ) end
json_response()
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 7 def json_response case body = JSON.parse(response.body) when Hash body.with_indifferent_access when Array body end end
stub_authentication!()
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 26 def stub_authentication! allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user } end
upload_image(filename)
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 49 def upload_image(filename) Rack::Test::UploadedFile.new(File.open(image(filename).path), 'image/jpg') end