module Spree::Api::TestingSupport::Helpers
Public Instance Methods
assert_not_found!()
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 14 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 overriden (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 30 def current_api_user @current_api_user ||= stub_model(Spree.user_class, email: 'spree@example.com') end
image(filename)
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 34 def image(filename) File.open(Spree::Api::Engine.root + 'spec/fixtures' + filename) end
json_response()
click to toggle source
# File lib/spree/api/testing_support/helpers.rb, line 5 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 24 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 38 def upload_image(filename) fixture_file_upload(image(filename).path, 'image/jpg') end