|
2 | 2 |
|
3 | 3 | feature 'Comment' do |
4 | 4 | let(:user) { create :user } |
| 5 | + let(:project) { create(:idea, originator: user) } |
| 6 | + let(:project_with_comments) { create(:idea, :with_comments, originator: user) } |
| 7 | + let(:comment_text) { Faker::Lorem.sentence } |
5 | 8 |
|
6 | 9 | before :each do |
7 | 10 | sign_in user |
8 | 11 | end |
9 | 12 |
|
10 | 13 | scenario 'markdown preview', :js do |
11 | | - project = create(:invention, originator: user, users: [user]) |
12 | | - |
13 | 14 | visit project_path(:all, project) |
14 | 15 | fill_in 'comment_text', with: '_italic_ **bold** :smile: @user' |
15 | 16 | click_on 'Preview' |
|
21 | 22 | end |
22 | 23 |
|
23 | 24 | scenario 'create', :js do |
24 | | - project = create(:idea, originator: user) |
25 | | - comment_text = Faker::Lorem.sentence |
26 | | - |
27 | 25 | visit project_path(nil, project) |
| 26 | + |
28 | 27 | within('#comments_form_section') do |
29 | 28 | fill_in 'comment_text', with: comment_text |
30 | 29 | end |
31 | 30 |
|
32 | | - expect do |
33 | | - within('#comments_form_section') do |
34 | | - click_on 'Create Comment' |
35 | | - end |
36 | | - end.to change(project.comments, :count).by(1) |
37 | | - expect(page).to have_text comment_text |
| 31 | + within('#comments_form_section') do |
| 32 | + click_on 'Create Comment' |
| 33 | + end |
| 34 | + |
| 35 | + within('#comments_section') do |
| 36 | + expect(page).to have_text comment_text |
| 37 | + end |
38 | 38 | end |
39 | 39 |
|
40 | 40 | scenario 'reply to a comment', :js do |
41 | | - project = create(:idea, :with_comments, originator: user) |
42 | | - reply_text = 'You are wrong on the internet!' |
43 | | - first_comment = project.comments.first |
| 41 | + visit project_path(nil, project_with_comments) |
44 | 42 |
|
45 | | - visit project_path(nil, project) |
46 | | - |
47 | | - within("li#comment_#{first_comment.id}") do |
| 43 | + within("#comment_#{project_with_comments.comments.first.id}") do |
48 | 44 | click_on 'Reply' |
49 | 45 | end |
50 | 46 |
|
51 | | - within("#replyCommentcomment_#{first_comment.id}") do |
52 | | - fill_in 'comment_text', with: reply_text |
| 47 | + within("#replyCommentcomment_#{project_with_comments.comments.first.id}") do |
| 48 | + fill_in 'comment_text', with: 'You are wrong on the internet!' |
| 49 | + end |
| 50 | + |
| 51 | + within("#replyCommentcomment_#{project_with_comments.comments.first.id}") do |
| 52 | + click_on 'Create Comment' |
53 | 53 | end |
54 | 54 |
|
55 | | - expect do |
56 | | - within("#replyCommentcomment_#{first_comment.id}") do |
57 | | - click_on 'Create Comment' |
58 | | - end |
59 | | - end.to change(first_comment.comments, :count).by(1) |
| 55 | + within("#comment_#{project_with_comments.comments.first.id}") do |
| 56 | + expect(page).to have_text 'You are wrong on the internet!' |
| 57 | + end |
60 | 58 | end |
61 | 59 |
|
62 | 60 | scenario 'update', :js do |
63 | | - project = create(:idea, originator: user) |
64 | 61 | comment = create(:comment, commenter: user, commentable: project) |
65 | | - update_text = Faker::Lorem.sentence |
66 | 62 |
|
67 | 63 | visit project_path(nil, project) |
68 | 64 |
|
|
71 | 67 | end |
72 | 68 |
|
73 | 69 | within("#editCommentcomment_#{comment.id}") do |
74 | | - fill_in 'comment_text', with: update_text |
| 70 | + fill_in 'comment_text', with: comment_text |
75 | 71 | click_on 'Update Comment' |
76 | 72 | end |
77 | 73 |
|
78 | 74 | within("li#comment_#{comment.id}") do |
79 | | - expect(page).to have_text update_text |
| 75 | + expect(page).to have_text comment_text |
80 | 76 | end |
81 | 77 | end |
82 | 78 | end |
0 commit comments