Skip to content

Commit

Permalink
[26829] Patch reform-rails to use activerecord i18n_scope
Browse files Browse the repository at this point in the history
The validator passed to AM::Error does not use the `i18n_scope` we
define on either Reform::Form or the model, but is delegated from the
included AM::Translations module.

This in turn causes I18n to lookup the scope `:activemodel`, failing the
localization.

trailblazer/reform-rails#56
trailblazer/reform-rails#35
  • Loading branch information
oliverguenther committed Jan 8, 2018
1 parent d4209d4 commit 8d0d2fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/initializers/reform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
include Reform::Form::ActiveModel::Validations
end

Reform::Form::ActiveModel::Validations::Validator.class_eval do
##
# use activerecord as the base scope instead of 'activemodel' to be compatible
# to the messages we have already stored
def self.i18n_scope
:activerecord
end
end


require 'reform/contract'

require 'open_project/patches/reform'
Expand Down
12 changes: 12 additions & 0 deletions spec/contracts/work_packages/base_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@
describe 'due date' do
it_behaves_like 'a parent unwritable property', :due_date
it_behaves_like 'a date attribute', :due_date

it 'returns an error when trying to set it before the start date' do
work_package.start_date = Date.today + 2.days
work_package.due_date = Date.today

contract.validate

message = I18n.t('activerecord.errors.messages.greater_than_or_equal_to_start_date')

expect(contract.errors[:due_date])
.to include message
end
end

describe 'percentage done' do
Expand Down

0 comments on commit 8d0d2fd

Please sign in to comment.