mobility: uniqueness validator fails in Rails 5.2 rc2

Entity

class Taxon < ApplicationRecord
  validates :name, presence: true, uniqueness: true
  
  extend Mobility
  translates :name, type: :string

  extend FriendlyId
  friendly_id :name, use: [:history,:mobility]
end

Test

t = Taxon.i18n.find_by(name: "Clothing")
t.name  "Clothing"
t.slug "clothing"

t1 = Taxon.create(name: "Clothing")
t1.name  Clothing""
t1.slug "clothing-6525635e-bdb8-492e-aaad-125ad75da630""

Isn’t mobility compatible with Rails 5.2 rc2? @shioyama

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

Try moving the validates :name, presence: true, uniqueness: true to after you call translates:

class Taxon < ApplicationRecord
  extend Mobility
  translates :name, type: :string

  extend FriendlyId
  friendly_id :name, use: [:history,:mobility]

  validates :name, presence: true, uniqueness: true
end

shioyama/friendly_id-mobility#5 is passing, so I don’t see any other possible issue.