Skip to content

Commit

Permalink
Redefine base resource path
Browse files Browse the repository at this point in the history
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 #645
  • Loading branch information
Rob Whittaker committed Feb 3, 2017
1 parent b7ce134 commit 0e6f9c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/administrate/view_generator.rb
Expand Up @@ -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
18 changes: 18 additions & 0 deletions spec/generators/views_generator_spec.rb
Expand Up @@ -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

0 comments on commit 0e6f9c1

Please sign in to comment.