user_test.rb
2.82 KB
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
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@provider = OauthClientPlugin::Provider.create!(:name => 'name', :strategy => 'strategy')
end
attr_reader :provider
should 'password is not required if there is a oauth provider' do
User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider])
end
should 'password is required if there is a oauth provider' do
user = User.new(:email => 'testoauth@example.com', :login => 'testoauth')
user.save
assert user.errors[:password].present?
end
should 'activate user when created with oauth' do
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider])
assert user.activated?
end
should 'not activate user when created without oauth' do
user = fast_create(User)
refute user.activated?
end
should 'not make activation code when created with oauth' do
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider])
refute user.activation_code
end
should 'make activation code when created without oauth' do
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :password => 'test', :password_confirmation => 'test')
assert user.activation_code
end
should 'not send activation email when created with oauth' do
UserMailer.expects(:activation_code).never
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider])
end
should 'save oauth data when create with oauth' do
OauthClientPlugin::SignupDataStore.stubs(:get_oauth_data).returns({
:provider_id => provider.id,
:credentials => {
token: 'abcdef',
any_field: 'abx'
}
})
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token')
user.oauth_signup_token = 'token'
assert user.oauth_user_providers.first.oauth_data.present?
end
should 'save oauth as a hash when creating user with oauth' do
OauthClientPlugin::SignupDataStore.stubs(:get_oauth_data)
.returns(
{
:provider_id => provider.id,
:credentials => {
token: 'abcdef',
any_field: 'abx'
}
}
)
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token')
assert user.oauth_user_providers.first.oauth_data.is_a? Hash
end
should 'note save oauth user provider when user is not originated from oauth' do
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :password => 'test', :password_confirmation => 'test')
assert user.oauth_user_providers.count.eql? 0
end
end