Navigation Menu

Skip to content

Commit

Permalink
Action generator doesn't respect Ruby file naming
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoc2505 committed May 22, 2015
1 parent 6a99db0 commit e6577d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/lotus/generators/action.rb
Expand Up @@ -27,7 +27,8 @@ class Action < Abstract
def initialize(command)
super

@controller, @action = name.split(ACTION_SEPARATOR)
@name = Utils::String.new(name).underscore
@controller, @action = @name.split(ACTION_SEPARATOR)
@controller_name = Utils::String.new(@controller).classify
@action_name = Utils::String.new(@action).classify

Expand Down Expand Up @@ -107,7 +108,7 @@ def generate_route

# Insert at the top of the file
cli.insert_into_file _routes_path, before: /\A(.*)/ do
"get '/#{ @controller }', to: '#{ name }'\n"
"get '/#{ @controller }', to: '#{ @name }'\n"
end
end

Expand Down
60 changes: 47 additions & 13 deletions test/integration/cli/generate_test.rb
Expand Up @@ -34,10 +34,18 @@ def generate_action
`bundle exec lotus generate action #{ app_name } dashboard#index`
end

def generate_action_with_camlcase
`bundle exec lotus generate action #{ app_name } AncientBooks#ToggleVisibility`
end

def generate_action_without_view
`bundle exec lotus generate action #{ app_name } dashboard#foo --skip-view`
end

def generate_action_with_camlcase_without_view
`bundle exec lotus generate action #{ app_name } DashBoard#TestCase --skip-view`
end

def generate_model
`bundle exec lotus generate model #{ klass }`
end
Expand All @@ -61,20 +69,46 @@ def after
chdir_to_root
end

it 'generates an action' do
@root.join('apps/web/controllers/dashboard/index.rb').must_be :exist?
@root.join('apps/web/views/dashboard/index.rb').must_be :exist?
@root.join('apps/web/templates/dashboard/index.html.erb').must_be :exist?
@root.join('spec/web/controllers/dashboard/index_spec.rb').must_be :exist?
@root.join('spec/web/views/dashboard/index_spec.rb').must_be :exist?
end
describe 'when application generates new action' do
describe 'when controllers, action name are Underscored names.' do
it 'generates an action' do
@root.join('apps/web/controllers/dashboard/index.rb').must_be :exist?
@root.join('apps/web/views/dashboard/index.rb').must_be :exist?
@root.join('apps/web/templates/dashboard/index.html.erb').must_be :exist?
@root.join('spec/web/controllers/dashboard/index_spec.rb').must_be :exist?
@root.join('spec/web/views/dashboard/index_spec.rb').must_be :exist?
end

it 'generates an action without view' do
@root.join('apps/web/controllers/dashboard/foo.rb').must_be :exist?
@root.join('apps/web/views/dashboard/foo.rb').wont_be :exist?
@root.join('apps/web/templates/dashboard/foo.html.erb').wont_be :exist?
@root.join('spec/web/controllers/dashboard/foo_spec.rb').must_be :exist?
@root.join('spec/web/views/dashboard/foo_spec.rb').wont_be :exist?
end
end

it 'generates an action without view' do
@root.join('apps/web/controllers/dashboard/foo.rb').must_be :exist?
@root.join('apps/web/views/dashboard/foo.rb').wont_be :exist?
@root.join('apps/web/templates/dashboard/foo.html.erb').wont_be :exist?
@root.join('spec/web/controllers/dashboard/foo_spec.rb').must_be :exist?
@root.join('spec/web/views/dashboard/foo_spec.rb').wont_be :exist?
describe 'when controllers, action name are CamelCase names.' do
before do
generate_action_with_camlcase
generate_action_with_camlcase_without_view
end
it 'generates an action' do
@root.join('apps/web/controllers/ancient_books/toggle_visibility.rb').must_be :exist?
@root.join('apps/web/views/ancient_books/toggle_visibility.rb').must_be :exist?
@root.join('apps/web/templates/ancient_books/toggle_visibility.html.erb').must_be :exist?
@root.join('spec/web/controllers/ancient_books/toggle_visibility_spec.rb').must_be :exist?
@root.join('spec/web/views/ancient_books/toggle_visibility_spec.rb').must_be :exist?
end

it 'generates an action without view' do
@root.join('apps/web/controllers/dash_board/test_case.rb').must_be :exist?
@root.join('apps/web/views/dash_board/test_case.rb').wont_be :exist?
@root.join('apps/web/templates/dash_board/test_case.html.erb').wont_be :exist?
@root.join('spec/web/controllers/dash_board/test_case_spec.rb').must_be :exist?
@root.join('spec/web/views/dash_board/test_case_spec.rb').wont_be :exist?
end
end
end

describe 'when application generates new model' do
Expand Down

0 comments on commit e6577d8

Please sign in to comment.