annotate .svn/pristine/bb/bb834d6c2f5551779bce71506eba9e5321f661e3.svn-base @ 1384:b51b5ae3734c luisf

Merge
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 20 Sep 2013 19:04:25 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class SettingTest < ActiveSupport::TestCase
Chris@1296 21
Chris@1296 22 def teardown
Chris@1296 23 Setting.clear_cache
Chris@1296 24 end
Chris@1296 25
Chris@1296 26 def test_read_default
Chris@1296 27 assert_equal "Redmine", Setting.app_title
Chris@1296 28 assert Setting.self_registration?
Chris@1296 29 assert !Setting.login_required?
Chris@1296 30 end
Chris@1296 31
Chris@1296 32 def test_update
Chris@1296 33 Setting.app_title = "My title"
Chris@1296 34 assert_equal "My title", Setting.app_title
Chris@1296 35 # make sure db has been updated (INSERT)
Chris@1296 36 assert_equal "My title", Setting.find_by_name('app_title').value
Chris@1296 37
Chris@1296 38 Setting.app_title = "My other title"
Chris@1296 39 assert_equal "My other title", Setting.app_title
Chris@1296 40 # make sure db has been updated (UPDATE)
Chris@1296 41 assert_equal "My other title", Setting.find_by_name('app_title').value
Chris@1296 42 end
Chris@1296 43
Chris@1296 44 def test_serialized_setting
Chris@1296 45 Setting.notified_events = ['issue_added', 'issue_updated', 'news_added']
Chris@1296 46 assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.notified_events
Chris@1296 47 assert_equal ['issue_added', 'issue_updated', 'news_added'], Setting.find_by_name('notified_events').value
Chris@1296 48 end
Chris@1296 49
Chris@1296 50 def test_setting_should_be_reloaded_after_clear_cache
Chris@1296 51 Setting.app_title = "My title"
Chris@1296 52 assert_equal "My title", Setting.app_title
Chris@1296 53
Chris@1296 54 s = Setting.find_by_name("app_title")
Chris@1296 55 s.value = 'New title'
Chris@1296 56 s.save!
Chris@1296 57 assert_equal "My title", Setting.app_title
Chris@1296 58
Chris@1296 59 Setting.clear_cache
Chris@1296 60 assert_equal "New title", Setting.app_title
Chris@1296 61 end
Chris@1296 62
Chris@1296 63 def test_per_page_options_array_should_be_an_empty_array_when_setting_is_blank
Chris@1296 64 with_settings :per_page_options => nil do
Chris@1296 65 assert_equal [], Setting.per_page_options_array
Chris@1296 66 end
Chris@1296 67
Chris@1296 68 with_settings :per_page_options => '' do
Chris@1296 69 assert_equal [], Setting.per_page_options_array
Chris@1296 70 end
Chris@1296 71 end
Chris@1296 72
Chris@1296 73 def test_per_page_options_array_should_be_an_array_of_integers
Chris@1296 74 with_settings :per_page_options => '10, 25, 50' do
Chris@1296 75 assert_equal [10, 25, 50], Setting.per_page_options_array
Chris@1296 76 end
Chris@1296 77 end
Chris@1296 78
Chris@1296 79 def test_per_page_options_array_should_omit_non_numerial_values
Chris@1296 80 with_settings :per_page_options => 'a, 25, 50' do
Chris@1296 81 assert_equal [25, 50], Setting.per_page_options_array
Chris@1296 82 end
Chris@1296 83 end
Chris@1296 84
Chris@1296 85 def test_per_page_options_array_should_be_sorted
Chris@1296 86 with_settings :per_page_options => '25, 10, 50' do
Chris@1296 87 assert_equal [10, 25, 50], Setting.per_page_options_array
Chris@1296 88 end
Chris@1296 89 end
Chris@1296 90 end