mirror of
https://github.com/redmine/redmine.git
synced 2026-05-07 02:17:43 +02:00
Merged r6098 from trunk.
Added Project#enable_module! and Project#disable_module! git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.2-stable@6104 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
4
test/fixtures/repositories.yml
vendored
4
test/fixtures/repositories.yml
vendored
@@ -1,9 +1,9 @@
|
||||
---
|
||||
repositories_001:
|
||||
project_id: 1
|
||||
url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
|
||||
url: file:///<%= Rails.root %>/tmp/test/subversion_repository
|
||||
id: 10
|
||||
root_url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
|
||||
root_url: file:///<%= Rails.root %>/tmp/test/subversion_repository
|
||||
password: ""
|
||||
login: ""
|
||||
type: Subversion
|
||||
|
||||
@@ -32,7 +32,7 @@ class ApplicationControllerTest < ActionController::TestCase
|
||||
|
||||
# check that all language files are valid
|
||||
def test_localization
|
||||
lang_files_count = Dir["#{RAILS_ROOT}/config/locales/*.yml"].size
|
||||
lang_files_count = Dir["#{Rails.root}/config/locales/*.yml"].size
|
||||
assert_equal lang_files_count, valid_languages.size
|
||||
valid_languages.each do |lang|
|
||||
assert set_language_if_valid(lang)
|
||||
|
||||
@@ -32,7 +32,7 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||
@controller = AttachmentsController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
|
||||
Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -78,11 +78,13 @@ class ActiveSupport::TestCase
|
||||
|
||||
# Use a temporary directory for attachment related tests
|
||||
def set_tmp_attachments_directory
|
||||
Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test")
|
||||
Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
|
||||
Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
|
||||
Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test")
|
||||
unless File.directory?("#{Rails.root}/tmp/test/attachments")
|
||||
Dir.mkdir "#{Rails.root}/tmp/test/attachments"
|
||||
end
|
||||
Attachment.storage_path = "#{Rails.root}/tmp/test/attachments"
|
||||
end
|
||||
|
||||
|
||||
def with_settings(options, &block)
|
||||
saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
|
||||
options.each {|k, v| Setting[k] = v}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
# redMine - project management software
|
||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
@@ -20,10 +20,10 @@ require File.expand_path('../../../../test_helper', __FILE__)
|
||||
class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
||||
|
||||
fixtures :issues
|
||||
|
||||
|
||||
# Some hooks that are manually registered in these tests
|
||||
class TestHook < Redmine::Hook::ViewListener; end
|
||||
|
||||
|
||||
class TestHook1 < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
'Test hook 1 listener.'
|
||||
@@ -35,13 +35,13 @@ class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
||||
'Test hook 2 listener.'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class TestHook3 < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
"Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class TestLinkToHook < TestHook
|
||||
def view_layouts_base_html_head(context)
|
||||
link_to('Issues', :controller => 'issues')
|
||||
@@ -51,54 +51,54 @@ class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
||||
class TestHookHelperController < ActionController::Base
|
||||
include Redmine::Hook::Helper
|
||||
end
|
||||
|
||||
|
||||
class TestHookHelperView < ActionView::Base
|
||||
include Redmine::Hook::Helper
|
||||
end
|
||||
|
||||
|
||||
Redmine::Hook.clear_listeners
|
||||
|
||||
|
||||
def setup
|
||||
@hook_module = Redmine::Hook
|
||||
end
|
||||
|
||||
|
||||
def teardown
|
||||
@hook_module.clear_listeners
|
||||
end
|
||||
|
||||
|
||||
def test_clear_listeners
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
@hook_module.add_listener(TestHook1)
|
||||
@hook_module.add_listener(TestHook2)
|
||||
assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
|
||||
|
||||
@hook_module.clear_listeners
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
end
|
||||
|
||||
|
||||
def test_add_listener
|
||||
assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
@hook_module.add_listener(TestHook1)
|
||||
assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook
|
||||
@hook_module.add_listener(TestHook1)
|
||||
assert_equal ['Test hook 1 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_with_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_equal ['Context keys: bar, controller, foo, project, request.'],
|
||||
hook_helper.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a')
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_with_multiple_listeners
|
||||
@hook_module.add_listener(TestHook1)
|
||||
@hook_module.add_listener(TestHook2)
|
||||
assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
|
||||
|
||||
# Context: Redmine::Hook::Helper.call_hook default_url
|
||||
def test_call_hook_default_url_options
|
||||
@hook_module.add_listener(TestLinkToHook)
|
||||
@@ -111,27 +111,27 @@ class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /project/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_from_controller_with_controller_added_to_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /controller/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_from_controller_with_request_added_to_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /request/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_from_view_with_project_added_to_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /project/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_from_view_with_controller_added_to_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /controller/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
end
|
||||
|
||||
|
||||
def test_call_hook_from_view_with_request_added_to_context
|
||||
@hook_module.add_listener(TestHook3)
|
||||
assert_match /request/i, view_hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
@@ -146,27 +146,27 @@ class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
||||
|
||||
def test_call_hook_should_not_change_the_default_url_for_email_notifications
|
||||
issue = Issue.find(1)
|
||||
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Mailer.deliver_issue_add(issue)
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
|
||||
|
||||
@hook_module.add_listener(TestLinkToHook)
|
||||
hook_helper.call_hook(:view_layouts_base_html_head)
|
||||
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
Mailer.deliver_issue_add(issue)
|
||||
mail2 = ActionMailer::Base.deliveries.last
|
||||
|
||||
|
||||
assert_equal mail.body, mail2.body
|
||||
end
|
||||
|
||||
|
||||
def hook_helper
|
||||
@hook_helper ||= TestHookHelperController.new
|
||||
end
|
||||
|
||||
def view_hook_helper
|
||||
@view_hook_helper ||= TestHookHelperView.new(RAILS_ROOT + '/app/views')
|
||||
@view_hook_helper ||= TestHookHelperView.new(Rails.root.to_s + '/app/views')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -597,6 +597,54 @@ class ProjectTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "enabled_modules" do
|
||||
setup do
|
||||
@project = Project.find(1)
|
||||
end
|
||||
|
||||
should "define module by names and preserve ids" do
|
||||
# Remove one module
|
||||
modules = @project.enabled_modules.slice(0..-2)
|
||||
assert modules.any?
|
||||
assert_difference 'EnabledModule.count', -1 do
|
||||
@project.enabled_module_names = modules.collect(&:name)
|
||||
end
|
||||
@project.reload
|
||||
# Ids should be preserved
|
||||
assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
|
||||
end
|
||||
|
||||
should "enable a module" do
|
||||
@project.enabled_module_names = []
|
||||
@project.reload
|
||||
assert_equal [], @project.enabled_module_names
|
||||
#with string
|
||||
@project.enable_module!("issue_tracking")
|
||||
assert_equal ["issue_tracking"], @project.enabled_module_names
|
||||
#with symbol
|
||||
@project.enable_module!(:gantt)
|
||||
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
|
||||
#don't add a module twice
|
||||
@project.enable_module!("issue_tracking")
|
||||
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
|
||||
end
|
||||
|
||||
should "disable a module" do
|
||||
#with string
|
||||
assert @project.enabled_module_names.include?("issue_tracking")
|
||||
@project.disable_module!("issue_tracking")
|
||||
assert ! @project.reload.enabled_module_names.include?("issue_tracking")
|
||||
#with symbol
|
||||
assert @project.enabled_module_names.include?("gantt")
|
||||
@project.disable_module!(:gantt)
|
||||
assert ! @project.reload.enabled_module_names.include?("gantt")
|
||||
#with EnabledModule object
|
||||
first_module = @project.enabled_modules.first
|
||||
@project.disable_module!(first_module)
|
||||
assert ! @project.reload.enabled_module_names.include?(first_module.name)
|
||||
end
|
||||
end
|
||||
|
||||
def test_enabled_module_names_should_not_recreate_enabled_modules
|
||||
project = Project.find(1)
|
||||
# Remove one module
|
||||
|
||||
Reference in New Issue
Block a user