diff options
| author | José Valim <jose.valim@gmail.com> | 2009-06-27 15:41:29 +0200 | 
|---|---|---|
| committer | José Valim <jose.valim@gmail.com> | 2009-06-27 21:30:00 +0200 | 
| commit | 7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7 (patch) | |
| tree | 2ef794a8dd1454b37e3bff4df4c7e1643eeee050 | |
| parent | ff44e5055cd92ee9c49c315cfffa3b0eb4feb844 (diff) | |
| download | rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.tar.gz rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.tar.bz2 rails-7b6c5ed7dbc2fcbaaf56deacd8061b3da51221e7.zip | |
Added parent option to model generator.
4 files changed, 14 insertions, 11 deletions
| diff --git a/railties/lib/generators/active_record/model/model_generator.rb b/railties/lib/generators/active_record/model/model_generator.rb index 448bf5c37f..45e773fde1 100644 --- a/railties/lib/generators/active_record/model/model_generator.rb +++ b/railties/lib/generators/active_record/model/model_generator.rb @@ -5,16 +5,11 @@ module ActiveRecord        check_class_collision -      # TODO Add parent support +      conditional_class_option :timestamps +      conditional_class_option :migration -      # TODO Add DEFAULTS support -      class_option :skip_timestamps, :type => :boolean, :default => false, -                   :desc => "Don't add timestamps to the migration file" - -      # TODO Make this a invoke_if -      # TODO Add DEFAULTS support -      class_option :skip_migration, :type => :boolean, :default => false, -                   :desc => "Don't generate a migration file" +      class_option :parent, :type => :string, :default => "ActiveRecord::Base", +                   :desc => "The parent class for the generated model"        def create_model_file          template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") @@ -28,6 +23,7 @@ module ActiveRecord  #          }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"  #        end        end +      end    end  end diff --git a/railties/lib/generators/active_record/model/templates/model.rb b/railties/lib/generators/active_record/model/templates/model.rb index 0656b06dfe..fb337d10e6 100644 --- a/railties/lib/generators/active_record/model/templates/model.rb +++ b/railties/lib/generators/active_record/model/templates/model.rb @@ -1,4 +1,4 @@ -class <%= class_name %> < ActiveRecord::Base +class <%= class_name %> < <%= options[:parent] %>  <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>    belongs_to :<%= attribute.name %>  <% end -%> diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index b9ec9eea62..5dd3b2aa84 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -5,9 +5,11 @@ module Rails      DEFAULTS = {        :fixture => true,        :helper => true, +      :migration => true,        :orm => 'active_record',        :test_framework => 'test_unit', -      :template_engine => 'erb' +      :template_engine => 'erb', +      :timestamps => true      }      ALIASES = { diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 904f77242d..55c08d0199 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -11,6 +11,11 @@ class ModelGeneratorTest < GeneratorsTestCase      assert_file "app/models/account.rb", /class Account < ActiveRecord::Base/    end +  def test_orm_with_parent_option +    run_generator ["account", "--parent", "Admin::Account"] +    assert_file "app/models/account.rb", /class Account < Admin::Account/ +  end +    def test_invokes_default_test_framework      run_generator      assert_file "test/unit/account_test.rb", /class AccountTest < ActiveSupport::TestCase/ | 
