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



9
10
11
12
# File 'lib/spree/api/testing_support/helpers.rb', line 9

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



14
15
16
17
# File 'lib/spree/api/testing_support/helpers.rb', line 14

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.



25
26
27
# File 'lib/spree/api/testing_support/helpers.rb', line 25

def current_api_user
  @current_api_user ||= stub_model(Spree::LegacyUser, :email => "[email protected]")
end

#image(filename) ⇒ Object



29
30
31
# File 'lib/spree/api/testing_support/helpers.rb', line 29

def image(filename)
  File.open(Spree::Api::Engine.root + "spec/fixtures" + filename)
end

#json_responseObject



5
6
7
# File 'lib/spree/api/testing_support/helpers.rb', line 5

def json_response
  JSON.parse(response.body)
end

#stub_authentication!Object



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

def stub_authentication!
  Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
end

#upload_image(filename) ⇒ Object



33
34
35
# File 'lib/spree/api/testing_support/helpers.rb', line 33

def upload_image(filename)
  fixture_file_upload(image(filename).path)
end