Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit edb6f21

Browse files
committed
display usage documentation when model is invalid
1 parent b8e861b commit edb6f21

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

features/nifty_scaffold.feature

+4
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ Feature: Nifty Scaffold Generator
3838
And I run "rails g rspec:install"
3939
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
4040
Then I should successfully run "rake spec"
41+
42+
Scenario: Report error when invalid model name
43+
Given a new Rails app
44+
Then I should see "Usage:" when running "rails g nifty:scaffold name:string parent_id:integer"

features/step_definitions/common_steps.rb

+4
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@
4242
Then /^I should successfully run "([^\"]*)"$/ do |command|
4343
system("cd #{@current_directory} && #{command}").should be_true
4444
end
45+
46+
Then /^I should see "([^\"]*)" when running "([^\"]*)"$/ do |expected_response, command|
47+
`cd #{@current_directory} && #{command}`.should include(expected_response)
48+
end

lib/generators/nifty.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ def self.source_root
88
end
99

1010
def self.banner
11-
"#{$0} nifty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
11+
"rails generate nifty:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
1212
end
13-
13+
1414
private
15-
15+
1616
def add_gem(name, options = {})
1717
gemfile_content = File.read(destination_path("Gemfile"))
1818
File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
1919
gem name, options unless gemfile_content.include? name
2020
end
21+
22+
def print_usage
23+
self.class.help(Thor::Base.shell.new)
24+
exit
25+
end
2126
end
2227
end
2328
end

lib/generators/nifty/scaffold/USAGE

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Usage:
2121
model's attributes. Timestamps are added by default, so you don't have to
2222
specify them by hand as 'created_at:datetime updated_at:datetime'.
2323

24-
For example, `nifty_scaffold post name:string content:text hidden:boolean`
24+
For example, `nifty:scaffold post name:string content:text hidden:boolean`
2525
gives you a model with those three attributes, a controller that handles
2626
the create/show/update/destroy, forms to create and edit your posts, and
2727
an index that lists them all, as well as a map.resources :posts

lib/generators/nifty/scaffold/scaffold_generator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class ScaffoldGenerator < Base
2525
def initialize(*args, &block)
2626
super
2727

28+
print_usage unless model_name =~ /^[a-zA-Z_]$/
29+
2830
@controller_actions = []
2931
@model_attributes = []
3032
@skip_model = options.skip_model?

0 commit comments

Comments
 (0)