/
users_spec.rb
66 lines (59 loc) · 1.94 KB
/
users_spec.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'spec_helper'
describe "Users" do
describe "signup" do
describe "failure" do
it "should not make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template('users/new')
response.should have_selector('div#error_explanation')
end.should_not change(User, :count)
end
end
describe "success" do
it "should make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => "Example User"
fill_in "Email", :with => "user@example.com"
fill_in "Password", :with => "foobar"
fill_in "Confirmation", :with => "foobar"
click_button
response.should have_selector('div.flash.success',
:content => "Welcome")
response.should render_template('users/show')
end.should change(User, :count).by(1)
end
end
end
describe "signin" do
describe "failure" do
it "should not sign a user in" do
visit signin_path
fill_in "Email", :with => ""
fill_in "Password", :with => ""
click_button
response.should have_selector('div.flash.error',
:content => "Invalid")
response.should render_template('sessions/new')
end
end
describe "success" do
it "should sign a user in and out" do
user = Factory(:user)
visit signin_path
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button
controller.should be_signed_in
click_link "Sign out"
controller.should_not be_signed_in
end
end
end
end