2009-11-14 05:38:35 -05: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
|
2006-08-29 06:43:00 -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
|
|
|
|
property('Bogus') {raise}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
assert !property_defined?('Bogus')
|
|
|
|
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
|
|
|
|
property 'Hello', 'World'
|
|
|
|
end
|
|
|
|
assert_property 'Hello', 'World'
|
|
|
|
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
|
|
|
|
property('Goodbye') {'World'}
|
|
|
|
end
|
|
|
|
assert_property 'Goodbye', 'World'
|
|
|
|
end
|
2008-04-22 16:44:13 -04:00
|
|
|
|
2013-05-03 10:37:22 -04:00
|
|
|
def test_rails_version
|
|
|
|
assert_property 'Rails version',
|
|
|
|
File.read(File.realpath('../../../RAILS_VERSION', __FILE__)).chomp
|
|
|
|
end
|
|
|
|
|
2008-11-24 21:47:42 -05:00
|
|
|
def test_framework_version
|
2013-03-24 01:41:13 -04:00
|
|
|
assert_property 'Active Support version', ActiveSupport.version.to_s
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2008-04-22 16:44:13 -04:00
|
|
|
|
2008-11-24 21:47:42 -05:00
|
|
|
def test_frameworks_exist
|
|
|
|
Rails::Info.frameworks.each do |framework|
|
2012-04-03 09:16:09 -04:00
|
|
|
dir = File.dirname(__FILE__) + "/../../" + framework.delete('_')
|
2008-11-24 21:47:42 -05:00
|
|
|
assert File.directory?(dir), "#{framework.classify} does not exist"
|
2007-07-24 22:50:35 -04:00
|
|
|
end
|
|
|
|
end
|
2005-11-04 23:44:33 -05:00
|
|
|
|
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
|
|
|
|
property 'Middleware', ['Rack::Lock', 'Rack::Static']
|
|
|
|
end
|
|
|
|
|
2009-04-07 10:16:48 -04:00
|
|
|
html = Rails::Info.to_html
|
|
|
|
assert html.include?('<tr><td class="name">Middleware</td>')
|
|
|
|
properties.value_for('Middleware').each do |value|
|
|
|
|
assert html.include?("<li>#{CGI.escapeHTML(value)}</li>")
|
|
|
|
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
|