File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1
1
en :
2
+ errors :
3
+ messages :
4
+ taken : " has already been taken"
5
+
2
6
mongoid :
3
7
errors :
4
8
messages :
549
553
server versions 3.6 and higher."
550
554
resolution : " Verify that all servers in your deployment are at least
551
555
version 3.6 or don't attempt to use sessions with older server versions."
552
- taken :
553
- " has already been taken"
554
556
too_many_nested_attribute_records :
555
557
message : " Accepting nested attributes for %{association} is limited
556
558
to %{limit} records."
Original file line number Diff line number Diff line change @@ -2472,4 +2472,33 @@ class SpanishActor < EuropeanActor
2472
2472
} . to raise_error ( Mongo ::Error ::OperationFailure )
2473
2473
end
2474
2474
end
2475
+
2476
+ describe "i18n" do
2477
+
2478
+ context 'when using a different locale' do
2479
+
2480
+ around do |example |
2481
+ I18n . with_locale ( :fr ) { example . run }
2482
+ end
2483
+
2484
+ before do
2485
+ # Translation key location is as per rails-i18n gem.
2486
+ # See: https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml
2487
+ I18n . backend . store_translations ( :fr , { errors : { messages : { taken : 'est déjà utilisé(e)' } } } )
2488
+ end
2489
+
2490
+ after do
2491
+ # i18n 1.0 requires +send+ because +translations+ aren't public.
2492
+ # Newer i18n versions have it as public.
2493
+ I18n . backend . send ( :translations ) . delete ( :fr )
2494
+ end
2495
+
2496
+ it "correctly translates the error message" do
2497
+ Circus . create! ( slogan : 'The Greatest Show on Mars' )
2498
+ dict = Circus . new ( slogan : 'The Greatest Show on Mars' )
2499
+ dict . valid?
2500
+ expect ( dict . errors . messages [ :slogan ] ) . to eq ( [ "est déjà utilisé(e)" ] )
2501
+ end
2502
+ end
2503
+ end
2475
2504
end
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ class Circus
4
4
include Mongoid ::Document
5
5
6
6
field :name
7
+ field :slogan
8
+
9
+ validates_uniqueness_of :slogan , allow_blank : true
7
10
8
11
embeds_many :animals
9
12
end
You can’t perform that action at this time.
0 commit comments