Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/activerecord_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
t.string :foo
t.boolean :newsletter_subscribed, default: true
t.json :store_accessor_store_with_no_defaults
t.string :locale
end

create_table :documents do |t|
Expand Down Expand Up @@ -114,6 +115,9 @@ class User < ActiveRecord::Base
enumerize :language, :in => [:en, :jp]
enumerize :country_code, :in => [:us, :ca]

normalizes :locale, with: ->(value) { value.downcase.strip.presence }
enumerize :locale, :in => [:de, :en, :pl]

serialize :interests, type: Array
enumerize :interests, :in => [:music, :sports, :dancing, :programming], :multiple => true

Expand Down Expand Up @@ -754,4 +758,15 @@ class AdminUser < User
expect(User.exists?(status: :active)).must_equal true
expect(User.exists?(interests: [:music, :sports])).must_equal true
end

it 'supports AR#normalizes class methods' do
User.delete_all
User.create!(locale: 'de')
expect(User.exists?(locale: ' DE ')).must_equal true
end

it 'supports AR#normalizes instance methods' do
user = User.new(locale: ' DE ')
expect(user.locale).must_equal 'de'
end
end