From e35b15c8682ebb9d37e00128a3c05044164eeb70 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 21:02:54 +1030 Subject: [PATCH 1/4] Only render an edit control if the permission exists --- app/views/scientific_names/show.html.haml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/scientific_names/show.html.haml b/app/views/scientific_names/show.html.haml index 1c0a76357..dffbdffc3 100644 --- a/app/views/scientific_names/show.html.haml +++ b/app/views/scientific_names/show.html.haml @@ -9,6 +9,8 @@ %b Crop: = link_to @scientific_name.crop, @scientific_name.crop -= link_to 'Edit', edit_scientific_name_path(@scientific_name), :class => 'btn btn-default btn-xs' -\| + +- if can? :edit, @scientific_name + = link_to 'Edit', edit_scientific_name_path(@scientific_name), :class => 'btn btn-default btn-xs' + \| = link_to 'Back', scientific_names_path From 9fa72fa5f7979d43dcc256996dfbbace7bf726d2 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 21:02:02 +1030 Subject: [PATCH 2/4] Only render a pipe if there are multiple options like edit rights available --- app/views/alternate_names/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alternate_names/show.html.haml b/app/views/alternate_names/show.html.haml index 06012457b..fc2b7b335 100644 --- a/app/views/alternate_names/show.html.haml +++ b/app/views/alternate_names/show.html.haml @@ -11,5 +11,5 @@ - if can? :edit, @alternate_name = link_to 'Edit', edit_alternate_name_path(@alternate_name), :class => 'btn btn-default btn-xs' -\| + \| = link_to 'Back', alternate_names_path From 32af1b28a80d0a63622b0a808ac0ebd748142089 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 22:03:59 +1030 Subject: [PATCH 3/4] Update the expectations: an edit link is visible to crop wranglers (which used to be an expectation about the id appearing in a link) --- spec/views/scientific_names/show.html.haml_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/views/scientific_names/show.html.haml_spec.rb b/spec/views/scientific_names/show.html.haml_spec.rb index c16fbe444..d3db043e8 100644 --- a/spec/views/scientific_names/show.html.haml_spec.rb +++ b/spec/views/scientific_names/show.html.haml_spec.rb @@ -28,6 +28,18 @@ describe "scientific_names/show" do render # Run the generator again with the --webrat flag if you want to use webrat matchers rendered.should match(/Zea mays/) - rendered.should match(@scientific_name.id.to_s) + end + + context 'signed in' do + + before :each do + @wrangler = FactoryGirl.create(:crop_wrangling_member) + sign_in @wrangler + render + end + + it 'should have an edit button' do + rendered.should have_content 'Edit' + end end end From bfffaab77fc0c2f3c47ca94e2b9d551d86ce33ba Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 28 Mar 2016 22:26:36 +1030 Subject: [PATCH 4/4] Have to stub the controller load_and_authorize_resource behaviour, as these tests aren't run in that context. --- spec/views/scientific_names/show.html.haml_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/views/scientific_names/show.html.haml_spec.rb b/spec/views/scientific_names/show.html.haml_spec.rb index d3db043e8..a36646658 100644 --- a/spec/views/scientific_names/show.html.haml_spec.rb +++ b/spec/views/scientific_names/show.html.haml_spec.rb @@ -35,6 +35,7 @@ describe "scientific_names/show" do before :each do @wrangler = FactoryGirl.create(:crop_wrangling_member) sign_in @wrangler + controller.stub(:current_user) { @wrangler } render end