framework_extension_test.rb 1.6 KB
Newer Older
1 2 3 4
require "isolation/abstract_unit"

module PluginsTest
  class FrameworkExtensionTest < Test::Unit::TestCase
5 6
    include ActiveSupport::Testing::Isolation

7 8 9
    def setup
      build_app
      boot_rails
C
Carl Lerche 已提交
10
      FileUtils.rm_rf("#{app_path}/config/environments")
11
      require "rails/all"
12 13 14 15 16
    end

    test "rake_tasks block is executed when MyApp.load_tasks is called" do
      $ran_block = false

C
Carl Lerche 已提交
17
      class MyTie < Rails::Railtie
18 19 20 21 22 23 24 25 26 27 28
        rake_tasks do
          $ran_block = true
        end
      end

      require "#{app_path}/config/environment"

      assert !$ran_block
      require 'rake'
      require 'rake/testtask'
      require 'rake/rdoctask'
29

30 31 32
      AppTemplate::Application.load_tasks
      assert $ran_block
    end
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

    test "generators block is executed when MyApp.load_generators is called" do
      $ran_block = false

      class MyTie < Rails::Railtie
        generators do
          $ran_block = true
        end
      end

      require "#{app_path}/config/environment"

      assert !$ran_block
      AppTemplate::Application.load_generators
      assert $ran_block
    end
49 50 51
  end

  class ActiveRecordExtensionTest < Test::Unit::TestCase
52 53
    include ActiveSupport::Testing::Isolation

54 55 56
    def setup
      build_app
      boot_rails
C
Carl Lerche 已提交
57
      FileUtils.rm_rf("#{app_path}/config/environments")
58 59 60 61 62 63 64 65 66 67 68
    end

    test "active_record extensions are applied to ActiveRecord" do
      add_to_config "config.active_record.table_name_prefix = 'tbl_'"

      require "#{app_path}/config/environment"

      assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix
    end
  end
end