clearance 0.10.3.2 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of clearance might be problematic. Click here for more details.

data/test/test_helper.rb DELETED
@@ -1,59 +0,0 @@
1
- ENV["RAILS_ENV"] ||= "test"
2
-
3
- PROJECT_ROOT = File.expand_path("../..", __FILE__)
4
- $LOAD_PATH << File.join(PROJECT_ROOT, "lib")
5
-
6
- require 'rails/all'
7
- Bundler.require
8
-
9
- require 'diesel/testing'
10
- require 'rails/test_help'
11
-
12
- require 'clearance'
13
- require 'clearance/shoulda_macros'
14
-
15
- Clearance.configure do |config|
16
- end
17
-
18
- class ApplicationController < ActionController::Base
19
- include Clearance::Authentication
20
- end
21
-
22
- class User < ActiveRecord::Base
23
- include Clearance::User
24
- end
25
-
26
- class ActiveSupport::TestCase
27
- self.use_transactional_fixtures = true
28
- self.use_instantiated_fixtures = false
29
-
30
- def self.should_set_cookie(name, value, should_expire_at)
31
- description = "set a '#{name}' cookie to '#{value}'"
32
- if should_expire_at
33
- description << " expiring at #{should_expire_at}"
34
- else
35
- description << " with no expiration date (session cookie)"
36
- end
37
- should description do
38
- assert_equal value, cookies[name]
39
- # the following statement may be redundant with the preceding one, but can't hurt
40
- assert_equal value, @response.cookies[name]
41
- # cookies and @response[cookies] don't give us the expire time, so we need to fish it out 'manually'
42
- set_cookie_headers = @response.headers['Set-Cookie']
43
- assert_not_nil set_cookie_headers, "@response.headers['Set-Cookie'] must not be nil"
44
- set_cookie_headers = [set_cookie_headers] if set_cookie_headers.respond_to?(:to_str)
45
- regex = /^#{name}=#{value}(;|$)/
46
- assert_contains set_cookie_headers, regex
47
- cookie = set_cookie_headers.find {|h| h =~ regex}
48
- regex = /; expires=(.*?)(;|$)/
49
- if should_expire_at
50
- assert_contains cookie, regex, "cookie does not contain an 'expires=' attribute"
51
- cookie =~ regex
52
- expires_at = Time.parse($1)
53
- assert_in_delta should_expire_at, expires_at, 100 # number of seconds we don't expect the test suite to exceed
54
- else
55
- assert_does_not_contain cookie, regex, "cookie contains an 'expires=' attribute but it shouldn't"
56
- end
57
- end
58
- end
59
- end