Skip to content

Commit

Permalink
Add hyperlink to show resource from collection table (thoughtbot#727)
Browse files Browse the repository at this point in the history
Allows a resource to be shown without javascript enabled
(which uses "data-url" attrs). Also facilitates faster tests using RackTest.
  • Loading branch information
odlp authored and fwolfst committed Mar 8, 2017
1 parent 8219bb4 commit 922fb48
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/administrate/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@
.table__action--destroy {
color: $light-red;
}

.table__link-plain {
color: inherit;

&:hover {
color: inherit;
}
}
6 changes: 5 additions & 1 deletion app/views/administrate/application/_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ to display a collection of resources in an HTML table.
>
<% collection_presenter.attributes_for(resource).each do |attribute| %>
<td class="cell-data cell-data--<%= attribute.html_class %>">
<%= render_field attribute %>
<a href="<%= polymorphic_path([namespace, resource]) -%>"
class="action-show table__link-plain"
>
<%= render_field attribute %>
</a>
</td>
<% end %>

Expand Down
9 changes: 9 additions & 0 deletions spec/features/index_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
expect(page).to have_content(customer.email)
end

it "links to the customer show page without javascript", js: false do
customer = create(:customer)

visit admin_customers_path
click_show_link_for(customer)

expect(page).to have_header(displayed(customer))
end

it "links to the edit page" do
customer = create(:customer)

Expand Down
10 changes: 10 additions & 0 deletions spec/support/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def click_row_for(model)
end
end

def click_show_link_for(model)
within(row_css_for(model)) do
all(show_link_elements).first.click
end
end

private

def row_css_for(model)
Expand All @@ -15,6 +21,10 @@ def clickable_table_elements
".cell-data--string, .cell-data--number"
end

def show_link_elements
".action-show"
end

def url_for(model)
"/" + [
:admin,
Expand Down

0 comments on commit 922fb48

Please sign in to comment.