Sha256: 18e4819182de04a4b52257696bc759b1f2a7457f9b349554cceea0e545f04ab9

Contents?: true

Size: 1.63 KB

Versions: 16

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'
require_generator :data_mapper   => ['model']

class DataMapper::Generators::ModelGeneratorTest < Rails::Generators::TestCase
  destination File.join(Rails.root)
  tests DataMapper::Generators::ModelGenerator

  setup :prepare_destination
  setup :copy_routes

  test "invoke with model name" do
    content = run_generator %w(Account)

    assert_file "app/models/account.rb" do |account|
      assert_class "Account", account do |klass|
        assert_match /include DataMapper::Resource/, klass
        assert_match /property :id, Serial/, klass        
      end
    end
  end

  test "invoke with model name and attributes" do
    content = run_generator %w(Account name:string age:integer)

    assert_file "app/models/account.rb" do |account|
      assert_class "Account", account do |klass|
        assert_match /property :name, String/, klass
        assert_match /property :age, Integer/, klass        
      end
    end
  end  
     
  test "invoke with model name and --timestamps option" do
    content = run_generator %w(Account --timestamps)

    assert_file "app/models/account.rb" do |account|
      assert_class "Account", account do |klass|
        assert_match /property :created_at, DateTime/, klass
        assert_match /property :updated_at, DateTime/, klass        
      end
    end
  end  

  test "invoke with model name and --parent option" do
    content = run_generator %w(Admin --parent User)
    assert_file "app/models/admin.rb" do |account|
      assert_class "Admin", account do |klass|
        assert_no_match /property :id, Serial/, klass
        assert_match /<\s+User/, klass
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rails3-generators-1.0.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.6 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.5 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.4 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.3 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.2 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.1 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.17.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.16.1 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.16.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.15.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.14.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.13.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.12.1 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.12.0 test/lib/generators/data_mapper/model_generator_test.rb
rails3-generators-0.11.0 test/lib/generators/data_mapper/model_generator_test.rb