Module: Spree::Api::TestingSupport::Helpers
- Defined in:
- lib/spree/api/testing_support/helpers.rb
Instance Method Summary collapse
- #assert_not_found! ⇒ Object
- #assert_unauthorized! ⇒ Object
-
#current_api_user ⇒ Object
This method can be overriden (with a let block) inside a context For instance, if you wanted to have an admin user instead.
- #image(filename) ⇒ Object
- #json_response ⇒ Object
- #stub_authentication! ⇒ Object
- #upload_image(filename) ⇒ Object
Instance Method Details
#assert_not_found! ⇒ Object
14 15 16 17 |
# 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 |
#assert_unauthorized! ⇒ Object
19 20 21 22 |
# File 'lib/spree/api/testing_support/helpers.rb', line 19 def expect(json_response).to eq('error' => 'You are not authorized to perform that action.') expect(response.status).to eq 401 end |
#current_api_user ⇒ Object
This method can be overriden (with a let block) inside a context For instance, if you wanted to have an admin user instead.
30 31 32 |
# File 'lib/spree/api/testing_support/helpers.rb', line 30 def current_api_user @current_api_user ||= stub_model(Spree.user_class, email: '[email protected]') end |
#image(filename) ⇒ Object
34 35 36 |
# 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 ⇒ Object
5 6 7 8 9 10 11 12 |
# 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! ⇒ Object
24 25 26 |
# 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) ⇒ Object
38 39 40 |
# File 'lib/spree/api/testing_support/helpers.rb', line 38 def upload_image(filename) fixture_file_upload(image(filename).path, 'image/jpg') end |