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:
parent
df37e5cfab
commit
16ba6bcb77
@ -43,7 +43,7 @@ class Attachment < ActiveRecord::Base
|
|||||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
|
||||||
|
|
||||||
cattr_accessor :storage_path
|
cattr_accessor :storage_path
|
||||||
@@storage_path = Redmine::Configuration['attachments_storage_path'] || "#{RAILS_ROOT}/files"
|
@@storage_path = Redmine::Configuration['attachments_storage_path'] || "#{Rails.root}/files"
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
|
||||||
|
@ -545,6 +545,26 @@ class Project < ActiveRecord::Base
|
|||||||
enabled_modules.collect(&:name)
|
enabled_modules.collect(&:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Enable a specific module
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# project.enable_module!(:issue_tracking)
|
||||||
|
# project.enable_module!("issue_tracking")
|
||||||
|
def enable_module!(name)
|
||||||
|
enabled_modules << EnabledModule.new(:name => name.to_s) unless module_enabled?(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Disable a module if it exists
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# project.disable_module!(:issue_tracking)
|
||||||
|
# project.disable_module!("issue_tracking")
|
||||||
|
# project.disable_module!(project.enabled_modules.first)
|
||||||
|
def disable_module!(target)
|
||||||
|
target = enabled_modules.detect{|mod| target.to_s == mod.name} unless enabled_modules.include?(target)
|
||||||
|
target.destroy unless target.blank?
|
||||||
|
end
|
||||||
|
|
||||||
safe_attributes 'name',
|
safe_attributes 'name',
|
||||||
'description',
|
'description',
|
||||||
'homepage',
|
'homepage',
|
||||||
|
@ -75,7 +75,7 @@ class Setting < ActiveRecord::Base
|
|||||||
TIS-620)
|
TIS-620)
|
||||||
|
|
||||||
cattr_accessor :available_settings
|
cattr_accessor :available_settings
|
||||||
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
|
@@available_settings = YAML::load(File.open("#{Rails.root}/config/settings.yml"))
|
||||||
Redmine::Plugin.all.each do |plugin|
|
Redmine::Plugin.all.each do |plugin|
|
||||||
next unless plugin.settings
|
next unless plugin.settings
|
||||||
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
||||||
|
@ -14,7 +14,7 @@ class RedminePluginControllerGenerator < ControllerGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destination_root
|
def destination_root
|
||||||
File.join(RAILS_ROOT, plugin_path)
|
File.join(Rails.root, plugin_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def manifest
|
def manifest
|
||||||
|
@ -14,7 +14,7 @@ class RedminePluginModelGenerator < ModelGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destination_root
|
def destination_root
|
||||||
File.join(RAILS_ROOT, plugin_path)
|
File.join(Rails.root, plugin_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def manifest
|
def manifest
|
||||||
|
@ -58,7 +58,7 @@ module Redmine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid_languages
|
def valid_languages
|
||||||
@@valid_languages ||= Dir.glob(File.join(RAILS_ROOT, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym)
|
@@valid_languages ||= Dir.glob(File.join(Rails.root, 'config', 'locales', '*.yml')).collect {|f| File.basename(f).split('.').first}.collect(&:to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_language(lang)
|
def find_language(lang)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -69,7 +69,7 @@ module Redmine #:nodoc:
|
|||||||
p.name(id.to_s.humanize) if p.name.nil?
|
p.name(id.to_s.humanize) if p.name.nil?
|
||||||
# Adds plugin locales if any
|
# Adds plugin locales if any
|
||||||
# YAML translation files should be found under <plugin>/config/locales/
|
# YAML translation files should be found under <plugin>/config/locales/
|
||||||
::I18n.load_path += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', id.to_s, 'config', 'locales', '*.yml'))
|
::I18n.load_path += Dir.glob(File.join(Rails.root, 'vendor', 'plugins', id.to_s, 'config', 'locales', '*.yml'))
|
||||||
registered_plugins[id] = p
|
registered_plugins[id] = p
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ module Redmine
|
|||||||
end
|
end
|
||||||
if Rails.env == 'development'
|
if Rails.env == 'development'
|
||||||
# Capture stderr when running in dev environment
|
# Capture stderr when running in dev environment
|
||||||
cmd = "#{cmd} 2>>#{RAILS_ROOT}/log/scm.stderr.log"
|
cmd = "#{cmd} 2>>#{Rails.root}/log/scm.stderr.log"
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
if RUBY_VERSION < '1.9'
|
if RUBY_VERSION < '1.9'
|
||||||
|
@ -14,7 +14,7 @@ module Redmine
|
|||||||
|
|
||||||
def self.revision
|
def self.revision
|
||||||
revision = nil
|
revision = nil
|
||||||
entries_path = "#{RAILS_ROOT}/.svn/entries"
|
entries_path = "#{Rails.root}/.svn/entries"
|
||||||
if File.readable?(entries_path)
|
if File.readable?(entries_path)
|
||||||
begin
|
begin
|
||||||
f = File.open(entries_path, 'r')
|
f = File.open(entries_path, 'r')
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -20,7 +20,7 @@ module Redmine
|
|||||||
module MyPage
|
module MyPage
|
||||||
module Block
|
module Block
|
||||||
def self.additional_blocks
|
def self.additional_blocks
|
||||||
@@additional_blocks ||= Dir.glob("#{RAILS_ROOT}/vendor/plugins/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
|
@@additional_blocks ||= Dir.glob("#{Rails.root}/vendor/plugins/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
|
||||||
name = File.basename(file).split('.').first.gsub(/^_/, '')
|
name = File.basename(file).split('.').first.gsub(/^_/, '')
|
||||||
h[name] = name.to_sym
|
h[name] = name.to_sym
|
||||||
h
|
h
|
||||||
|
@ -7,7 +7,7 @@ task :extract_fixtures => :environment do
|
|||||||
ActiveRecord::Base.establish_connection
|
ActiveRecord::Base.establish_connection
|
||||||
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
|
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
|
||||||
i = "000"
|
i = "000"
|
||||||
File.open("#{RAILS_ROOT}/#{table_name}.yml", 'w' ) do |file|
|
File.open("#{Rails.root}/#{table_name}.yml", 'w' ) do |file|
|
||||||
data = ActiveRecord::Base.connection.select_all(sql % table_name)
|
data = ActiveRecord::Base.connection.select_all(sql % table_name)
|
||||||
file.write data.inject({}) { |hash, record|
|
file.write data.inject({}) { |hash, record|
|
||||||
# cast extracted values
|
# cast extracted values
|
||||||
@ -20,3 +20,4 @@ task :extract_fixtures => :environment do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
desc 'Generates a configuration file for cookie store sessions.'
|
desc 'Generates a configuration file for cookie store sessions.'
|
||||||
|
|
||||||
file 'config/initializers/session_store.rb' do
|
file 'config/initializers/session_store.rb' do
|
||||||
path = File.join(RAILS_ROOT, 'config', 'initializers', 'session_store.rb')
|
path = File.join(Rails.root, 'config', 'initializers', 'session_store.rb')
|
||||||
secret = ActiveSupport::SecureRandom.hex(40)
|
secret = ActiveSupport::SecureRandom.hex(40)
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
f.write <<"EOF"
|
f.write <<"EOF"
|
||||||
|
4
test/fixtures/repositories.yml
vendored
4
test/fixtures/repositories.yml
vendored
@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
repositories_001:
|
repositories_001:
|
||||||
project_id: 1
|
project_id: 1
|
||||||
url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
|
url: file:///<%= Rails.root %>/tmp/test/subversion_repository
|
||||||
id: 10
|
id: 10
|
||||||
root_url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
|
root_url: file:///<%= Rails.root %>/tmp/test/subversion_repository
|
||||||
password: ""
|
password: ""
|
||||||
login: ""
|
login: ""
|
||||||
type: Subversion
|
type: Subversion
|
||||||
|
@ -32,7 +32,7 @@ class ApplicationControllerTest < ActionController::TestCase
|
|||||||
|
|
||||||
# check that all language files are valid
|
# check that all language files are valid
|
||||||
def test_localization
|
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
|
assert_equal lang_files_count, valid_languages.size
|
||||||
valid_languages.each do |lang|
|
valid_languages.each do |lang|
|
||||||
assert set_language_if_valid(lang)
|
assert set_language_if_valid(lang)
|
||||||
|
@ -32,7 +32,7 @@ class AttachmentsControllerTest < ActionController::TestCase
|
|||||||
@controller = AttachmentsController.new
|
@controller = AttachmentsController.new
|
||||||
@request = ActionController::TestRequest.new
|
@request = ActionController::TestRequest.new
|
||||||
@response = ActionController::TestResponse.new
|
@response = ActionController::TestResponse.new
|
||||||
Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
|
Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
|
||||||
User.current = nil
|
User.current = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,9 +78,11 @@ class ActiveSupport::TestCase
|
|||||||
|
|
||||||
# Use a temporary directory for attachment related tests
|
# Use a temporary directory for attachment related tests
|
||||||
def set_tmp_attachments_directory
|
def set_tmp_attachments_directory
|
||||||
Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test")
|
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")
|
unless File.directory?("#{Rails.root}/tmp/test/attachments")
|
||||||
Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
|
Dir.mkdir "#{Rails.root}/tmp/test/attachments"
|
||||||
|
end
|
||||||
|
Attachment.storage_path = "#{Rails.root}/tmp/test/attachments"
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_settings(options, &block)
|
def with_settings(options, &block)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -166,7 +166,7 @@ class Redmine::Hook::ManagerTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def view_hook_helper
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -597,6 +597,54 @@ class ProjectTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
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
|
def test_enabled_module_names_should_not_recreate_enabled_modules
|
||||||
project = Project.find(1)
|
project = Project.find(1)
|
||||||
# Remove one module
|
# Remove one module
|
||||||
|
Loading…
x
Reference in New Issue
Block a user