Project

General

Profile

Feature #38231 » limit-year-to-4-digits-v2.patch

Go MAEDA, 2023-03-29 06:26

View differences:

config/initializers/10-patches.rb
82 82
      end
83 83
    end
84 84

  
85
    module FormHelper
86
      alias :date_field_without_max :date_field
87
      def date_field(object_name, method, options = {})
88
        date_field_without_max(object_name, method, options.reverse_merge(max: '9999-12-31'))
89
      end
90
    end
91

  
85 92
    module FormTagHelper
86 93
      alias :select_tag_without_non_empty_blank_option :select_tag
87 94
      def select_tag(name, option_tags = nil, options = {})
......
90 97
        end
91 98
        select_tag_without_non_empty_blank_option(name, option_tags, options)
92 99
      end
100

  
101
      alias :date_field_tag_without_max :date_field_tag
102
      def date_field_tag(name, value = nil, options = {})
103
        date_field_tag_without_max(name, value, options.reverse_merge(max: '9999-12-31'))
104
      end
93 105
    end
94 106

  
95 107
    module FormOptionsHelper
test/unit/initializers/patches_test.rb
21 21

  
22 22
class PatchesTest < ActiveSupport::TestCase
23 23
  include Redmine::I18n
24
  include ActionView::Helpers::FormHelper
24 25

  
25 26
  def setup
26 27
    Setting.default_language = 'en'
......
37 38
  test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
38 39
    assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
39 40
  end
41

  
42
  test 'ActionView::Helpers::FormHelper.date_field should add max=9999-12-31 to limit year value to 4 digits' do
43
    assert_include 'max="9999-12-31"', date_field('issue', 'start_date')
44
  end
45

  
46
  test 'ActionView::Helpers::FormTagHelper.date_field_tag should add max=9999-12-31 to limit year value to 4 digits' do
47
    assert_include 'max="9999-12-31"', date_field_tag('start_date')
48
  end
40 49
end
(2-2/2)