@@ -0,0 +1,40 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
14 | # You should have received a copy of the GNU General Public License | |||
|
15 | # along with this program; if not, write to the Free Software | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |||
|
19 | ||||
|
20 | class PatchesTest < ActiveSupport::TestCase | |||
|
21 | include Redmine::I18n | |||
|
22 | ||||
|
23 | context "ActiveRecord::Base.human_attribute_name" do | |||
|
24 | setup do | |||
|
25 | Setting.default_language = 'en' | |||
|
26 | end | |||
|
27 | ||||
|
28 | should "transform name to field_name" do | |||
|
29 | assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on') | |||
|
30 | end | |||
|
31 | ||||
|
32 | should "cut extra _id suffix for better validation" do | |||
|
33 | assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id') | |||
|
34 | end | |||
|
35 | ||||
|
36 | should "default to humanized value if no translation has been found (useful for custom fields)" do | |||
|
37 | assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name') | |||
|
38 | end | |||
|
39 | end | |||
|
40 | end |
@@ -7,7 +7,7 module ActiveRecord | |||||
7 |
|
7 | |||
8 | # Translate attribute names for validation errors display |
|
8 | # Translate attribute names for validation errors display | |
9 | def self.human_attribute_name(attr) |
|
9 | def self.human_attribute_name(attr) | |
10 | l("field_#{attr.to_s.gsub(/_id$/, '')}") |
|
10 | l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr) | |
11 | end |
|
11 | end | |
12 | end |
|
12 | end | |
13 | end |
|
13 | end |
General Comments 0
You need to be logged in to leave comments.
Login now