Make polymorphic_path work with booth assignments

This commit is contained in:
Javi Martín
2020-06-08 22:57:40 +02:00
parent f76930aab6
commit 94a1865217
3 changed files with 14 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ module ActionDispatch::Routing::UrlFor
end end
def admin_polymorphic_path(resource, options = {}) def admin_polymorphic_path(resource, options = {})
if %w[Budget::Group Budget::Heading Poll::Booth Poll::Officer 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].include?(resource.class.name)
resolve = resolve_for(resource) resolve = resolve_for(resource)
resolve_options = resolve.pop resolve_options = resolve.pop

View File

@@ -278,6 +278,10 @@ resolve "Poll::Booth" do |booth, options|
[:booth, options.merge(id: booth)] [:booth, options.merge(id: booth)]
end end
resolve "Poll::BoothAssignment" do |assignment, options|
[assignment.poll, :booth_assignment, options.merge(id: assignment)]
end
resolve "Poll::Officer" do |officer, options| resolve "Poll::Officer" do |officer, options|
[:officer, options.merge(id: officer)] [:officer, options.merge(id: officer)]
end end

View File

@@ -148,6 +148,15 @@ describe "Polymorphic routes" do
) )
end end
it "routes booth assignments" do
poll = create(:poll)
assignment = create(:poll_booth_assignment, poll: poll)
expect(admin_polymorphic_path(assignment)).to eq(
admin_poll_booth_assignment_path(poll, assignment)
)
end
it "supports routes for actions like edit" do it "supports routes for actions like edit" do
proposal = create(:proposal) proposal = create(:proposal)
milestone = create(:milestone, milestoneable: proposal) milestone = create(:milestone, milestoneable: proposal)