Get the claimed code as result instead of just checking that there was one

Stephen Paul Weber created

Change summary

lib/invites_repo.rb       | 7 ++++---
test/test_registration.rb | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)

Detailed changes

lib/invites_repo.rb 🔗

@@ -53,6 +53,7 @@ class InvitesRepo
 	CLAIM_SQL = <<~SQL
 		UPDATE invites SET used_by_id=$1, used_at=LOCALTIMESTAMP
 		WHERE code=$2 AND used_by_id IS NULL
+		RETURNING creator_id
 	SQL
 
 	def claim_code(customer_id, code, &blk)
@@ -60,10 +61,10 @@ class InvitesRepo
 
 		guard_too_many_tries(customer_id).then do
 			@db.transaction do
-				valid = @db.exec(CLAIM_SQL, [customer_id, code]).cmd_tuples.positive?
-				invalid_code(customer_id, code).sync unless valid
+				claimed = @db.exec(CLAIM_SQL, [customer_id, code]).first
+				invalid_code(customer_id, code).sync unless claimed
 
-				blk.call
+				blk.call(claimed)
 			end
 		end
 	end

test/test_registration.rb 🔗

@@ -281,7 +281,7 @@ class RegistrationTest < Minitest::Test
 			Registration::Activation::DB.expect(:transaction, []) { |&blk| blk.call }
 			Registration::Activation::DB.expect(
 				:exec,
-				OpenStruct.new(cmd_tuples: 1),
+				[{ creator_id: "creator" }],
 				[String, ["test", "123"]]
 			)
 			Registration::Activation::Finish.expect(