cirandas.net

ref: master

plugins/oauth_client/test/unit/user_test.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
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 'associate the oauth provider with the created user' do
    user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [provider])
    assert_equal user.oauth_providers.reload, [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

end