Skip to content

Instantly share code, notes, and snippets.

@tagliala
Created August 28, 2014 08:18
Show Gist options
  • Save tagliala/6cfe162c3294924e77da to your computer and use it in GitHub Desktop.
Save tagliala/6cfe162c3294924e77da to your computer and use it in GitHub Desktop.
Friendly Id bug with globalize
# Activate the gem you are reporting the issue against.
gem 'activerecord', '3.2.19'
gem 'friendly_id', '4.0.10.1'
gem 'globalize', '3.0.4'
gem 'i18n'
require 'active_record'
require 'friendly_id'
require 'globalize'
require 'minitest/autorun'
require 'logger'
require 'i18n'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table "page_translations", :force => true do |t|
t.integer "page_id"
t.string "locale"
t.string "title"
t.string "slug"
end
add_index "page_translations", ["locale"], :name => "index_page_translations_on_locale"
add_index "page_translations", ["page_id"], :name => "index_page_translations_on_page_id"
add_index "page_translations", ["slug", "locale"], :name => "index_page_translations_on_slug_and_locale", :unique => true
create_table :pages do |t|
t.string "title"
t.string "slug"
end
end
class Page < ActiveRecord::Base
extend FriendlyId
translates :title, :slug
friendly_id :title, use: [:globalize]
validates :slug, uniqueness: true
end
class BugTest < Minitest::Test
def test_translated
page_1 = Page.create! title: 'Star Wars'
page_2 = Page.create! title: 'Star Wars'
assert_equal true, page_2.valid?
I18n.with_locale(:it) do
page_1.update_attributes title: 'Guerre Stellari'
page_2.update_attributes title: 'Guerre Stellari'
assert_equal true, page_2.valid?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment