Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author name links to author show page #28 #49

Merged
merged 5 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/views/books/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p>Author(s):</p>
<ul>
<% book.authors.each do |author| %>
<li><%= link_to author.name %></li>
<li><%= link_to author.name, author_path(author) %></li>
<% end %>
</ul>
<p>Average rating: <%= book.average_rating %> out of 5</p>
Expand Down
8 changes: 4 additions & 4 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
<p>Author(s):</p>
<ul class="authors">
<% @book.authors.each do |author| %>
<li><%= link_to author.name %></li>
<li><%= link_to author.name, author_path(author) %></li>
<% end %>
</ul>
<section class="book-stats">
<% unless @book.reviews.empty? %>
<section class="top-reviews">
<p>Top Reviews</p>
<%= @book.grab_reviews('top', 3).each do |review| %>
<% @book.grab_reviews('top', 3).each do |review| %>
<p>Title: <%= review.title %>, Rating: <%= review.rating %>, User: <%= link_to review.username %></p>
<% end %>
</section>

<section class="bottom-reviews">
<p>Bottome Reviews</p>
<%= @book.grab_reviews('bottom', 3).each do |review| %>
<p>Bottom Reviews</p>
<% @book.grab_reviews('bottom', 3).each do |review| %>
<p>Title: <%= review.title %>, Rating: <%= review.rating %>, User: <%= link_to review.username %></p>
<% end %>
<% else %>
Expand Down
17 changes: 16 additions & 1 deletion spec/features/author_show_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe 'As a visitor', type: :feature do
RSpec.describe 'As a visitor to an author show page', type: :feature do
it 'shows all books by that author' do
author = Author.create(name: 'Bob')
book_1 = author.books.create(thumbnail: 'steve.jpg', title: 'book title 1', pages: 40, year_published: 1987)
Expand Down Expand Up @@ -60,4 +60,19 @@
expect(page).to have_link("Steve")
end
end

it 'shows co authors as links to their author show page' do
author = Author.create(name: 'Bob')
author_2 = Author.create(name: 'Monkey')
author_3 = Author.create(name: 'Steve')
book_1 = author.books.create(thumbnail: 'steve.jpg', title: 'book title 1', pages: 40, year_published: 1987)
book_2 = Book.create(thumbnail: 'andrew.jpg', title: 'book title 2', pages: 456, year_published: 1978, authors: [author, author_2, author_3])

visit author_path(author)

within "#book-#{book_2.id}" do
expect(page).to have_link("Monkey", href: author_path(author_2))
expect(page).to have_link("Steve", href: author_path(author_3))
end
end
end
8 changes: 4 additions & 4 deletions spec/features/book_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
expect(page).to have_link("where the wild things are", href: book_path(book_1))
expect(page).to have_content("Page Count: #{book_1.pages}")
expect(page).to have_content("Year Published: 1987")
expect(page).to have_link(author.name)
expect(page).to have_link(author.name, href: author_path(author))
end

within "#book-#{book_2.id}" do
expect(page).to have_xpath("//img[@src='bob.jpg']")
expect(page).to have_link("Whatever", href: book_path(book_2))
expect(page).to have_content("Page Count: 230")
expect(page).to have_content("Year Published: 2019")
expect(page).to have_link("bob")
expect(page).to have_link("bob", href: author_path(author))
end

within "#book-#{book_3.id}" do
expect(page).to have_xpath("//img[@src='andrew.jpg']")
expect(page).to have_link("meh", href: book_path(book_3))
expect(page).to have_content("Page Count: 456")
expect(page).to have_content("Year Published: 1978")
expect(page).to have_link("bob")
expect(page).to have_link("monkey")
expect(page).to have_link("bob", href: author_path(author))
expect(page).to have_link("monkey", href: author_path(author_2))
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/features/book_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
expect(page).to have_content("Title: Where The Wild Things Are")
expect(page).to have_content("Page Count: 40")
expect(page).to have_content("Year Published: 1987")
expect(page).to have_content("Author 1 name")
expect(page).to have_content("Author 2 name")
expect(page).to have_link("Author 1 name", href: author_path(author_1))
expect(page).to have_link("Author 2 name", href: author_path(author_2))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about being able to call the href in the expects. That's going to be really handy.

end
end

Expand Down Expand Up @@ -115,7 +115,7 @@
book = author.books.create(thumbnail: 'steve.jpg', title: 'where the wild things are', pages: 40, year_published: 1987)

visit book_path(book)

expect(page).to_not have_content("Top Reviews")
expect(page).to_not have_content("Bottom Reviews")
expect(page).to have_link("Be the first to review this book")
Expand Down