cirandas.net

ref: master

test/integration/user_registers_at_the_application_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
require_relative "../test_helper"

class UserRegistersAtTheApplicationTest < ActionDispatch::IntegrationTest
  fixtures :users, :environments, :profiles

  def test_successfull_registration
    get '/'
    assert_can_login
    assert_can_signup

    get '/account/signup'

    assert_response :success

    post '/account/signup', :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' }
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => /^\/account\/login/ }
  end

  def test_trying_an_existing_login_name
    env = Environment.default
    env.min_signup_delay = 0
    env.save!

    assert User.find_by(login: 'ze') # just to make sure that 'ze' already exists

    get '/'
    assert_can_login
    assert_can_signup

    get '/account/signup'

    assert_response :success

    post '/account/signup', :user => { :login => 'ze', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' }
    assert_response :success
    assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation', :class => 'errorExplanation' }

  end

end