user_test.rb
1.71 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
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < ActiveSupport::TestCase
should 'find with omniauth params' do
user = fast_create(User)
user.settings[:oauth_providers] = [:test => {}]
user.save!
auth = {:info => OpenStruct.new({:email => user.email})}
assert_equal user, User.find_with_omniauth(OpenStruct.new(auth))
end
should 'do not return user if there is no provider' do
user = fast_create(User)
auth = {:info => OpenStruct.new({:email => user.email})}
assert_equal nil, User.find_with_omniauth(OpenStruct.new(auth))
end
should 'password is not required if there is a oauth provider' do
User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [:test])
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 => [:test])
assert user.activated?
end
should 'not activate user when created without oauth' do
user = fast_create(User)
assert !user.activated?
end
should 'not make activation code when created with oauth' do
user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [:test])
assert !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
end