#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview/initializer' ) class TestConfiguration < Test::Unit::TestCase CurrentPath = File.dirname(__FILE__) #TestCasesDir = File.join(CurrentPath, '../..') TestFixturesDir = File.join(CurrentPath, '../fixtures/configs') def setup #STDOUT.puts "\n============= #{method_name} ===============" end def test_mv_install_dir_refs # default settings for standalone operation config = MasterView::Configuration.new code_base_from_install_dir = "#{config.mv_installation_dir}/lib/masterview" assert File.directory?( code_base_from_install_dir ), "no lib/masterview code dir at mv_installation_dir='#{config.mv_installation_dir}'" assert_equal code_base_from_install_dir, config.mv_code_base_dir, "inconsistent mv_code_base_dir='#{config.mv_code_base_dir}'" end def test_default_settings_standalone # default settings for standalone operation config = MasterView::Configuration.new # general options assert ! config.rails_app?, 'standalone config is not a rails app' assert ! config.on_rails?, 'standalone config is not running on rails' assert_nil config.rails_root_path, 'no rails root for a standalone config' assert_nil config.config_dir_path, 'no opinion on location of config settings in standalone config' #??assert_equal "#{config.root_path}/masterview/config", config.config_dir_path, 'default config settings dir' assert_nil config.environment, 'no opinion on environment for a standalone config' assert config.logger, 'default config includes a logger' assert_equal 'WARN', config.log_level, 'default log level is WARN unless development' # template source/dst/parsing options... assert_equal "#{config.root_path}/masterview/templates", config.template_src_dir_path, 'default templates dir' assert_equal "#{config.root_path}/masterview/output", config.template_dst_dir_path, 'default template output dir' # rails application options #we probably ought to support this for non-rails app iff src/dst dirs known, anyway #assert ! config.parse_masterview_templates_at_startup end def test_default_settings_rails_app # default settings for a rails app fake_rails_app_root = File.join( TestFixturesDir, 'fake_rails_app' ) rails_root_full_path = File.expand_path(fake_rails_app_root) rails_views_root = File.join(rails_root_full_path, 'app/views') config = MasterView::Configuration.new( :rails_app_root_path => fake_rails_app_root ) # general options assert config.rails_app?, 'this is a rails app' assert ! config.on_rails?, 'operating on a rails app but not running rails' assert_equal rails_root_full_path, config.rails_root_path, 'we explicitly provided the rails root' assert_equal rails_root_full_path, config.root_path, 'app root is rails app root' assert_equal "#{rails_root_full_path}/config/masterview", config.config_dir_path, 'standard MV rails config settings dir' assert_nil config.environment, 'no opinion on environment when not running rails' assert config.logger, 'default config includes a logger' assert_equal 'WARN', config.log_level, 'default log level is WARN unless development' # template source/dst/parsing options... # check defaults - users would care about changing this assumption for release upgrade assert_equal "#{rails_root_full_path}/app/views", config.template_src_dir_path, 'default templates directory in rails app' assert_equal rails_views_root, config.template_dst_dir_path, 'default template output in rails is app/views' # rails application options assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app' assert ! config.reparse_changed_masterview_templates, 'reparsing changed templates is only supported when actually running on rails' assert ! config.enable_admin_pages end def test_config_settings_rails_app # default settings for a rails app (standard app settings, no env) fake_rails_app_root = File.join( TestFixturesDir, 'fake_rails_app_with_config' ) rails_root_full_path = File.expand_path(fake_rails_app_root) rails_views_root = File.join(rails_root_full_path, 'app/views') config = MasterView::Configuration.new( :rails_app_root_path => fake_rails_app_root ) MasterView::Initializer.run(:load_config_settings, config) # general options assert config.rails_app?, 'this should be configured for a rails app' assert ! config.on_rails?, 'operating on a rails app but not running rails' assert_equal rails_root_full_path, config.rails_root_path, 'we explicitly provided the rails root' assert_equal rails_root_full_path, config.root_path, 'app root is rails app root' assert_equal "#{rails_root_full_path}/config/masterview", config.config_dir_path, 'standard MV rails config settings dir' assert_nil config.environment, 'no point of view on environment when not running rails' assert_equal 'WARN', config.log_level, 'default log level is WARN unless development' # template source/dst/parsing options... # this application customized the output directory for its templates assert_equal "#{rails_root_full_path}/app/views", config.template_src_dir_path, 'default templates directory in rails app' assert_equal "#{rails_views_root}/content", config.template_dst_dir_path, 'alt template output dir' # rails application options assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app' assert ! config.reparse_changed_masterview_templates, 'reparsing changed templates is only supported when actually running on rails' assert ! config.enable_admin_pages end def test_config_settings_rails_app_development # default settings for a rails app (standard app settings, development config) fake_rails_app_root = File.join( TestFixturesDir, 'fake_rails_app_with_config' ) rails_root_full_path = File.expand_path(fake_rails_app_root) rails_views_root = File.join(rails_root_full_path, 'app/views') environment = 'development' config = MasterView::Configuration.new( :rails_app_root_path => fake_rails_app_root, :environment => environment ) MasterView::Initializer.run(:load_config_settings, config) # general options assert config.rails_app?, 'this should be configured for a rails app' assert ! config.on_rails?, 'operating on a rails app but not running rails' assert_equal rails_root_full_path, config.rails_root_path, 'we explicitly provided the rails root' assert_equal rails_root_full_path, config.root_path, 'app root is rails app root' assert_equal "#{rails_root_full_path}/config/masterview", config.config_dir_path, 'standard MV rails config settings dir' assert_equal environment, config.environment, "loading config settings for environment #{environment}" assert_equal 'INFO', config.log_level, 'default log level is WARN unless development' # template source/dst/parsing options... # this application wants to try some alternate templates for a development test assert_equal "#{rails_root_full_path}/app/mv_test_templates", config.template_src_dir_path, 'alt template dir in this dev config' assert_equal "#{rails_views_root}/content", config.template_dst_dir_path, 'alt template output dir' # rails application options assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app' #assert config.reparse_changed_masterview_templates, 'reparsing changed templates is enabled by default in development mode' assert ! config.enable_admin_pages end def test_config_settings_rails_app_production # default settings for a rails app (standard app settings, development config) fake_rails_app_root = File.join( TestFixturesDir, 'fake_rails_app_with_config' ) rails_root_full_path = File.expand_path(fake_rails_app_root) rails_views_root = File.join(rails_root_full_path, 'app/views') environment = 'production' config = MasterView::Configuration.new( :rails_app_root_path => fake_rails_app_root, :environment => environment ) MasterView::Initializer.run(:load_config_settings, config) # general options assert config.rails_app?, 'this should be configured for a rails app' assert ! config.on_rails?, 'operating on a rails app but not running rails' assert_equal rails_root_full_path, config.rails_root_path, 'we explicitly provided the rails root' assert_equal rails_root_full_path, config.root_path, 'app root is rails app root' assert_equal "#{rails_root_full_path}/config/masterview", config.config_dir_path, 'MV config settings loaded from rails app config' assert_equal environment, config.environment, "loading config settings for environment #{environment}" assert_equal 'WARN', config.log_level, 'default log level is WARN unless development' # template source/dst/parsing options... assert_equal "#{rails_root_full_path}/app/views", config.template_src_dir_path, 'default templates directory in rails app' assert_equal "#{rails_views_root}/content", config.template_dst_dir_path, 'alt template output dir' # rails application options assert config.parse_masterview_templates_at_startup, 'template parsing at startup should be on by default for a rails app' #assert config.reparse_changed_masterview_templates, 'reparsing changed templates is enabled by default in development mode' assert ! config.enable_admin_pages, 'this app doesn\'t want the MasterView admin pages in the production site' end end