diff --git a/app/models/setting.rb b/app/models/setting.rb index 70d8f2b..26e4c91 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -84,6 +84,8 @@ class Setting < ActiveRecord::Base validates_inclusion_of :name, :in => @@available_settings.keys validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } + before_save :remove_trailing_slash_from_hostname + # Hash used to cache setting values @cached_settings = {} @cached_cleared_on = Time.now @@ -157,6 +159,10 @@ class Setting < ActiveRecord::Base end private + def remove_trailing_slash_from_hostname + value.gsub!(/\/+$/, '') if name == 'host_name' + end + # Returns the Setting instance for the setting named name # (record found in database or new record with default value) def self.find_or_default(name) diff --git a/test/functional/settings_controller_test.rb b/test/functional/settings_controller_test.rb index f7ff2d1..791655c 100644 --- a/test/functional/settings_controller_test.rb +++ b/test/functional/settings_controller_test.rb @@ -56,4 +56,12 @@ class SettingsControllerTest < ActionController::TestCase assert_equal %w(issue_added issue_updated news_added), Setting.notified_events assert_equal 'Test footer', Setting.emails_footer end + + # Test if the host-name is modified so that no forward-slash is at the end of the string. + def test_post_edit_host_name + post :edit, :settings => {:host_name => 'http://www.example.com/'} + assert_redirected_to 'settings/edit' + assert_equal 'http://www.example.com', Setting.host_name + end + end -- 1.7.1