Skip to content

Commit

Permalink
Don't allow creating a new app with certain confusing names
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m committed Nov 14, 2024
1 parent a76a653 commit dbbbafb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/hanami/cli/commands/gem/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class New < Command
# @api private
SUPPORTED_DATABASES = [DATABASE_SQLITE, DATABASE_POSTGRES, DATABASE_MYSQL].freeze

# @api private
FORBIDDEN_APP_NAMES = %w[app slice].freeze

desc "Generate a new Hanami app"

# @since 2.0.0
Expand Down Expand Up @@ -126,6 +129,7 @@ def call(
app = inflector.underscore(app)

raise PathAlreadyExistsError.new(app) if fs.exist?(app)
raise ForbiddenAppNameError.new(app) if FORBIDDEN_APP_NAMES.include?(app)

normalized_database ||= normalize_database(database)

Expand Down
7 changes: 7 additions & 0 deletions lib/hanami/cli/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def initialize(path)
end
end

# @api public
class ForbiddenAppNameError < Error
def initialize(name)
super("Cannot create new Hanami app with the name: `#{name}'")
end
end

# @since 2.0.0
# @api public
class MissingSliceError < Error
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
expect(fs.read("#{app}/config/app.rb")).to include("module #{module_name}")
end

it "forbids certain confusing app names" do
%w[app slice].each do |forbidden_name|
expect {
subject.call(app: forbidden_name)
}.to raise_error(
Hanami::CLI::ForbiddenAppNameError,
"Cannot create new Hanami app with the name: `#{forbidden_name}'"
)
end
end

it "generates an app" do
expect(bundler).to receive(:install!)
.and_return(true)
Expand Down

0 comments on commit dbbbafb

Please sign in to comment.