Add model_subclass generator with deprecation warning.
This commit is contained in:
parent
7b6c5ed7db
commit
fdeee65c96
|
@ -8,7 +8,7 @@ module ActiveRecord
|
|||
conditional_class_option :timestamps
|
||||
conditional_class_option :migration
|
||||
|
||||
class_option :parent, :type => :string, :default => "ActiveRecord::Base",
|
||||
class_option :parent, :type => :string,
|
||||
:desc => "The parent class for the generated model"
|
||||
|
||||
def create_model_file
|
||||
|
@ -17,11 +17,17 @@ module ActiveRecord
|
|||
|
||||
# TODO Add migration support
|
||||
def create_migration_file
|
||||
# unless options[:skip_migration]
|
||||
if options[:migration] && options[:parent].nil?
|
||||
# m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
||||
# :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
||||
# }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def parent_class_name
|
||||
options[:parent] || "ActiveRecord::Base"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class <%= class_name %> < <%= options[:parent] %>
|
||||
class <%= class_name %> < <%= parent_class_name.classify %>
|
||||
<% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
|
||||
belongs_to :<%= attribute.name %>
|
||||
<% end -%>
|
||||
|
|
|
@ -12,6 +12,9 @@ Description:
|
|||
This generator invokes your configured ORM and test framework, which
|
||||
defaults to ActiveRecord and TestUnit.
|
||||
|
||||
Finally, if --parent option is given, it's used as superclass of the
|
||||
created model. This allows you create Single Table Inheritance models.
|
||||
|
||||
Examples:
|
||||
`./script/generate model account`
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
module Rails
|
||||
module Generators
|
||||
class ModelSubclassGenerator < Base
|
||||
desc "model_subclass is deprecated. Invoke model with --parent option instead."
|
||||
|
||||
def say_deprecation_warn
|
||||
say self.class.desc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,6 +16,11 @@ class ModelGeneratorTest < GeneratorsTestCase
|
|||
assert_file "app/models/account.rb", /class Account < Admin::Account/
|
||||
end
|
||||
|
||||
def test_orm_with_underscored_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/
|
||||
|
|
Loading…
Reference in New Issue