From d4de52d63f400f30dabb7034e14202f5c9bd0192 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 19 Jun 2017 17:24:15 +0200 Subject: Lines#show: Render header links from #action_links Get the header links from the decorator so we can reuse them instead of defining them directly in the template. Add an option to the `destroy_link_content` Rails helper method to allow us to specify alternate translation keys, giving us different text in the button label. Added this because the template in question uses a different label than the others (usually it's `actions.destroy`). Refs #3479 --- app/controllers/lines_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/controllers/lines_controller.rb') diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 7eedaeb05..c3378208b 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -25,6 +25,10 @@ class LinesController < BreadcrumbController def show @group_of_lines = resource.group_of_lines show! do + @line = @line.decorate(context: { + line_referential: @line_referential + }) + build_breadcrumb :show end end -- cgit v1.2.3 From 140270297b1db064b78472ccd7e59b8279d21be7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 19 Jun 2017 18:35:26 +0200 Subject: lines/show.html.erb_spec.rb: Fix specs resulting from `LineDecorator` The tests failed because we weren't using a decorated `Chouette::Line` object, but the views now expect decorated lines in order to be able to call the `#action_links` method. Here are our failures: 5) /lines/show should render h1 with the line name Failure/Error: - @line.action_links.each do |link| ActionView::Template::Error: undefined method `action_links' for # # ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360' # ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader' # ./app/helpers/newapplication_helper.rb:244:in `block in pageheader' # ./app/helpers/newapplication_helper.rb:243:in `pageheader' # ./app/views/lines/show.html.slim:2:in `_app_views_lines_show_html_slim___3813514632397395671_70250211127360' # ./spec/views/lines/show.html.erb_spec.rb:16:in `block (2 levels) in ' # -e:1:in `
' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `action_links' for # # ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360' 6) /lines/show should render a link to remove the line Failure/Error: - @line.action_links.each do |link| ActionView::Template::Error: undefined method `action_links' for # # ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360' # ./app/helpers/newapplication_helper.rb:246:in `block (2 levels) in pageheader' # ./app/helpers/newapplication_helper.rb:244:in `block in pageheader' # ./app/helpers/newapplication_helper.rb:243:in `pageheader' # ./app/views/lines/show.html.slim:2:in `_app_views_lines_show_html_slim___3813514632397395671_70250211127360' # ./spec/views/lines/show.html.erb_spec.rb:31:in `block (2 levels) in ' # -e:1:in `
' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `action_links' for # # ./app/views/lines/show.html.slim:10:in `block in _app_views_lines_show_html_slim___3813514632397395671_70250211127360' Update the test to decorate the lines used in them. Turn `current_organisation` into a `context` field on `LineDecorator` because otherwise it's a global variable that comes from wherever that's required in `LineDecorator`. And we'd have to mock `current_organisation` on `line` in the test, which I wasn't keen on. Refs #3479 --- app/controllers/lines_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/controllers/lines_controller.rb') diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index c3378208b..1e2056aad 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -26,7 +26,8 @@ class LinesController < BreadcrumbController @group_of_lines = resource.group_of_lines show! do @line = @line.decorate(context: { - line_referential: @line_referential + line_referential: @line_referential, + current_organisation: current_organisation }) build_breadcrumb :show -- cgit v1.2.3