Skip to content

Remove deprecated positional argument on create_snapshot! #52

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

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CHANGELOG

- **Unreleased**
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.4.0...master)
* Nothing yet
* [#xx]((https://github.com/westonganger/active_snapshot/pull/xx) Remove :identifier argument as a positional argument

- **v0.4.0** - July 23, 2024
* [View Diff](https://github.com/westonganger/active_snapshot/compare/v0.3.2...v0.4.0)
Expand Down
14 changes: 1 addition & 13 deletions lib/active_snapshot/models/concerns/snapshots_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ module SnapshotsConcern
has_many :snapshot_items, as: :item, class_name: 'ActiveSnapshot::SnapshotItem'
end

def create_snapshot!(legacy_identifier=nil, identifier: nil, user: nil, metadata: nil)
if identifier.nil? && legacy_identifier
identifier = legacy_identifier

if ActiveSupport.version >= Gem::Version.new("7.1")
ActiveSupport::Deprecation.new.warn(LEGACY_POSITIONAL_ARGUMENT_WARNING)
else
ActiveSupport::Deprecation.warn(LEGACY_POSITIONAL_ARGUMENT_WARNING)
end
end

def create_snapshot!(identifier: nil, user: nil, metadata: nil)
snapshot = snapshots.create!({
identifier: identifier,
user_id: (user.id if user),
Expand Down Expand Up @@ -131,7 +121,5 @@ def children_to_snapshot
end
end

LEGACY_POSITIONAL_ARGUMENT_WARNING = "Supplying the snapshots :identifier as a positional argument is now deprecated and will be removed in upcoming versions. Please supply the snapshot identifier using the :identifier keyword argument instead.".freeze

end
end
18 changes: 1 addition & 17 deletions test/models/snapshots_concern_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_create_snapshot!

def test_has_snapshot_children
klass = VolatilePost

assert_nil klass.has_snapshot_children

klass.has_snapshot_children do
Expand Down Expand Up @@ -115,22 +115,6 @@ def test_has_snapshot_children
assert klass.new.children_to_snapshot.count == 2
end

def test_legacy_positional_identifier_argument
call_count = 0

allow_any_instance_of(ActiveSupport::Deprecation).to receive(:warn).and_wrap_original do |m, *args|
if args.first == ActiveSnapshot::SnapshotsConcern::LEGACY_POSITIONAL_ARGUMENT_WARNING
call_count += 1
end
end

assert_difference ->{ ActiveSnapshot::Snapshot.count }, 1 do
@snapshot = Post.first.create_snapshot!("snapshot-1")
end

assert_equal call_count, 1
end

def test_optional_identifier
post = Post.first

Expand Down
Loading