Skip to content
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

Stop deleting pusher_id on versions when the parent user is deleted #3766

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class User < ApplicationRecord
has_many :subscriptions, dependent: :destroy
has_many :subscribed_gems, -> { order("name ASC") }, through: :subscriptions, source: :rubygem

has_many :pushed_versions, -> { by_created_at }, dependent: :nullify, inverse_of: :pusher, class_name: "Version", foreign_key: :pusher_id
has_many :pushed_versions, -> { by_created_at }, inverse_of: :pusher, class_name: "Version", foreign_key: :pusher_id

has_many :deletions, dependent: :nullify
has_many :web_hooks, dependent: :destroy
Expand Down
15 changes: 15 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -843,4 +843,19 @@ class UserTest < ActiveSupport::TestCase
assert_equal "", User.normalize_email("\u9999".force_encoding("ascii"))
end
end

context ".pushed_versions" do
setup do
@user = create(:user)
@version = create(:version, pusher: @user)
end
should "return version objects for each version the user has pushed" do
assert_includes @user.pushed_versions, @version
end

should "not delete pusher_id from Version when deleted" do
@user.destroy!
assert_equal @user.id, @version.reload.pusher_id
end
end
end