Skip to content

Commit

Permalink
Merge pull request #137 from cobudget/fix_user_merger
Browse files Browse the repository at this point in the history
stop admin from merging a user into itself then destroying it
  • Loading branch information
data-doge committed Apr 12, 2016
2 parents fa62a78 + 262c446 commit 3128cf0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/services/user_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def self.fetch_recent_activity_for(user:)
end

def self.merge_users(user_to_kill:, user_to_keep:)
if user_to_kill == user_to_keep
puts "nope" unless Rails.env.test?
return
end

user_to_kill.memberships.each do |membership|
memberships = Membership.where(group: membership.group, member: [user_to_keep, user_to_kill])

Expand Down
2 changes: 1 addition & 1 deletion spec/models/bucket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Timecop.return

bucket.reload
expect(bucket.live_at).to eq(current_time - 1.hour)
expect(bucket.live_at).to be_within(1).of(current_time - 1.hour)
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/services/user_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@
@comment_to_transfer = create(:comment, user: @user_to_kill)
end

context "admin submits same user to both keep and kill" do
it "does not kill the user" do
UserService.merge_users(user_to_keep: @user_to_keep, user_to_kill: @user_to_keep)

@user_to_keep.reload
expect(@user_to_keep.persisted?).to be true
end
end

context "transfering memebership is going to double up membership for a group," do
before do
@existing_membership = create(:membership, member: @user_to_keep, group: @group)
Expand Down

0 comments on commit 3128cf0

Please sign in to comment.