FIX: Uninvite correct user

FIX: Uninvite correct user

diff --git a/lib/topic_extensions.rb b/lib/topic_extensions.rb
index 57c58ab..dc7c231 100644
--- a/lib/topic_extensions.rb
+++ b/lib/topic_extensions.rb
@@ -11,7 +11,7 @@ module TopicExtensions
 
   def remove_allowed_user(removed_by, user)
     ret = super
-    EncryptedTopicsUser.delete_by(topic_id: id, user_id: user_id) if ret
+    EncryptedTopicsUser.delete_by(topic_id: id, user_id: user.id) if ret
     ret
   end
 end
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 0fc088d..c30350a 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -46,4 +46,16 @@ describe TopicsController do
       expect(TopicAllowedGroup.where(group_id: group.id, topic_id: topic.id).exists?).to eq(false)
     end
   end
+
+  context '#remove_allowed_user' do
+    let(:topic) { Fabricate(:encrypt_topic, user: user) }
+    let(:other_user) { topic.topic_allowed_users.map(&:user).find { |u| u != user } }
+
+    it 'uninvites the user' do
+      put "/t/#{topic.id}/remove-allowed-user.json", params: { username: other_user.username }
+
+      expect(EncryptedTopicsUser.where(topic_id: topic.id, user_id: user.id)      .exists?).to eq(true)
+      expect(EncryptedTopicsUser.where(topic_id: topic.id, user_id: other_user.id).exists?).to eq(false)
+    end
+  end
 end

GitHub sha: 54a513bc

1 Like