@@ -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 |
@@ -1,100 +1,100 | |||
|
1 | 1 | |
|
2 | 2 | require 'active_record' |
|
3 | 3 | |
|
4 | 4 | module ActiveRecord |
|
5 | 5 | class Base |
|
6 | 6 | include Redmine::I18n |
|
7 | 7 | |
|
8 | 8 | # Translate attribute names for validation errors display |
|
9 | 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 | 11 | end |
|
12 | 12 | end |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | module ActiveRecord |
|
16 | 16 | class Errors |
|
17 | 17 | def full_messages(options = {}) |
|
18 | 18 | full_messages = [] |
|
19 | 19 | |
|
20 | 20 | @errors.each_key do |attr| |
|
21 | 21 | @errors[attr].each do |message| |
|
22 | 22 | next unless message |
|
23 | 23 | |
|
24 | 24 | if attr == "base" |
|
25 | 25 | full_messages << message |
|
26 | 26 | elsif attr == "custom_values" |
|
27 | 27 | # Replace the generic "custom values is invalid" |
|
28 | 28 | # with the errors on custom values |
|
29 | 29 | @base.custom_values.each do |value| |
|
30 | 30 | value.errors.each do |attr, msg| |
|
31 | 31 | full_messages << value.custom_field.name + ' ' + msg |
|
32 | 32 | end |
|
33 | 33 | end |
|
34 | 34 | else |
|
35 | 35 | attr_name = @base.class.human_attribute_name(attr) |
|
36 | 36 | full_messages << attr_name + ' ' + message.to_s |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | full_messages |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | module ActionView |
|
46 | 46 | module Helpers |
|
47 | 47 | module DateHelper |
|
48 | 48 | # distance_of_time_in_words breaks when difference is greater than 30 years |
|
49 | 49 | def distance_of_date_in_words(from_date, to_date = 0, options = {}) |
|
50 | 50 | from_date = from_date.to_date if from_date.respond_to?(:to_date) |
|
51 | 51 | to_date = to_date.to_date if to_date.respond_to?(:to_date) |
|
52 | 52 | distance_in_days = (to_date - from_date).abs |
|
53 | 53 | |
|
54 | 54 | I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| |
|
55 | 55 | case distance_in_days |
|
56 | 56 | when 0..60 then locale.t :x_days, :count => distance_in_days.round |
|
57 | 57 | when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round |
|
58 | 58 | else locale.t :over_x_years, :count => (distance_in_days / 365).floor |
|
59 | 59 | end |
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" } |
|
67 | 67 | |
|
68 | 68 | # Adds :async_smtp and :async_sendmail delivery methods |
|
69 | 69 | # to perform email deliveries asynchronously |
|
70 | 70 | module AsynchronousMailer |
|
71 | 71 | %w(smtp sendmail).each do |type| |
|
72 | 72 | define_method("perform_delivery_async_#{type}") do |mail| |
|
73 | 73 | Thread.start do |
|
74 | 74 | send "perform_delivery_#{type}", mail |
|
75 | 75 | end |
|
76 | 76 | end |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | ActionMailer::Base.send :include, AsynchronousMailer |
|
81 | 81 | |
|
82 | 82 | # TMail::Unquoter.convert_to_with_fallback_on_iso_8859_1 introduced in TMail 1.2.7 |
|
83 | 83 | # triggers a test failure in test_add_issue_with_japanese_keywords(MailHandlerTest) |
|
84 | 84 | module TMail |
|
85 | 85 | class Unquoter |
|
86 | 86 | class << self |
|
87 | 87 | alias_method :convert_to, :convert_to_without_fallback_on_iso_8859_1 |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | module ActionController |
|
93 | 93 | module MimeResponds |
|
94 | 94 | class Responder |
|
95 | 95 | def api(&block) |
|
96 | 96 | any(:xml, :json, &block) |
|
97 | 97 | end |
|
98 | 98 | end |
|
99 | 99 | end |
|
100 | 100 | end |
General Comments 0
You need to be logged in to leave comments.
Login now