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
|
# frozen_string_literal: true
require 'test_helper'
class Posts::CommentsControllerTest < ActionController::TestCase
def setup
@image = create(:post)
@request.cookies['_ses'] = 'c1836832948'
end
def setup_user
@user = create(:user)
sign_in @user
end
test 'should post a comment anonymously' do
post :create, params: { image_id: @image.id, comment: {
body: 'Test body',
anonymous: false
} }
@image.reload
assert_response :redirect
assert_redirected_to post_path(@image, anchor: "comment_#{@image.comments.first.id}")
assert_equal 'Test body', @image.comments.first.body
end
test 'should post a comment for a user' do
setup_user
post :create, params: { image_id: @image.id, comment: {
body: 'Test body',
anonymous: false
} }
@image.reload
assert_response :redirect
assert_redirected_to post_path(@image, anchor: "comment_#{@image.comments.first.id}")
assert_equal @user, @image.comments.first.user
assert_equal 'Test body', @image.comments.first.body
end
test 'should allow anonymous posting' do
setup_user
post :create, params: { image_id: @image.id, comment: {
body: 'Test body',
anonymous: true
} }
@image.reload
assert_response :redirect
assert_redirected_to post_path(@image, anchor: "comment_#{@image.comments.first.id}")
assert_equal @user, @image.comments.first.user
assert @image.comments.first.anonymous
assert_equal 'Test body', @image.comments.first.body
end
end
|