2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "abstract_unit"
|
2006-08-29 06:43:00 -04:00
|
|
|
|
2009-04-07 10:16:48 -04:00
|
|
|
class InfoTest < ActiveSupport::TestCase
|
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
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not 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",
|
2017-05-15 10:17:28 -04:00
|
|
|
File.read(File.realpath("../../RAILS_VERSION", __dir__)).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
|
|
|
|
|
2016-12-23 09:45:39 -05:00
|
|
|
private
|
2008-04-22 16:44:13 -04:00
|
|
|
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
|