Skip to content

Add failing test cases for ActiveRecord#normalizes #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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