Skip to content

Commit

Permalink
Merged r6098 from trunk.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jbbarth committed Jun 20, 2011
1 parent df37e5c commit 16ba6bc
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Attachment < ActiveRecord::Base
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}

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
if self.filesize > Setting.attachment_max_size.to_i.kilobytes
Expand Down
22 changes: 21 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,27 @@ def enabled_module_names=(module_names)
def enabled_module_names
enabled_modules.collect(&:name)
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',
'description',
'homepage',
Expand Down
2 changes: 1 addition & 1 deletion app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Setting < ActiveRecord::Base
TIS-620)

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|
next unless plugin.settings
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(runtime_args, runtime_options = {})
end

def destination_root
File.join(RAILS_ROOT, plugin_path)
File.join(Rails.root, plugin_path)
end

def manifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(runtime_args, runtime_options = {})
end

def destination_root
File.join(RAILS_ROOT, plugin_path)
File.join(Rails.root, plugin_path)
end

def manifest
Expand Down
6 changes: 3 additions & 3 deletions lib/redmine/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def day_name(day)
def month_name(month)
::I18n.t('date.month_names')[month]
end

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

def find_language(lang)
@@languages_lookup = valid_languages.inject({}) {|k, v| k[v.to_s.downcase] = v; k }
@@languages_lookup[lang.to_s.downcase]
Expand Down
10 changes: 5 additions & 5 deletions lib/redmine/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# redMine - project management software
# Copyright (C) 2006-2007 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.
Expand Down Expand Up @@ -69,7 +69,7 @@ def self.register(id, &block)
p.name(id.to_s.humanize) if p.name.nil?
# Adds plugin locales if any
# 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
end

Expand Down
2 changes: 1 addition & 1 deletion lib/redmine/scm/adapters/abstract_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def self.shellout(cmd, &block)
end
if Rails.env == 'development'
# 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
begin
if RUBY_VERSION < '1.9'
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module VERSION #:nodoc:

def self.revision
revision = nil
entries_path = "#{RAILS_ROOT}/.svn/entries"
entries_path = "#{Rails.root}/.svn/entries"
if File.readable?(entries_path)
begin
f = File.open(entries_path, 'r')
Expand Down
8 changes: 4 additions & 4 deletions lib/redmine/views/my_page/block.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# 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
# 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.
Expand All @@ -20,7 +20,7 @@ module Views
module MyPage
module Block
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(/^_/, '')
h[name] = name.to_sym
h
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/extract_fixtures.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ task :extract_fixtures => :environment do
ActiveRecord::Base.establish_connection
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
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)
file.write data.inject({}) { |hash, record|
# cast extracted values
Expand All @@ -19,4 +19,5 @@ task :extract_fixtures => :environment do
}.to_yaml
end
end
end
end

2 changes: 1 addition & 1 deletion lib/tasks/initializers.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
desc 'Generates a configuration file for cookie store sessions.'

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)
File.open(path, 'w') do |f|
f.write <<"EOF"
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/repositories.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/application_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setup

# 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)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/attachments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setup
@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

Expand Down
10 changes: 6 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ def mock_file

# 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}
Expand Down
Loading

0 comments on commit 16ba6bc

Please sign in to comment.