|
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 |
|
39 | 38 | end |
40 | 39 |
|
41 | 40 | scenario 'reply to a comment', :js do |
42 | | - project = create(:idea, :with_comments, originator: user) |
43 | | - reply_text = 'You are wrong on the internet!' |
44 | | - first_comment = project.comments.first |
| 41 | + visit project_path(nil, project_with_comments) |
45 | 42 |
|
46 | | - visit project_path(nil, project) |
47 | | - |
48 | | - within("li#comment_#{first_comment.id}") do |
| 43 | + within("#comment_#{project_with_comments.comments.first.id}") do |
49 | 44 | click_on 'Reply' |
50 | 45 | end |
51 | 46 |
|
52 | | - within("#replyCommentcomment_#{first_comment.id}") do |
53 | | - 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!' |
54 | 49 | end |
55 | 50 |
|
56 | | - within("#replyCommentcomment_#{first_comment.id}") do |
| 51 | + within("#replyCommentcomment_#{project_with_comments.comments.first.id}") do |
57 | 52 | click_on 'Create Comment' |
58 | 53 | end |
59 | 54 |
|
60 | | - within("#comment_#{first_comment.id}") do |
61 | | - expect(page).to have_text reply_text |
| 55 | + within("#comment_#{project_with_comments.comments.first.id}") do |
| 56 | + expect(page).to have_text 'You are wrong on the internet!' |
62 | 57 | end |
63 | 58 | end |
64 | 59 |
|
65 | 60 | scenario 'update', :js do |
66 | | - project = create(:idea, originator: user) |
67 | 61 | comment = create(:comment, commenter: user, commentable: project) |
68 | | - update_text = Faker::Lorem.sentence |
69 | 62 |
|
70 | 63 | visit project_path(nil, project) |
71 | 64 |
|
|
74 | 67 | end |
75 | 68 |
|
76 | 69 | within("#editCommentcomment_#{comment.id}") do |
77 | | - fill_in 'comment_text', with: update_text |
| 70 | + fill_in 'comment_text', with: comment_text |
78 | 71 | click_on 'Update Comment' |
79 | 72 | end |
80 | 73 |
|
81 | 74 | within("li#comment_#{comment.id}") do |
82 | | - expect(page).to have_text update_text |
| 75 | + expect(page).to have_text comment_text |
83 | 76 | end |
84 | 77 | end |
85 | 78 | end |
0 commit comments