padrino-gen 0.2.9 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -105,6 +105,12 @@ Usually the model file will generate files similar to the following:
105
105
 
106
106
  You can define as many models as you would like in a Padrino application using this generator.
107
107
 
108
+ You can destroy models that you created via the destroy option and setting it to true. default is false.
109
+
110
+ $ padrino-gen model User -d
111
+
112
+ This remove all created model files.
113
+
108
114
  === Migration Generator ===
109
115
 
110
116
  Padrino provides generator for quickly generating new migrations to change or manipulate the database schema.
@@ -127,6 +133,12 @@ You can also specify desired columns to be added to the migration file:
127
133
  The migration generator will then construct the migration file according to your ORM component chosen
128
134
  within <tt>db/migrate/xxx_add_fields_to_users.rb</tt> including the columns specified in the command.
129
135
 
136
+ You can destroy migrations that you created via the destroy option and setting it to true. default is false.
137
+
138
+ $ padrino-gen migration AddFieldsToUsers -d
139
+
140
+ This removes the migration file.
141
+
130
142
  === Controller Generator ===
131
143
 
132
144
  Padrino provides generator support for quickly creating new controllers within your Padrino application. Note that
@@ -151,6 +163,12 @@ test framework chosen during app generation. A default route will also be genera
151
163
  $ padrino-gen controller User get:index
152
164
 
153
165
  will create a url route for :index mapping to "/user/index"
166
+
167
+ You can destroy controllers that you created via the destroy option and setting it to true. default is false.
168
+
169
+ $ padrino-gen controller User -d
170
+
171
+ This removes all created controller files.
154
172
 
155
173
  === Mailer Generator ===
156
174
 
@@ -168,6 +186,12 @@ You can also specify desired delivery actions to be added to the mailer:
168
186
 
169
187
  The mailer generator will then construct the mailer file within <tt>app/mailers/user_notifier.rb</tt>
170
188
 
189
+ You can destroy mailer that you created via the destroy option and setting it to true. default is false.
190
+
191
+ $ padrino-gen mailer UserNotifer -d
192
+
193
+ This remove all created mailer files.
194
+
171
195
  == Copyright
172
196
 
173
197
  Copyright (c) 2009 Padrino. See LICENSE for details.
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  require 'rake/testtask'
32
32
  Rake::TestTask.new(:test) do |test|
33
- test.libs << 'lib' << 'test'
33
+ test.libs << 'test'
34
34
  test.pattern = 'test/**/test_*.rb'
35
35
  test.verbose = true
36
36
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.9
1
+ 0.4.5
@@ -4,7 +4,9 @@ class <%= @class_name %> < Padrino::Application
4
4
  # set :sessions, false # Enabled by default
5
5
  # set :log_to_file, true # Log to file instead of stdout (default is stdout in development)
6
6
  # set :reload, false # Reload application files (default in development)
7
+ # set :locale, :it # Set the current locale (default is :en)
7
8
  # disable :padrino_helpers # Disables padrino markup helpers (enabled by default)
8
9
  # disable :flash # Disables rack-flash (enabled by default)
10
+ # enable :auto_locale # Enable auto localization inspecting "/:locale/your/path" or browser languages
9
11
  end
10
12
  end
@@ -15,8 +15,6 @@ module Padrino
15
15
  def load_boot
16
16
  if in_app_root?(options[:root])
17
17
  require(options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb')
18
- else
19
- say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
20
18
  end
21
19
  end
22
20
  end
@@ -39,11 +39,10 @@ module Padrino
39
39
  contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
40
40
  contents = contents.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
41
41
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
42
- current_migration_number = Dir[app_root_path('db/migrate/*.rb')].map { |f|
43
- File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i || 0
42
+ current_migration_number = return_last_migration_number
44
43
  contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, (current_migration_number + 1).to_s)
45
44
  migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
46
- create_file(app_root_path('db/migrate/', migration_filename), contents)
45
+ create_file(app_root_path('db/migrate/', migration_filename), contents, :skip => true)
47
46
  end
48
47
 
49
48
  # For orm database components
@@ -64,14 +63,36 @@ module Padrino
64
63
  contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, (direction == 'add' ? forward_text.to_s : back_text.to_s))
65
64
  contents.gsub!(/\s{4}!DOWN!\n/m, (direction == 'add' ? back_text.to_s : forward_text.to_s))
66
65
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
67
- current_migration_number = Dir[app_root_path('db/migrate/*.rb')].map { |f|
68
- File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i || 0
69
- contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s)
66
+ current_migration_number = return_last_migration_number
67
+ contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s)
70
68
  migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
71
69
  # migration_filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}_#{filename.underscore}.rb"
72
70
  create_file(app_root_path('db/migrate/', migration_filename), contents)
73
71
  end
74
72
 
73
+ # For migration files
74
+ # returns the number of the latest(most current) migration file
75
+ def return_last_migration_number
76
+ Dir[app_root_path('db/migrate/*.rb')].map do |f|
77
+ File.basename(f).match(/^(\d+)/)[0].to_i
78
+ end.max.to_i || 0
79
+ end
80
+
81
+ #For model destroy option
82
+ #removes the initial migration file of model
83
+ def remove_model_migration(name)
84
+ remove_migration "Create" + name
85
+ end
86
+
87
+ #For the removal of migration files
88
+ # removes the migration file based on the migration name
89
+ def remove_migration(name)
90
+ migration_path = Dir[app_root_path('db/migrate/*.rb')].select do |f|
91
+ File.basename(f).match(/#{name.to_s.underscore}/)
92
+ end.first
93
+ remove_file migration_path
94
+ end
95
+
75
96
  # For testing components
76
97
  # Injects the test class text into the test_config file for setting up the test gen
77
98
  # insert_test_suite_setup('...CLASS_NAME...')
@@ -98,26 +119,26 @@ module Padrino
98
119
  def indent_spaces(count)
99
120
  ' ' * count
100
121
  end
101
-
122
+
102
123
  # For Controller action generation
103
124
  # Takes in fields for routes in the form of get:index post:test delete:yada and such
104
125
  def controller_actions(fields)
105
126
  field_tuples = fields.collect { |value| value.split(":") }
106
- action_declarations = field_tuples.collect do |request, name|
127
+ action_declarations = field_tuples.collect do |request, name|
107
128
  "#{request} :#{name} do\n end\n"
108
- end.join("\n ")
129
+ end.join("\n ")
109
130
  end
110
-
131
+
111
132
  # For controller route generation
112
133
  # Takes in the fields and maps out an appropriate default route.
113
134
  # where controller is user and route is get:test, will add map(:test).to("/user/test")
114
135
  def controller_routes(name,fields)
115
136
  field_tuples = fields.collect { |value| value.split(":") }
116
- routes = "\n" + field_tuples.collect do |request, route|
137
+ routes = "\n" + field_tuples.collect do |request, route|
117
138
  " map(:#{route}).to(\"/#{name}/#{route}\")"
118
- end.join("\n") + "\n"
139
+ end.join("\n") + "\n"
119
140
  end
120
-
141
+
121
142
  end
122
143
  end
123
144
  end
@@ -65,9 +65,8 @@ module Padrino
65
65
 
66
66
  def create_model_file(name, fields)
67
67
  model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
68
- return false if File.exist?(model_path)
69
68
  model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
70
- create_file(model_path, model_contents)
69
+ create_file(model_path, model_contents,:skip => true)
71
70
  end
72
71
 
73
72
  AR_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
@@ -34,7 +34,7 @@ module Padrino
34
34
  # Generates a controller test given the controllers name
35
35
  def generate_controller_test(name, root)
36
36
  bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
37
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), bacon_contents
37
+ create_file app_root_path("test/controllers/","#{name}_controller_test.rb"), bacon_contents, :skip => true
38
38
  end
39
39
 
40
40
  BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -50,7 +50,7 @@ module Padrino
50
50
 
51
51
  def generate_model_test(name)
52
52
  bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
53
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents
53
+ create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents, :skip => true
54
54
  end
55
55
 
56
56
  end
@@ -33,7 +33,7 @@ module Padrino
33
33
  # Generates a controller test given the controllers name
34
34
  def generate_controller_test(name, root)
35
35
  riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), riot_contents
36
+ create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
37
37
  end
38
38
 
39
39
  RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -49,7 +49,7 @@ module Padrino
49
49
 
50
50
  def generate_model_test(name)
51
51
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), riot_contents
52
+ create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), riot_contents, :skip => true
53
53
  end
54
54
 
55
55
  end
@@ -35,7 +35,7 @@ module Padrino
35
35
  # Generates a controller test given the controllers name
36
36
  def generate_controller_test(name, root)
37
37
  rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
38
- create_file File.join(root, "test/controllers/#{name}_controller_spec.rb"), rspec_contents
38
+ create_file File.join(root, "test/controllers/#{name}_controller_spec.rb"), rspec_contents, :skip => true
39
39
  end
40
40
 
41
41
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -51,7 +51,7 @@ module Padrino
51
51
 
52
52
  def generate_model_test(name)
53
53
  rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
54
- create_file app_root_path("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents
54
+ create_file app_root_path("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents, :skip => true
55
55
  end
56
56
 
57
57
  end
@@ -38,7 +38,7 @@ module Padrino
38
38
  # Generates a controller test given the controllers name
39
39
  def generate_controller_test(name, root)
40
40
  shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
41
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), shoulda_contents
41
+ create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), shoulda_contents, :skip => true
42
42
  end
43
43
 
44
44
  SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -56,7 +56,7 @@ module Padrino
56
56
 
57
57
  def generate_model_test(name)
58
58
  shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
59
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents
59
+ create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents, :skip => true
60
60
  end
61
61
 
62
62
  end
@@ -33,7 +33,7 @@ module Padrino
33
33
  # Generates a controller test given the controllers name
34
34
  def generate_controller_test(name, root)
35
35
  testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), testspec_contents
36
+ create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), testspec_contents, :skip => true
37
37
  end
38
38
 
39
39
  TESTSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
@@ -49,7 +49,7 @@ module Padrino
49
49
 
50
50
  def generate_model_test(name)
51
51
  tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
- create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), tests_contents
52
+ create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), tests_contents, :skip => true
53
53
  end
54
54
 
55
55
  end
@@ -22,12 +22,14 @@ module Padrino
22
22
  argument :name, :desc => "The name of your padrino controller"
23
23
  argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
24
24
  class_option :root, :aliases => '-r', :default => nil, :type => :string
25
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
26
 
26
27
  # Copies over the base sinatra starting project
27
28
  def create_controller
28
29
  if in_app_root?(options[:root])
29
30
  @app_name = fetch_app_name(options[:root])
30
31
  @actions = controller_actions(fields)
32
+ self.behavior = :revoke if options[:destroy]
31
33
  inject_into_file app_root_path("config/urls.rb"), controller_routes(name,fields), :after => "urls do\n"
32
34
  template "templates/controller.rb.tt", app_root_path("app/controllers", "#{name}.rb")
33
35
  template "templates/helper.rb.tt", app_root_path("app/helpers", "#{name}_helper.rb")
@@ -21,10 +21,12 @@ module Padrino
21
21
 
22
22
  argument :name, :desc => "The name of your padrino mailer"
23
23
  class_option :root, :aliases => '-r', :default => nil, :type => :string
24
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
25
 
25
26
  # Copies over the base sinatra starting project
26
27
  def create_mailer
27
28
  if in_app_root?(options[:root])
29
+ self.behavior = :revoke if options[:destroy]
28
30
  simple_name = name.to_s.gsub(/mailer/i, '')
29
31
  @mailer_basename = "#{simple_name.downcase.underscore}_mailer"
30
32
  @mailer_klass = "#{simple_name.downcase.camelize}Mailer"
@@ -22,11 +22,14 @@ module Padrino
22
22
  argument :name, :desc => "The name of your padrino migration"
23
23
  argument :columns, :desc => "The columns for the migration", :type => :array, :default => []
24
24
  class_option :root, :aliases => '-r', :default => nil, :type => :string
25
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
26
 
26
27
  # Copies over the base sinatra starting project
27
28
  def create_model
28
29
  if in_app_root?(options[:root])
30
+ remove_migration(name) if options[:destroy]
29
31
  include_component_module_for(:orm, options[:root])
32
+ self.behavior = :revoke if options[:destroy]
30
33
  create_migration_file(name, name, columns)
31
34
  else
32
35
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
@@ -22,22 +22,23 @@ module Padrino
22
22
  argument :name, :desc => "The name of your padrino model"
23
23
  argument :fields, :desc => "The fields for the model", :type => :array, :default => []
24
24
  class_option :root, :aliases => '-r', :default => nil, :type => :string
25
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
26
 
26
27
  # Copies over the base sinatra starting project
27
28
  def create_model
28
29
  if in_app_root?(options[:root])
30
+ remove_model_migration(name) if options[:destroy]
31
+ self.behavior = :revoke if options[:destroy]
29
32
  include_component_module_for(:orm, options[:root])
30
33
  include_component_module_for(:test, options[:root])
31
34
  migration_name = "create_#{name.pluralize.underscore}"
32
- model_success = create_model_file(name, fields)
33
- generate_model_test(name) if model_success
34
- model_success ? create_model_migration(migration_name, name, fields) :
35
- say("'#{name}' model has already been generated!")
35
+ create_model_file(name, fields)
36
+ generate_model_test(name)
37
+ create_model_migration(migration_name, name, fields)
36
38
  else
37
39
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
38
40
  end
39
41
  end
40
42
  end
41
-
42
43
  end
43
- end
44
+ end
data/padrino-gen.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-gen}
8
- s.version = "0.2.9"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2009-12-22}
12
+ s.date = %q{2010-01-06}
13
13
  s.default_executable = %q{padrino-gen}
14
14
  s.description = %q{Generators for easily creating and building padrino applications from the console}
15
15
  s.email = %q{nesquena@gmail.com}
@@ -34,6 +34,9 @@ Gem::Specification.new do |s|
34
34
  "lib/padrino-gen/generators/app/app/app.rb.tt",
35
35
  "lib/padrino-gen/generators/app/app/controllers/.empty_directory",
36
36
  "lib/padrino-gen/generators/app/app/helpers/.empty_directory",
37
+ "lib/padrino-gen/generators/app/app/public/images/.empty_directory",
38
+ "lib/padrino-gen/generators/app/app/public/javascripts/.empty_directory",
39
+ "lib/padrino-gen/generators/app/app/public/stylesheets/.empty_directory",
37
40
  "lib/padrino-gen/generators/app/app/views/.empty_directory",
38
41
  "lib/padrino-gen/generators/app/config.ru",
39
42
  "lib/padrino-gen/generators/app/config/apps.rb.tt",
@@ -42,9 +45,6 @@ Gem::Specification.new do |s|
42
45
  "lib/padrino-gen/generators/app/config/initializers/example.rb",
43
46
  "lib/padrino-gen/generators/app/config/urls.rb.tt",
44
47
  "lib/padrino-gen/generators/app/lib/.empty_directory",
45
- "lib/padrino-gen/generators/app/public/images/.empty_directory",
46
- "lib/padrino-gen/generators/app/public/javascripts/.empty_directory",
47
- "lib/padrino-gen/generators/app/public/stylesheets/.empty_directory",
48
48
  "lib/padrino-gen/generators/app/tmp/.empty_directory",
49
49
  "lib/padrino-gen/generators/base.rb",
50
50
  "lib/padrino-gen/generators/components/actions.rb",
data/test/helper.rb CHANGED
@@ -59,6 +59,11 @@ class Test::Unit::TestCase
59
59
  def assert_match_in_file(pattern, file)
60
60
  File.exist?(file) ? assert_match(pattern, File.read(file)) : assert_file_exists(file)
61
61
  end
62
+
63
+ def assert_no_match_in_file(pattern, file)
64
+ File.exists?(file) ? !assert_match(pattern, File.read(file)) : assert_file_exists(file)
65
+ end
66
+
62
67
  end
63
68
 
64
69
  class Object
@@ -57,22 +57,54 @@ class TestControllerGenerator < Test::Unit::TestCase
57
57
  expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
58
58
  assert_match_in_file(expected_pattern, @controller_test_path)
59
59
  end
60
-
60
+
61
61
  # Controller action generation
62
-
62
+
63
63
  should "generate actions for get:test post:yada" do
64
64
  silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=shoulda'])}
65
65
  silence_logger { @contgen.start(['demo_items', "get:test","post:yada",'-r=/tmp/sample_app']) }
66
66
  assert_match_in_file(/get :test do\n end\n/m,@controller_path)
67
67
  assert_match_in_file(/post :yada do\n end\n/m,@controller_path)
68
68
  end
69
-
69
+
70
70
  should "generate url routes for get:yoda post:yada" do
71
71
  silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=shoulda'])}
72
72
  silence_logger { @contgen.start(['demo_items', "get:yoda","post:yada",'-r=/tmp/sample_app']) }
73
73
  assert_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
74
- assert_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
74
+ assert_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
75
+ end
76
+
77
+ end
78
+
79
+ context "the controller destroy option" do
80
+
81
+ should "destroy controller files" do
82
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon'])}
83
+ silence_logger { @contgen.start(['demo_items','-r=/tmp/sample_app']) }
84
+ silence_logger { @contgen.start(['demo_items','-r=/tmp/sample_app','-d'])}
85
+ assert_no_file_exists(@controller_path)
86
+ assert_no_file_exists(@controller_test_path)
87
+ assert_no_file_exists('/tmp/sample_app/app/helpers/demo_items_helper.rb')
88
+ end
89
+
90
+ should "destroy controller files with rspec" do
91
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=rspec'])}
92
+ silence_logger { @contgen.start(['demo_items','-r=/tmp/sample_app']) }
93
+ silence_logger { @contgen.start(['demo_items','-r=/tmp/sample_app','-d'])}
94
+ assert_no_file_exists(@controller_path)
95
+ assert_no_file_exists('/tmp/sample_app/app/helpers/demo_items_helper.rb')
96
+ assert_no_file_exists('/tmp/sample_app/test/controllers/demo_items_controller_spec.rb')
75
97
  end
76
98
 
99
+ should "remove url routes" do
100
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon'])}
101
+ silence_logger { @contgen.start(['demo_items', "get:yoda","post:yada",'-r=/tmp/sample_app']) }
102
+ silence_logger { @contgen.start(['demo_items','-r=/tmp/sample_app','-d'])}
103
+ assert_no_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
104
+ assert_no_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
105
+ end
106
+
77
107
  end
108
+
109
+
78
110
  end
@@ -41,4 +41,16 @@ class TestMailerGenerator < Test::Unit::TestCase
41
41
  end
42
42
  end
43
43
 
44
+ context "the mailer destroy option" do
45
+
46
+ should "destroy mailer file" do
47
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
48
+ silence_logger { @mailgen.start(['demo', '-r=/tmp/sample_app']) }
49
+ silence_logger { @mailgen.start(['demo', '-r=/tmp/sample_app','-d']) }
50
+ assert_no_dir_exists('/tmp/sample_app/app/views/demo_mailer')
51
+ assert_no_file_exists('/tmp/sample_app/app/mailers/demo_mailer.rb')
52
+ assert_no_file_exists('/tmp/sample_app/config/initializers/mailer.rb')
53
+ end
54
+ end
55
+
44
56
  end
@@ -164,4 +164,27 @@ class TestMigrationGenerator < Test::Unit::TestCase
164
164
  assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
165
165
  end
166
166
  end
167
+
168
+ context "the migration destroy option" do
169
+
170
+ should "destroy the migration files" do
171
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
172
+ migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
173
+ silence_logger { @mig_gen.start(migration_params) }
174
+ silence_logger { @mig_gen.start(['RemoveEmailFromUsers', '-r=/tmp/sample_app','-d']) }
175
+ assert_no_file_exists("/tmp/sample_app/db/migrate/001_remove_email_from_users.rb")
176
+ end
177
+
178
+ should "destroy the migration file regardless of number" do
179
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
180
+ migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
181
+ migration_param2 = ['AddEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
182
+ silence_logger { @mig_gen.start(migration_param2) }
183
+ silence_logger { @mig_gen.start(migration_params) }
184
+ silence_logger { @mig_gen.start(['RemoveEmailFromUsers', '-r=/tmp/sample_app','-d']) }
185
+ assert_no_file_exists("/tmp/sample_app/db/migrate/002_remove_email_from_users.rb")
186
+ end
187
+
188
+ end
189
+
167
190
  end
@@ -21,7 +21,9 @@ class TestModelGenerator < Test::Unit::TestCase
21
21
  response_success = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
22
22
  response_duplicate = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
23
23
  assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_app/app/models/user.rb')
24
- assert_match /'user' model has already been generated!/, response_duplicate
24
+ # assert_match /'user' model has already been generated!/, response_duplicate
25
+ assert_match "identical\e[0m mp/sample_app/app/models/user.rb", response_duplicate
26
+ assert_match "identical\e[0m mp/sample_app/test/models/user_test.rb", response_duplicate
25
27
  end
26
28
 
27
29
  should "generate migration file versions properly" do
@@ -218,5 +220,33 @@ class TestModelGenerator < Test::Unit::TestCase
218
220
  assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/user_test.rb')
219
221
  end
220
222
  end
223
+
224
+ context "the model destroy option" do
225
+
226
+ should "destroy the model file" do
227
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
228
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
229
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app', '-d']) }
230
+ assert_no_file_exists('/tmp/sample_app/app/models/user.rb')
231
+ assert_no_file_exists('/tmp/sample_app/test/models/user_test.rb')
232
+ assert_no_file_exists('/tmp/sample_app/db/migrate/001_create_users.rb')
233
+ end
234
+
235
+ should "destroy the model test file with rspec" do
236
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
237
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
238
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app', '-d']) }
239
+ assert_no_file_exists('/tmp/sample_app/test/models/user_spec.rb')
240
+ end
241
+
242
+ should "destroy the model migration" do
243
+ silence_logger { @app.start(['sample_app', '/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
244
+ silence_logger { @model_gen.start(['Person', '-r=/tmp/sample_app']) }
245
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
246
+ silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app', '-d']) }
247
+ assert_no_file_exists('/tmp/sample_app/db/migrate/002_create_users.rb')
248
+ end
249
+
250
+ end
221
251
 
222
252
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-12-22 00:00:00 -08:00
15
+ date: 2010-01-06 00:00:00 +01:00
16
16
  default_executable: padrino-gen
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -140,6 +140,9 @@ files:
140
140
  - lib/padrino-gen/generators/app/app/app.rb.tt
141
141
  - lib/padrino-gen/generators/app/app/controllers/.empty_directory
142
142
  - lib/padrino-gen/generators/app/app/helpers/.empty_directory
143
+ - lib/padrino-gen/generators/app/app/public/images/.empty_directory
144
+ - lib/padrino-gen/generators/app/app/public/javascripts/.empty_directory
145
+ - lib/padrino-gen/generators/app/app/public/stylesheets/.empty_directory
143
146
  - lib/padrino-gen/generators/app/app/views/.empty_directory
144
147
  - lib/padrino-gen/generators/app/config.ru
145
148
  - lib/padrino-gen/generators/app/config/apps.rb.tt
@@ -148,9 +151,6 @@ files:
148
151
  - lib/padrino-gen/generators/app/config/initializers/example.rb
149
152
  - lib/padrino-gen/generators/app/config/urls.rb.tt
150
153
  - lib/padrino-gen/generators/app/lib/.empty_directory
151
- - lib/padrino-gen/generators/app/public/images/.empty_directory
152
- - lib/padrino-gen/generators/app/public/javascripts/.empty_directory
153
- - lib/padrino-gen/generators/app/public/stylesheets/.empty_directory
154
154
  - lib/padrino-gen/generators/app/tmp/.empty_directory
155
155
  - lib/padrino-gen/generators/base.rb
156
156
  - lib/padrino-gen/generators/components/actions.rb