From 289eb96561201e247e9b8be28836cfc7a4012184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 9 Jun 2020 00:14:27 +0200 Subject: [PATCH] Make polymorphic_path work with poll shifts --- config/initializers/routes_hierarchy.rb | 2 +- config/routes/admin.rb | 4 ++++ spec/routing/polymorphic_routes_spec.rb | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 1f5084041..fd096a64a 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -17,7 +17,7 @@ module ActionDispatch::Routing::UrlFor def admin_polymorphic_path(resource, options = {}) if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer - Poll::Question Poll::Question::Answer::Video].include?(resource.class.name) + Poll::Question Poll::Question::Answer::Video Poll::Shift].include?(resource.class.name) resolve = resolve_for(resource) resolve_options = resolve.pop diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 54af7ace3..5121fec3b 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -282,6 +282,10 @@ resolve "Poll::BoothAssignment" do |assignment, options| [assignment.poll, :booth_assignment, options.merge(id: assignment)] end +resolve "Poll::Shift" do |shift, options| + [:booth, :shift, options.merge(booth_id: shift.booth, id: shift)] +end + resolve "Poll::Officer" do |officer, options| [:officer, options.merge(id: officer)] end diff --git a/spec/routing/polymorphic_routes_spec.rb b/spec/routing/polymorphic_routes_spec.rb index c6e14d26c..8ab22512b 100644 --- a/spec/routing/polymorphic_routes_spec.rb +++ b/spec/routing/polymorphic_routes_spec.rb @@ -157,6 +157,13 @@ describe "Polymorphic routes" do ) end + it "routes poll shifts" do + booth = create(:poll_booth) + shift = create(:poll_shift, booth: booth) + + expect(admin_polymorphic_path(shift)).to eq(admin_booth_shift_path(booth, shift)) + end + it "supports routes for actions like edit" do proposal = create(:proposal) milestone = create(:milestone, milestoneable: proposal)