forked from harley/newstc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_helper.rb
74 lines (65 loc) · 2.18 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
require "test/unit"
require "rubygems"
require "ruby-debug"
require "active_record"
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
ActiveRecord::Base.configurations = true
ActiveRecord::Schema.define(:version => 1) do
create_table :users do |t|
t.datetime :created_at
t.datetime :updated_at
t.integer :lock_version, :default => 0
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 :oauth_token
t.string :oauth_secret
t.string :email
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
end
end
require "active_record/fixtures"
require "action_controller"
require "oauth"
Rails = true # to trick authlogic into loading the rails adapter
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic"
require File.dirname(__FILE__) + "/../../authlogic/lib/authlogic/test_case"
require File.dirname(__FILE__) + '/../lib/authlogic_oauth' unless defined?(AuthlogicOauth)
require File.dirname(__FILE__) + '/lib/user'
require File.dirname(__FILE__) + '/lib/user_session'
class ActionController::Base
def redirecting_to
@redirect_to
end
def redirect_to(*args)
@redirect_to = args
end
end
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
def activate_authlogic
Authlogic::Session::Base.controller = controller
end
def controller
@controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController::Base.new)
end
def redirecting_to_oauth?
controller.redirecting_to.to_s =~ /^http:\/\/example.com/
end
end