forked from binarylogic/authlogic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_helper.rb
182 lines (158 loc) · 5.16 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
require "test/unit"
require "rubygems"
require "ruby-debug"
require "active_record"
require "active_record/fixtures"
# A temporary fix to bring active record errors up to speed with rails edge.
# I need to remove this once the new gem is released. This is only here so my tests pass.
unless defined?(::ActiveModel)
class ActiveRecord::Errors
def [](key)
value = on(key)
value.is_a?(Array) ? value : [value].compact
end
end
end
ActiveRecord::Schema.verbose = false
begin
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
rescue ArgumentError
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
end
ActiveRecord::Base.configurations = true
ActiveRecord::Schema.define(:version => 1) do
create_table :companies do |t|
t.datetime :created_at
t.datetime :updated_at
t.string :name
t.boolean :active
end
create_table :projects do |t|
t.datetime :created_at
t.datetime :updated_at
t.string :name
end
create_table :projects_users, :id => false do |t|
t.integer :project_id
t.integer :user_id
end
create_table :users do |t|
t.datetime :created_at
t.datetime :updated_at
t.integer :lock_version, :default => 0
t.integer :company_id
t.string :login
t.string :crypted_password
t.string :password_salt
t.string :persistence_token
t.string :single_access_token
t.string :perishable_token
t.string :email
t.string :first_name
t.string :last_name
t.integer :login_count, :default => 0, :null => false
t.integer :failed_login_count, :default => 0, :null => false
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
t.boolean :active, :default => true
t.boolean :approved, :default => true
t.boolean :confirmed, :default => true
end
create_table :employees do |t|
t.datetime :created_at
t.datetime :updated_at
t.integer :company_id
t.string :email
t.string :crypted_password
t.string :password_salt
t.string :persistence_token
t.string :first_name
t.string :last_name
t.integer :login_count, :default => 0, :null => false
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
end
create_table :affiliates do |t|
t.datetime :created_at
t.datetime :updated_at
t.integer :company_id
t.string :username
t.string :pw_hash
t.string :pw_salt
t.string :persistence_token
end
create_table :ldapers do |t|
t.datetime :created_at
t.datetime :updated_at
t.string :ldap_login
t.string :persistence_token
end
end
require File.dirname(__FILE__) + '/../lib/authlogic' unless defined?(Authlogic)
require File.dirname(__FILE__) + '/../lib/authlogic/test_case'
require File.dirname(__FILE__) + '/libs/project'
require File.dirname(__FILE__) + '/libs/affiliate'
require File.dirname(__FILE__) + '/libs/employee'
require File.dirname(__FILE__) + '/libs/employee_session'
require File.dirname(__FILE__) + '/libs/ldaper'
require File.dirname(__FILE__) + '/libs/user'
require File.dirname(__FILE__) + '/libs/user_session'
require File.dirname(__FILE__) + '/libs/company'
Authlogic::CryptoProviders::AES256.key = "myafdsfddddddddddddddddddddddddddddddddddddddddddddddd"
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
self.fixture_path = File.dirname(__FILE__) + "/fixtures"
self.use_transactional_fixtures = false
self.use_instantiated_fixtures = false
self.pre_loaded_fixtures = false
fixtures :all
setup :activate_authlogic
private
def password_for(user)
case user
when users(:ben)
"benrocks"
when users(:zack)
"zackrocks"
end
end
def http_basic_auth_for(user = nil, &block)
unless user.blank?
controller.http_user = user.login
controller.http_password = password_for(user)
end
yield
controller.http_user = controller.http_password = nil
end
def set_cookie_for(user, id = nil)
controller.cookies["user_credentials"] = {:value => user.persistence_token, :expires => nil}
end
def unset_cookie
controller.cookies["user_credentials"] = nil
end
def set_params_for(user, id = nil)
controller.params["user_credentials"] = user.single_access_token
end
def unset_params
controller.params["user_credentials"] = nil
end
def set_request_content_type(type)
controller.request_content_type = type
end
def unset_request_content_type
controller.request_content_type = nil
end
def set_session_for(user, id = nil)
controller.session["user_credentials"] = user.persistence_token
controller.session["user_credentials_id"] = user.id
end
def unset_session
controller.session["user_credentials"] = controller.session["user_credentials_id"] = nil
end
end