diff --git a/CHANGELOG.md b/CHANGELOG.md index fc8b5aa..6ffd302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ ### Unreleased +* [Breaking] Remove `exists?` override. + +To continue using `exists?`, you can decode the ID first: + +```ruby +User.exists? User.decode_prefix_id(params[:id]) +``` + ### 1.8.1 * Ensure that decode returns all parts of composite key diff --git a/lib/prefixed_ids.rb b/lib/prefixed_ids.rb index 0ef6b45..e7ce9bf 100644 --- a/lib/prefixed_ids.rb +++ b/lib/prefixed_ids.rb @@ -38,11 +38,10 @@ module Rails end class_methods do - def has_prefix_id(prefix, override_find: true, override_param: true, override_exists: true, fallback: true, **options) + def has_prefix_id(prefix, override_find: true, override_param: true, fallback: true, **options) include Attribute include Finder if override_find include ToParam if override_param - include Exists if override_exists self._prefix_id = PrefixId.new(self, prefix, **options) self._prefix_id_fallback = fallback @@ -124,18 +123,4 @@ def to_param _prefix_id.encode(id) end end - - module Exists - extend ActiveSupport::Concern - - class_methods do - def exists?(id) - if _prefix_id.present? && id.is_a?(String) - super(_prefix_id.decode(id)) - else - super - end - end - end - end end diff --git a/test/prefixed_ids_test.rb b/test/prefixed_ids_test.rb index 2ff248b..40a2b92 100644 --- a/test/prefixed_ids_test.rb +++ b/test/prefixed_ids_test.rb @@ -191,23 +191,6 @@ class PrefixedIdsTest < ActiveSupport::TestCase assert_equal account, account.user.accounts.find(account.prefix_id) end - test "exists? works with prefixed ID" do - account = accounts(:one) - assert Account.exists?(account.prefix_id) - end - - test "disabled exists? with prefixed ID" do - post = posts(:one) - - refute Post.exists?(post.prefix_id) - end - - test "exists? works with conditions instead of ID" do - account = accounts(:one) - - assert Account.exists?(id: account.id) - end - test "calling find on an associated model without prefix id succeeds" do nonprefixed_item = nonprefixed_items(:one) user = users(:one)