Skip to content

Commit

Permalink
Allows to generate the app in the current folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mengqing authored and Trung Lê committed Jan 14, 2015
1 parent 89a4ace commit ac07b73
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/lotus/commands/new.rb
Expand Up @@ -10,11 +10,11 @@ class New
attr_reader :app_name, :source, :target, :cli, :options

def initialize(app_name, environment, cli)
@app_name = app_name
@app_name = _get_real_app_name(app_name)
@options = environment.to_options
@arch = @options.fetch(:architecture)

@target = Pathname.pwd.join(@app_name)
@target = Pathname.pwd.join(app_name)
@source = Pathname.new(@options.fetch(:source) { ::File.dirname(__FILE__) + '/../generators/application/' }).join(@arch)

@cli = cli
Expand All @@ -27,6 +27,21 @@ def initialize(app_name, environment, cli)
def start
@command.start
end

private
def _get_real_app_name(app_name)
case app_name
when '.'
::File.basename(Dir.getwd)
when '/'
# If path is root, then use a default app name
# most likely won't be used due to file permission
'app'
else
# Allows the app name to be a path
::File.basename(app_name)
end
end
end
end
end
78 changes: 78 additions & 0 deletions test/commands/new_test.rb
Expand Up @@ -490,5 +490,83 @@ def container_options
end
end
end

describe 'when app_name is .' do
let(:app_name) { '.' }

describe 'config/environment.rb' do
it 'generates it' do
content = @root.join('config/environment.rb').read
content.must_match %(require_relative '../lib/new')
end
end

describe 'lib/new' do
it 'generates it' do
@root.join('lib/new').must_be :directory?
end
end

describe 'lib/new.rb' do
it 'generates it' do
@root.join('lib/new.rb').must_be :file?
content = @root.join('lib/new.rb').read
content.must_match %(adapter type: :file_system, uri: ENV['NEW_DATABASE_URL'])
end
end

describe 'config/.env.development' do
it 'generates it' do
content = @root.join('config/.env.development').read
content.must_match %(NEW_DATABASE_URL="file:///db/new_development")
end
end

describe 'config/.env.test' do
it 'generates it' do
content = @root.join('config/.env.test').read
content.must_match %(NEW_DATABASE_URL="file:///db/new_test")
end
end
end

describe 'when app_name is a path' do
let(:app_name) { '../new' }

describe 'config/environment.rb' do
it 'generates it' do
content = @root.join('config/environment.rb').read
content.must_match %(require_relative '../lib/new')
end
end

describe 'lib/new' do
it 'generates it' do
@root.join('lib/new').must_be :directory?
end
end

describe 'lib/new.rb' do
it 'generates it' do
@root.join('lib/new.rb').must_be :file?
content = @root.join('lib/new.rb').read
content.must_match %(adapter type: :file_system, uri: ENV['NEW_DATABASE_URL'])
end
end

describe 'config/.env.development' do
it 'generates it' do
content = @root.join('config/.env.development').read
content.must_match %(NEW_DATABASE_URL="file:///db/new_development")
end
end

describe 'config/.env.test' do
it 'generates it' do
content = @root.join('config/.env.test').read
content.must_match %(NEW_DATABASE_URL="file:///db/new_test")
end
end
end
end
end

0 comments on commit ac07b73

Please sign in to comment.