-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add namespace option to generators #956
add namespace option to generators #956
Conversation
it "populates default dashboards under the given namespace" do | ||
routes = file("config/routes.rb") | ||
|
||
run_generator ['--namespace', 'manager'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
it "is generated" do | ||
stub_generator_dependencies | ||
|
||
run_generator | ||
|
||
%w[customer order product line_item].each do |resource| | ||
expect(Rails::Generators). | ||
to invoke_generator("administrate:dashboard", [resource]) | ||
to invoke_generator("administrate:dashboard", [resource, "--namespace", "admin"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [91/80]
namespace(:manager) { resources :customers } | ||
end | ||
|
||
run_generator ['--namespace', 'manager'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
stub_generator_dependencies | ||
controller = file("app/controllers/manager/application_controller.rb") | ||
|
||
run_generator ['--namespace', 'manager'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -18,6 +18,20 @@ module Admin | |||
class ApplicationController < Administrate::ApplicationController | |||
RB | |||
end | |||
|
|||
it 'uses the namespace option' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -6,6 +6,7 @@ module Administrate | |||
module Generators | |||
class RoutesGenerator < Rails::Generators::Base | |||
source_root File.expand_path("../templates", __FILE__) | |||
class_option :namespace, type: :string, default: 'admin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
"app/controllers/admin/application_controller.rb" | ||
template( | ||
"application_controller.rb.erb", | ||
"app/controllers/#{namespace}/application_controller.rb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
@@ -8,34 +8,41 @@ class InstallGenerator < Rails::Generators::Base | |||
include Administrate::GeneratorHelpers | |||
source_root File.expand_path("../templates", __FILE__) | |||
|
|||
class_option :namespace, type: :string, default: 'admin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -24,6 +24,8 @@ class DashboardGenerator < Rails::Generators::NamedBase | |||
COLLECTION_ATTRIBUTE_LIMIT = 4 | |||
READ_ONLY_ATTRIBUTES = %w[id created_at updated_at] | |||
|
|||
class_option :namespace, type: :string, default: 'admin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -4,7 +4,10 @@ | |||
require "support/constant_helpers" | |||
|
|||
describe Administrate::Generators::InstallGenerator, :generator do | |||
describe "admin/application_controller" do | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at block body beginning.
c8e9623
to
feb785a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! A few comments.
end | ||
|
||
it "does not invoke routes generator if namespace routes already exist \ | ||
when using custom namespace" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we'd be able to use a context
here, instead of having a super long it
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
|
||
run_generator ["--namespace", "manager"] | ||
|
||
expect(controller).to exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check it exists if we're also ensuring it looks right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this verification as it will raise a proper error message when the file doesn't exist (expected "/home/rodrigo/Projects/administrate/tmp/app/controllers/manager/application_controller.rb" to exist
)
If we use only the have_correct_syntax
matcher and the generator fails to create the file, the error message would be No such file or directory @ rb_sysopen - /home/rodrigo/Projects/administrate/tmp/app/controllers/manager/application_controller.rb
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good reason! Let's leave it in there.
end | ||
|
||
|
||
context 'using the namespace option' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line detected.
c682de6
to
6d4f822
Compare
rebased |
Seems that it was fixed by #339 |
Hi @Rodrigora! I noticed you closed this, but I don't quite think we've solved it. Looking at the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes #754
With this change, we'll be able to run the generators with the namespace option: