concept " Edit Ticket " link in category rails

appears as: “Edit Ticket” link, n “Edit Ticket” link
Rails 4 in Action: Revised Edition of Rails 3 in Action

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.

To fix this, add the “Edit Ticket” link to the show template of the TicketsController, because that’s the page you’ve visited in the feature. It sounds like an action link for the ticket, so you can add a list of action links into the header that specifies the ticket’s name:

4.  Hide the “Edit Ticket” link in your view.

If you really wanted to make sure that you only display the link if the user is allowed to update the ticket, a better fit would be a view test. We don’t cover view testing in this book, but the idea is that you write two specs that manually render the ticket’s show.html.erb view, which holds the “Edit Ticket” link. In one spec, policy(@ticket) .update? would be stubbed out to return true, and you’d verify that the link is shown. In the other, policy(@ticket).update? would be stubbed out to return false, and you’d verify that the link is not shown.

Open spec/features/hidden_links_spec.rb and add some new scenarios for testing the presence of the “Edit Ticket” link.

Listing 8.59. Testing the presence or absence of the “Edit Ticket” link
RSpec.feature "Users can only see the appropriate links" do ... let(:ticket) do FactoryGirl.create(:ticket, project: project, author: user) end context "non-admin users (project viewers)" do ... scenario "cannot see the Edit Ticket link" do visit project_ticket_path(project, ticket) expect(page).not_to have_link "Edit Ticket" end end context "admin users" do ... scenario "can see the Edit Ticket link" do visit project_ticket_path(project, ticket) expect(page).to have_link "Edit Ticket" end end end