Skip to content

Commit

Permalink
test new specs
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaLiao committed Jan 9, 2025
1 parent 544b3bb commit b50fc51
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 81 deletions.
60 changes: 30 additions & 30 deletions spec/views/comments/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }

before do
assign(:entry, entry)
assign(:comment, comment)
render
context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the heading" do
expect(rendered).to have_selector("h1", text: "Edit comment")
end

it "renders the form to edit comment" do
expect(rendered).to have_selector("form[action='#{entry_comment_path(entry, comment)}'][method='post']")
end

it "pre-fills the text area with the current comment" do
expect(rendered).to have_selector("textarea[name='comment[text]']", text: comment.text)
end

it "displays the submit button" do
expect(rendered).to have_selector("input[type='submit'][value='Update']")
end

it "has a link to show the comment" do
expect(rendered).to have_link('Show this comment', href: entry_comments_path(entry, comment))
end

it "has a link to go back to the comments index" do
expect(rendered).to have_link('Back to comment', href: entry_comments_path(entry))
end
end

xit "displays the heading" do
expect(rendered).to have_selector("h1", text: "Edit comment")
end

xit "renders the form to edit comment" do
expect(rendered).to have_selector("form[action='#{entry_comment_path(entry, comment)}'][method='post']")
end

xit "pre-fills the text area with the current comment" do
expect(rendered).to have_selector("textarea[name='comment[text]']", text: comment.text)
end

xit "displays the submit button" do
expect(rendered).to have_selector("input[type='submit'][value='Update']")
end

xit "has a link to show the comment" do
expect(rendered).to have_link('Show this comment', href: entry_comments_path(entry, comment))
end

xit "has a link to go back to the comments index" do
expect(rendered).to have_link('Back to comment', href: entry_comments_path(entry))
end


end
32 changes: 17 additions & 15 deletions spec/views/comments/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comments) { FactoryBot.create_list(:comment, 2, entry: entry, user: user) }

before do
assign(:entry, entry)
assign(:comments, comments)
render
end
context "web page text" do
before do
assign(:entry, entry)
assign(:comments, comments)
render
end

xit "displays the entry" do
expect(rendered).to include(entry.text)
end
it "displays the entry" do
expect(rendered).to include(entry.text)
end

xit "displays all comments for that entry" do
comments.each do |comment|
expect(rendered).to include(comment.user.email)
expect(rendered).to include(comment.text)
it "displays all comments for that entry" do
comments.each do |comment|
expect(rendered).to include(comment.user.email)
expect(rendered).to include(comment.text)
end
end
end

xit "displays a link back to the entry" do
expect(rendered).to have_link("Back to entry", href: entry_path(entry))
it "displays a link back to the entry" do
expect(rendered).to have_link("Back to entry", href: entry_path(entry))
end
end
end
24 changes: 13 additions & 11 deletions spec/views/comments/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
let(:entry) { FactoryBot.create(:entry, user: user) }
let!(:comment) { FactoryBot.create(:comment, entry: entry) }

before do
assign(:entry, entry)
assign(:comment, comment)
render
end
context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

xit "displays the new comment form" do
expect(rendered).to have_selector("h1", text: "New comment")
expect(rendered).to render_template(partial: "_form")
end
it "displays the new comment form" do
expect(rendered).to have_selector("h1", text: "New comment")
expect(rendered).to render_template(partial: "_form")
end

xit "renders a link back to comments index" do
expect(rendered).to have_link("Back to comments", href: comments_index_path)
it "renders a link back to comments index" do
expect(rendered).to have_link("Back to comments", href: comments_index_path)
end
end
end
51 changes: 26 additions & 25 deletions spec/views/comments/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@
let(:entry) { FactoryBot.create(:entry, user: friend) }
let!(:comment) { FactoryBot.create(:comment, entry: entry, user: user, text: "Test comment") }


before do
assign(:entry, entry)
assign(:comment, comment)
render
end

xit "displays the comment" do
expect(rendered).to include("Test comment")
end

xit "renders the partial for the comment" do
expect(rendered).to include(comment.text)
end

xit "displays the edit link" do
expect(rendered).to have_link("Edit", href: edit_entry_comment_path(entry, comment))
end

xit "displays the back to entry link" do
expect(rendered).to have_link("My Entries", href: entries_path)
end

xit "displays my friends entries" do
expect(rendered).to have_link("Friends Entries", href: friend_entries_path)
context "web page text" do
before do
assign(:entry, entry)
assign(:comment, comment)
render
end

it "displays the comment" do
expect(rendered).to include("Test comment")
end

it "renders the partial for the comment" do
expect(rendered).to include(comment.text)
end

it "displays the edit link" do
expect(rendered).to have_link("Edit", href: edit_entry_comment_path(entry, comment))
end

it "displays the back to entry link" do
expect(rendered).to have_link("My Entries", href: entries_path)
end

it "displays my friends entries" do
expect(rendered).to have_link("Friends Entries", href: friend_entries_path)
end
end
end

0 comments on commit b50fc51

Please sign in to comment.