forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_helper.rb
74 lines (60 loc) · 1.7 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
ENV['RACK_ENV'] = 'test'
require 'minitest/autorun'
require 'rack/test'
require 'yaml'
require 'database_cleaner'
require 'factory_girl'
require 'mocha'
require_relative 'factories'
require_relative '../rstatus'
module TestHelper
require 'capybara/dsl'
include Capybara
include Rack::Test::Methods
include Sinatra::UserHelper
OmniAuth.config.test_mode = true
def app() Rstatus end
def setup
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.start
end
def teardown
DatabaseCleaner.clean
end
def omni_mock(username, options={})
provider = (options[:provider] || :twitter).to_sym
return OmniAuth.config.add_mock(provider, {
:uid => options[:uid] || 12345,
:user_info => {
:name => "Joe Public",
:email => "[email protected]",
:nickname => username,
:urls => { :Website => "http://rstat.us" },
:description => "A description",
:image => "/images/something.png"
},
:credentials => {:token => "1234", :secret => "4567"}
})
end
def log_in(u, uid = 12345)
Author.any_instance.stubs(:valid_gravatar?).returns(:false)
omni_mock(u.username, {:uid => uid})
visit '/auth/twitter'
end
def log_in_fb(u, uid = 12345)
Author.any_instance.stubs(:valid_gravatar?).returns(:false)
omni_mock(u.username, {:uid => uid, :provider => :facebook})
visit '/auth/facebook'
end
def log_in_email(user)
User.stubs(:authenticate).returns(user)
visit "/login"
within("form") do
fill_in "username", :with => user.username
fill_in "password", :with => "anything"
end
click_button "Log in"
end
Capybara.app = Rstatus
end