forked from technoweenie/restful-authentication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticated_test_helper.rb
28 lines (24 loc) · 1.14 KB
/
authenticated_test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module AuthenticatedTestHelper
# Sets the current <%= file_name %> in the session from the <%= file_name %> fixtures.
def login_as(<%= file_name %>)
@request.session[:<%= file_name %>] = <%= file_name %> ? <%= table_name %>(<%= file_name %>).id : nil
end
def authorize_as(user)
@request.env["HTTP_AUTHORIZATION"] = user ? "Basic #{Base64.encode64("#{users(user).login}:test")}" : nil
end
<% unless has_rspec? %>
# taken from edge rails / rails 2.0. Only needed on Rails 1.2.3
def assert_difference(expressions, difference = 1, message = nil, &block)
expression_evaluations = [expressions].flatten.collect{|expression| lambda { eval(expression, block.binding) } }
original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
yield
expression_evaluations.each_with_index do |expression, i|
assert_equal original_values[i] + difference, expression.call, message
end
end
# taken from edge rails / rails 2.0. Only needed on Rails 1.2.3
def assert_no_difference(expressions, message = nil, &block)
assert_difference expressions, 0, message, &block
end
<% end %>
end