Module: Spree::Api::TestingSupport::Helpers

Defined in:
lib/spree/api/testing_support/helpers.rb

Instance Method Summary collapse

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!
  json_response.should == { "error" => "The resource you were looking for could not be found." }
  response.status.should == 404
end

#assert_unauthorized!Object



19
20
21
22
# File 'lib/spree/api/testing_support/helpers.rb', line 19

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

#current_api_userObject

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::LegacyUser, :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_responseObject



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!
  Spree::LegacyUser.stub(: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