This repository was archived by the owner on Dec 12, 2021. It is now read-only.
File tree 5 files changed +19
-4
lines changed
5 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -38,3 +38,7 @@ Feature: Nifty Scaffold Generator
38
38
And I run "rails g rspec:install"
39
39
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
40
40
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"
Original file line number Diff line number Diff line change 42
42
Then /^I should successfully run "([^\" ]*)"$/ do |command |
43
43
system ( "cd #{ @current_directory } && #{ command } " ) . should be_true
44
44
end
45
+
46
+ Then /^I should see "([^\" ]*)" when running "([^\" ]*)"$/ do |expected_response , command |
47
+ `cd #{ @current_directory } && #{ command } ` . should include ( expected_response )
48
+ end
Original file line number Diff line number Diff line change @@ -8,16 +8,21 @@ def self.source_root
8
8
end
9
9
10
10
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]"
12
12
end
13
-
13
+
14
14
private
15
-
15
+
16
16
def add_gem ( name , options = { } )
17
17
gemfile_content = File . read ( destination_path ( "Gemfile" ) )
18
18
File . open ( destination_path ( "Gemfile" ) , 'a' ) { |f | f . write ( "\n " ) } unless gemfile_content =~ /\n \Z /
19
19
gem name , options unless gemfile_content . include? name
20
20
end
21
+
22
+ def print_usage
23
+ self . class . help ( Thor ::Base . shell . new )
24
+ exit
25
+ end
21
26
end
22
27
end
23
28
end
Original file line number Diff line number Diff line change 21
21
model's attributes. Timestamps are added by default, so you don't have to
22
22
specify them by hand as 'created_at:datetime updated_at:datetime'.
23
23
24
- For example, `nifty_scaffold post name:string content:text hidden:boolean`
24
+ For example, `nifty:scaffold post name:string content:text hidden:boolean`
25
25
gives you a model with those three attributes, a controller that handles
26
26
the create/show/update/destroy, forms to create and edit your posts, and
27
27
an index that lists them all, as well as a map.resources :posts
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ class ScaffoldGenerator < Base
25
25
def initialize ( *args , &block )
26
26
super
27
27
28
+ print_usage unless model_name =~ /^[a-zA-Z_]$/
29
+
28
30
@controller_actions = [ ]
29
31
@model_attributes = [ ]
30
32
@skip_model = options . skip_model?
You can’t perform that action at this time.
0 commit comments