|
29 | 29 | end |
30 | 30 |
|
31 | 31 | describe "form submission functions" do |
32 | | - let(:comment) { Comment.new(author: "Author", text: "This is a comment") } |
| 32 | + let(:comment) { Comment.new(author: "Author", text: "This is a comment #{Time.zone.now}") } |
33 | 33 | let(:author_field) { "comment_author" } |
34 | 34 | let(:author_error) { "Author: can't be blank" } |
35 | 35 | let(:text_field) { "comment_text" } |
|
39 | 39 | visit "/stimulus" |
40 | 40 | end |
41 | 41 |
|
42 | | - it "adds a new comment to the page" do |
43 | | - fill_in author_field, with: comment.author |
44 | | - fill_in text_field, with: comment.text |
45 | | - click_button("Post") |
46 | | - expect(page).to have_selector "h2", text: comment.author |
47 | | - end |
48 | | - |
49 | | - it "comment count increases with successful form submission" do |
| 42 | + it "adds a new comment to the page and database" do |
50 | 43 | initital_comment_count = Comment.all.count |
51 | 44 | new_comment_count = initital_comment_count + 1 |
52 | 45 | fill_in author_field, with: comment.author |
53 | 46 | fill_in text_field, with: comment.text |
54 | 47 | click_button("Post") |
55 | | - sleep(1) |
| 48 | + |
| 49 | + expect(page).to have_css("h2", text: comment.author) |
| 50 | + expect(page).to have_css("p", text: comment.text) |
56 | 51 | expect(Comment.all.count).to equal(new_comment_count) |
57 | 52 | end |
58 | 53 |
|
59 | 54 | it "comment count remains the same when author field is empty" do |
60 | 55 | initial_comment_count = Comment.all.count |
61 | 56 | fill_in text_field, with: comment.text |
62 | 57 | click_button("Post") |
| 58 | + |
| 59 | + expect(page).to have_text("Author: can't be blank") |
63 | 60 | expect(Comment.all.count).to equal(initial_comment_count) |
64 | 61 | end |
65 | 62 |
|
66 | 63 | it "comment count remains the same when text field is empty" do |
67 | 64 | initial_comment_count = Comment.all.count |
68 | 65 | fill_in author_field, with: comment.author |
69 | 66 | click_button("Post") |
| 67 | + |
| 68 | + expect(page).to have_text("Text: can't be blank") |
70 | 69 | expect(Comment.all.count).to equal(initial_comment_count) |
71 | 70 | end |
72 | 71 |
|
73 | 72 | it "comment count remains the same when both form fields are empty" do |
74 | 73 | initial_comment_count = Comment.all.count |
75 | 74 | click_button("Post") |
| 75 | + |
| 76 | + expect(page).to have_text("Author: can't be blank") |
76 | 77 | expect(Comment.all.count).to equal(initial_comment_count) |
77 | 78 | end |
78 | 79 | end |
|
0 commit comments