2016-08-06 13:16:09 -04:00
|
|
|
require "abstract_unit"
|
2006-08-29 06:43:00 -04:00
|
|
|
|
2006-09-02 20:04:20 -04:00
|
|
|
unless defined?(Rails) && defined?(Rails::Info)
|
|
|
|
module Rails
|
|
|
|
class Info; end
|
|
|
|
end
|
2006-08-29 06:43:00 -04:00
|
|
|
end
|
2005-11-04 23:44:33 -05:00
|
|
|
|
2009-05-16 15:28:25 -04:00
|
|
|
require "active_support/core_ext/kernel/reporting"
|
|
|
|
|
2009-04-07 10:16:48 -04:00
|
|
|
class InfoTest < ActiveSupport::TestCase
|
2005-11-06 23:06:05 -05:00
|
|
|
def setup
|
|
|
|
Rails.send :remove_const, :Info
|
2016-08-06 13:16:09 -04:00
|
|
|
silence_warnings { load "rails/info.rb" }
|
2005-11-06 23:06:05 -05:00
|
|
|
end
|
2006-08-29 06:43:00 -04:00
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
def test_property_with_block_swallows_exceptions_and_ignores_property
|
|
|
|
assert_nothing_raised do
|
|
|
|
Rails::Info.module_eval do
|
2016-08-16 03:30:11 -04:00
|
|
|
property("Bogus") { raise }
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-06 13:16:09 -04:00
|
|
|
assert !property_defined?("Bogus")
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2008-04-22 16:44:13 -04:00
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
def test_property_with_string
|
|
|
|
Rails::Info.module_eval do
|
2016-08-06 13:16:09 -04:00
|
|
|
property "Hello", "World"
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_property "Hello", "World"
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2008-04-22 16:44:13 -04:00
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
def test_property_with_block
|
|
|
|
Rails::Info.module_eval do
|
2016-08-16 03:30:11 -04:00
|
|
|
property("Goodbye") { "World" }
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_property "Goodbye", "World"
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2008-04-22 16:44:13 -04:00
|
|
|
|
2013-05-03 10:37:22 -04:00
|
|
|
def test_rails_version
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_property "Rails version",
|
|
|
|
File.read(File.realpath("../../../RAILS_VERSION", __FILE__)).chomp
|
2013-05-03 10:37:22 -04:00
|
|
|
end
|
|
|
|
|
2009-04-07 10:16:48 -04:00
|
|
|
def test_html_includes_middleware
|
2009-09-26 13:41:17 -04:00
|
|
|
Rails::Info.module_eval do
|
2016-08-06 13:16:09 -04:00
|
|
|
property "Middleware", ["Rack::Lock", "Rack::Static"]
|
2009-09-26 13:41:17 -04:00
|
|
|
end
|
|
|
|
|
2009-04-07 10:16:48 -04:00
|
|
|
html = Rails::Info.to_html
|
2016-09-16 12:44:05 -04:00
|
|
|
assert_includes html, '<tr><td class="name">Middleware</td>'
|
2016-08-06 13:16:09 -04:00
|
|
|
properties.value_for("Middleware").each do |value|
|
2016-09-16 12:44:05 -04:00
|
|
|
assert_includes html, "<li>#{CGI.escapeHTML(value)}</li>"
|
2009-04-07 10:16:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-04-22 16:44:13 -04:00
|
|
|
protected
|
|
|
|
def properties
|
|
|
|
Rails::Info.properties
|
|
|
|
end
|
|
|
|
|
|
|
|
def property_defined?(property_name)
|
|
|
|
properties.names.include? property_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_property(property_name, value)
|
|
|
|
raise "Property #{property_name.inspect} not defined" unless
|
|
|
|
property_defined? property_name
|
|
|
|
assert_equal value, properties.value_for(property_name)
|
|
|
|
end
|
2005-11-16 19:32:16 -05:00
|
|
|
end
|