aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/metal_test.rb
blob: a31f4ab27368eb21ff6510687b36e412f7da9e75 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'abstract_unit'
require 'initializer'

class MetalTest < Test::Unit::TestCase
  def test_metals_should_return_list_of_found_metal_apps
    use_appdir("singlemetal") do
      assert_equal(["FooMetal"], found_metals_as_string_array)
    end
  end

  def test_metals_should_return_alphabetical_list_of_found_metal_apps
    use_appdir("multiplemetals") do
      assert_equal(["MetalA", "MetalB"], found_metals_as_string_array)
    end
  end

  def test_metals_load_order_should_be_overriden_by_requested_metals
    use_appdir("multiplemetals") do
      Rails::Rack::Metal.requested_metals = ["MetalB", "MetalA"]
      assert_equal(["MetalB", "MetalA"], found_metals_as_string_array)
    end
  end

  def test_metals_not_listed_should_not_load
    use_appdir("multiplemetals") do
      Rails::Rack::Metal.requested_metals = ["MetalB"]
      assert_equal(["MetalB"], found_metals_as_string_array)
    end
  end

  def test_metal_finding_should_work_with_subfolders
    use_appdir("subfolders") do
      assert_equal(["Folder::MetalA", "Folder::MetalB"], found_metals_as_string_array)
    end
  end

  def test_metal_finding_with_requested_metals_should_work_with_subfolders
    use_appdir("subfolders") do
      Rails::Rack::Metal.requested_metals = ["Folder::MetalB"]
      assert_equal(["Folder::MetalB"], found_metals_as_string_array)
    end
  end

  private

  def use_appdir(root)
    dir = "#{File.dirname(__FILE__)}/fixtures/metal/#{root}"
    Rails::Rack::Metal.metal_paths = ["#{dir}/app/metal"]
    Rails::Rack::Metal.requested_metals = nil
    $LOAD_PATH << "#{dir}/app/metal"
    yield
  end

  def found_metals_as_string_array
    Rails::Rack::Metal.metals.map { |m| m.to_s }
  end
end