aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/named_base_test.rb
blob: 98cbf9b8f623c96e0c8c6760db7d36e35cb4855f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'abstract_unit'
require 'generators/generators_test_helper'
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'

# Mock out what we need from AR::Base.
module ActiveRecord
  class Base
    class << self
      attr_accessor :pluralize_table_names
    end
    self.pluralize_table_names = true
  end
end

class NamedBaseTest < GeneratorsTestCase

  def test_named_generator_attributes
    g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"]
    assert_equal 'admin/foo', g.name
    assert_equal %w(admin), g.class_path
    assert_equal 1, g.class_nesting_depth
    assert_equal 'Admin::Foo', g.class_name
    assert_equal 'foo', g.singular_name
    assert_equal 'foos', g.plural_name
    assert_equal g.singular_name, g.file_name
    assert_equal "admin_#{g.plural_name}", g.table_name
  end

  def test_named_generator_attributes_without_pluralized
    ActiveRecord::Base.pluralize_table_names = false
    g = Rails::Generators::ScaffoldControllerGenerator.new ["admin/foo"]
    assert_equal "admin_#{g.singular_name}", g.table_name
  end

  def test_scaffold_plural_names
    g = Rails::Generators::ScaffoldControllerGenerator.new ["ProductLine"]
    assert_equal "ProductLines", g.controller_name
    assert_equal "ProductLines", g.controller_class_name
    assert_equal "product_lines", g.controller_file_name
  end

end