1 require File.dirname(__FILE__) + '/../test_helper'
3 class ExtensionInitializationTest < Test::Unit::TestCase
5 Dependencies.mechanism = :load
6 Radiant::ExtensionLoader.reactivate
10 Dependencies.mechanism = :require
14 assert_nothing_raised { BasicExtension }
15 assert_equal File.join(File.expand_path(RADIANT_ROOT), 'test', 'fixtures', 'extensions', '01_basic'), BasicExtension.root
16 assert_equal 'Basic', BasicExtension.extension_name
17 assert_nothing_raised { BasicExtensionController }
18 assert_nothing_raised { BasicExtensionModel }
22 assert_basic_extension_annotations
25 BasicExtensionController.instance_variable_set("@action_methods", nil) # ActionController cached no index action
26 BasicExtension.version = "should get changed back on clear"
27 BasicExtensionController.module_eval do
29 render :text => "should get changed back on clear"
32 assert_view_paths :index => /should get changed/
34 #only want to clear the test extensions
35 old_list = Dependencies.explicitly_unloadable_constants
36 Dependencies.explicitly_unloadable_constants = Radiant::Extension.descendants.select {|ex| ex.root.index(TEST_ROOT) == 0}.map {|x| x.name }
38 Dependencies.explicitly_unloadable_constants = old_list
40 assert_basic_extension_annotations
48 def test_mailer_view_paths
49 mail = BasicExtensionMailer.create_message
50 assert_match /Hello, Extension Mailer World/, mail.body
53 def test_basic_extension_annotations
54 assert_basic_extension_annotations
57 def test_should_load_plugin_from_vendor_plugin
58 assert $LOAD_PATH.include?(BasicExtension.root + "/vendor/plugins/plugin_normal/lib")
59 assert Dependencies.load_paths.include?(BasicExtension.root + "/vendor/plugins/plugin_normal/lib")
60 assert Dependencies.load_once_paths.include?(BasicExtension.root + "/vendor/plugins/plugin_normal/lib")
61 assert defined?(NormalPlugin)
64 def test_should_add_extension_load_paths_to_requirable_load_path
65 assert_nothing_raised { require 'new_module' }
66 assert defined?(NewModule)
71 def assert_admin_tabs(more_tabs = [])
73 Radiant::AdminUI.tabs.each do |tab|
74 assert !tab_names.include?(tab.name), "duplicate tab #{tab.name.inspect}"
77 more_tabs.each do |tab_name|
78 assert Radiant::AdminUI.tabs.any? {|tab| tab.name == tab_name }
82 def assert_basic_extension_annotations
83 assert_equal "1.1", BasicExtension.version
84 assert_equal "just a test", BasicExtension.description
85 assert_equal "http://test.com", BasicExtension.url
88 def assert_view_paths(expected_messages = {}, message = nil)
89 expected_messages.reverse_merge!(
90 :index => /Hello, Extension World/,
91 :override => /Hello, Overridden Extension World/,
92 :routing => /You're routing works/
95 @controller = BasicExtensionController.new
96 @request = ActionController::TestRequest.new
97 @response = ActionController::TestResponse.new
99 [:index, :override, :routing].each do |action|
101 assert_match expected_messages[action], @response.body, message