From 9d021d77b9fe54f30bc3aeadd98d830b588ff6a7 Mon Sep 17 00:00:00 2001 From: john hernandez Date: Fri, 3 Feb 2017 12:09:57 +0000 Subject: [PATCH] Redefine base resource path Before, the base resource path for view generators was a hard-coded string. This was causing issues for some generators. When called without an argument, their sub-generators had the wrong resource path. Replaced the base resource path string with a value object. * Fixes https://github.com/thoughtbot/administrate/issues/645 --- lib/administrate/view_generator.rb | 8 +++++++- spec/generators/views_generator_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/administrate/view_generator.rb b/lib/administrate/view_generator.rb index 6c7b5bc..8f49299 100644 --- a/lib/administrate/view_generator.rb +++ b/lib/administrate/view_generator.rb @@ -24,7 +24,13 @@ def copy_resource_template(template_name) end def resource_path - args.first.try(:underscore).try(:pluralize) || "application" + args.first.try(:underscore).try(:pluralize) || BaseResourcePath.new + end + + class BaseResourcePath + def to_s + "application" + end end end end diff --git a/spec/generators/views_generator_spec.rb b/spec/generators/views_generator_spec.rb index e1a403e..49603ea 100644 --- a/spec/generators/views_generator_spec.rb +++ b/spec/generators/views_generator_spec.rb @@ -28,5 +28,23 @@ behavior: :revoke, ) end + + context "when run without any arguments" do + it "calls the sub-generators without any arguments" do + application_resource_path = instance_double("BaseResourcePath") + allow(Administrate::ViewGenerator::BaseResourcePath).to receive(:new). + and_return(application_resource_path) + allow(Rails::Generators).to receive(:invoke) + + run_generator + + %w[index show new edit].each do |generator| + expect(Rails::Generators). to invoke_generator( + "administrate:views:#{generator}", + [application_resource_path], + ) + end + end + end end end