From 79b4048f8353102aa88ccb2969ad0286363a109b Mon Sep 17 00:00:00 2001 From: Oli Peate Date: Fri, 6 Jan 2017 12:49:48 +0000 Subject: [PATCH] Add hyperlink to show resource from collection table Allows a resource to be shown without javascript enabled (using "data-url"). Also facilitates faster tests using RackTest. --- .../stylesheets/administrate/components/_table.scss | 8 ++++++++ .../administrate/application/_collection.html.erb | 6 +++++- spec/features/index_page_spec.rb | 9 +++++++++ spec/support/table.rb | 10 ++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/administrate/components/_table.scss b/app/assets/stylesheets/administrate/components/_table.scss index a290cd2041..dc18205841 100644 --- a/app/assets/stylesheets/administrate/components/_table.scss +++ b/app/assets/stylesheets/administrate/components/_table.scss @@ -21,3 +21,11 @@ .table__action--destroy { color: $light-red; } + +.table__link-plain { + color: inherit; + + &:hover { + color: inherit; + } +} diff --git a/app/views/administrate/application/_collection.html.erb b/app/views/administrate/application/_collection.html.erb index ed64ea7763..8a4d0932a1 100644 --- a/app/views/administrate/application/_collection.html.erb +++ b/app/views/administrate/application/_collection.html.erb @@ -60,7 +60,11 @@ to display a collection of resources in an HTML table. > <% collection_presenter.attributes_for(resource).each do |attribute| %> - <%= render_field attribute %> + + <%= render_field attribute %> + <% end %> diff --git a/spec/features/index_page_spec.rb b/spec/features/index_page_spec.rb index fde9c0725c..cf6d903b38 100644 --- a/spec/features/index_page_spec.rb +++ b/spec/features/index_page_spec.rb @@ -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) diff --git a/spec/support/table.rb b/spec/support/table.rb index 93e093ac78..1ca63382a1 100644 --- a/spec/support/table.rb +++ b/spec/support/table.rb @@ -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) @@ -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,