forked from vikingeducation/project_danebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchris_example_test.rb
57 lines (48 loc) · 1.61 KB
/
chris_example_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
46
47
48
49
50
51
52
53
54
55
56
57
describe 'POST #create' do
let(:post_create_post) do
post :create, :user_id => user.id,
:post => attributes_for(
:post,
:user_id => user.id
)
end
let(:post_create_invalid) do
post :create, :user_id => user.id,
:post => attributes_for(
:post,
:body => ''
)
end
context 'the user is signed in' do
it 'creates a new post when valid' do
expect {post_create_post}.to change(Post, :count).by(1)
end
it 'sets a success flash when valid' do
post_create_post
expect(flash[:success]).to_not be_nil
end
it 'does not create a post when invalid' do
expect {post_create_invalid}.to change(Post, :count).by(0)
end
it 'sets an error flash when invalid' do
post_create_invalid
expect(flash[:error]).to_not be_nil
end
end
context 'the user is signed out' do
before do
logout
end
it 'does not create a post' do
expect {post_create_post}.to change(Post, :count).by(0)
end
it 'redirects to root' do
post_create_post
expect(response).to redirect_to root_path
end
it 'sets an error flash' do
post_create_post
expect(flash[:error]).to_not be_nil
end
end
end