Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update test helpers

  • Loading branch information...
commit 1eb30b1f2d157fafdad46a66efe74320795e2b9d 1 parent 906d918
@josepjaume josepjaume authored
Showing with 21 additions and 8 deletions.
  1. +21 −8 lib/empresaula-api/test_helpers/user.rb
View
29 lib/empresaula-api/test_helpers/user.rb
@@ -6,15 +6,12 @@ module Empresaula
module API
module TestHelpers
module User
+
def mock_current_user(user)
cookies = Capybara.current_session.driver.browser.current_session.instance_variable_get(:@rack_mock_session).cookie_jar
cookies[:empresaula_session] = 'qwertyuiop123456789'
- ActiveResource::HttpMock.respond_to do |mock|
- mock.get "/api/users/qwertyuiop123456789.json", {},
- user.to_json
- mock.get "/api/users/#{user[:id]}.json", {},
- user.to_json
- end
+ add_mock '/api/users/qwertyuiop123456789.json', user
+ mock_user user
@current_user = Empresaula::API::Resource::User.find(user[:id])
end
@@ -23,9 +20,25 @@ def current_user
end
def mock_user(user)
+ add_mock "/api/users/#{user[:id]}.json", user
+ end
+
+ def add_mock(url, object, method = 'get')
+ @_mocks ||= {}
+ @_mocks[url] = {method: method, object: object}
+ perform_mocks!
+ end
+
+ def mocks
+ @_mocks || {}
+ end
+
+ def perform_mocks!
+ ActiveResource::HttpMock.reset!
ActiveResource::HttpMock.respond_to do |mock|
- mock.get "/api/users/#{user[:id]}.json", {},
- user.to_json
+ mocks.each do |k, v|
+ mock.send(v[:method], k, {}, v[:object].to_json)
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.