Ticket #7269: refactor_resource_generator_to_use_model_generator.patch
| File refactor_resource_generator_to_use_model_generator.patch, 3.2 kB (added by bscofield, 2 years ago) |
|---|
-
resource_generator.rb
old new 39 39 m.directory(File.join('test/functional', controller_class_path)) 40 40 m.directory(File.join('test/unit', class_path)) 41 41 42 m. template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))42 m.dependency 'model', [singular_name] + @args, :collision => :skip 43 43 44 44 m.template( 45 45 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb") … … 47 47 48 48 m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) 49 49 m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) 50 m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))51 m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))52 50 53 unless options[:skip_migration]54 m.migration_template(55 'migration.rb', 'db/migrate',56 :assigns => {57 :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",58 :attributes => attributes59 },60 :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"61 )62 end63 64 51 m.route_resources controller_file_name 65 52 end 66 53 end -
templates/unit_test.rb
old new 1 require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'2 3 class <%= class_name %>Test < Test::Unit::TestCase4 fixtures :<%= table_name %>5 6 # Replace this with your real tests.7 def test_truth8 assert true9 end10 end -
templates/model.rb
old new 1 class <%= class_name %> < ActiveRecord::Base2 end -
templates/fixtures.yml
old new 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html2 one:3 id: 14 <% for attribute in attributes -%>5 <%= attribute.name %>: <%= attribute.default %>6 <% end -%>7 two:8 id: 29 <% for attribute in attributes -%>10 <%= attribute.name %>: <%= attribute.default %>11 <% end -%> -
templates/migration.rb
old new 1 class <%= migration_name %> < ActiveRecord::Migration2 def self.up3 create_table :<%= table_name %> do |t|4 <% for attribute in attributes -%>5 t.column :<%= attribute.name %>, :<%= attribute.type %>6 <% end -%>7 end8 end9 10 def self.down11 drop_table :<%= table_name %>12 end13 end