1
1
require "rails_helper"
2
2
3
3
feature "User sign up" do
4
- let ( :username ) { "user1234" }
4
+ let ( :email ) { "[email protected] " }
5
+ let ( :name ) { "name" }
5
6
6
7
def click_submit
7
8
click_button "Create account"
@@ -12,14 +13,16 @@ def click_submit
12
13
13
14
expect ( page ) . to have_text "Create an account"
14
15
15
- fill_in "user_username" , with : username
16
+ fill_in "user_name" , with : name
17
+ fill_in "user_email" , with : email
16
18
fill_in "user_password" , with : "securepassword"
17
19
18
20
expect { click_submit } . to change { User . count } . by 1
19
21
20
22
new_user = User . last
21
23
22
- expect ( new_user . username ) . to eq username
24
+ expect ( new_user . name ) . to eq name
25
+ expect ( new_user . email ) . to eq email
23
26
expect ( new_user . password_digest ) . to_not be nil
24
27
expect ( current_path ) . to eq user_path ( new_user )
25
28
end
@@ -28,38 +31,41 @@ def click_submit
28
31
it "does not allow the user to submit the form" do
29
32
visit new_user_path
30
33
31
- fill_in "user_username" , with : username
34
+ fill_in "user_email" , with : email
35
+ fill_in "user_name" , with : name
32
36
click_submit
33
37
34
38
expect ( page ) . to have_text "Password can't be blank"
35
39
end
36
40
end
37
41
38
- context "no username is provided" do
42
+ context "no email is provided" do
39
43
it "does not allow the user to submit the form" do
40
44
visit new_user_path
41
45
46
+ fill_in "user_name" , with : name
42
47
fill_in "user_password" , with : "password"
43
48
click_submit
44
49
45
- expect ( page ) . to have_text "Username can't be blank"
50
+ expect ( page ) . to have_text "Email can't be blank"
46
51
end
47
52
end
48
53
49
- context "username has already been taken" do
54
+ context "email has already been taken" do
50
55
before do
51
- User . create! ( username : username , password : "password" )
56
+ create ( :user , email : email )
52
57
end
53
58
54
- it "prompts the user to choose another username " do
59
+ it "prompts the user to choose another email " do
55
60
visit new_user_path
56
61
57
- fill_in "user_username" , with : username
62
+ fill_in "user_name" , with : name
63
+ fill_in "user_email" , with : email
58
64
fill_in "user_password" , with : "securepassword"
59
65
60
66
click_submit
61
67
62
- expect ( page ) . to have_text "Username \" #{ username } \" is already taken. Please choose another! "
68
+ expect ( page ) . to have_text "An account with that email has already been created. "
63
69
end
64
70
end
65
71
end
0 commit comments