Skip to content
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

Merged

Conversation

Rodrigora
Copy link
Contributor

fixes #754

With this change, we'll be able to run the generators with the namespace option:

rails generate administrate:install --namespace manager
rails generate administrate:dashboard --namespace manager

it "populates default dashboards under the given namespace" do
routes = file("config/routes.rb")

run_generator ['--namespace', 'manager']

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"])

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']

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']

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

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'

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"

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'

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'

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

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.

@Rodrigora Rodrigora force-pushed the add-namespace-option-to-generators branch from c8e9623 to feb785a Compare August 1, 2017 17:16
Copy link
Member

@nickcharlton nickcharlton left a 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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

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


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line detected.

@Rodrigora Rodrigora force-pushed the add-namespace-option-to-generators branch from c682de6 to 6d4f822 Compare August 3, 2017 15:56
@Rodrigora
Copy link
Contributor Author

rebased

@Rodrigora
Copy link
Contributor Author

Seems that it was fixed by #339

@Rodrigora Rodrigora closed this Sep 27, 2017
@nickcharlton
Copy link
Member

nickcharlton commented Sep 28, 2017

Hi @Rodrigora! I noticed you closed this, but I don't quite think we've solved it.

Looking at the current master, we don't have an option for the generator (but everything else seems to be ready). This issue is relevant, too: #754

@nickcharlton nickcharlton reopened this Sep 28, 2017
Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@nickcharlton nickcharlton merged commit 844d7b2 into thoughtbot:master Nov 10, 2017
@Rodrigora Rodrigora deleted the add-namespace-option-to-generators branch July 24, 2018 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add namespace option to generators
4 participants