@@ -920,6 +920,60 @@ describe "lapis.db.postgres", ->
920920 " db.encode_clause: passed an empty clause (use allow_empty: true to permit empty clause)"
921921 )
922922
923+ describe " + operator" , ->
924+ it " combines two clauses with OR" , ->
925+ a = db. clause hello : " world"
926+ b = db. clause { " not deleted" }
927+ combined = a + b
928+ assert . same ' ("hello" = \' world\' ) OR ((not deleted))' , db. encode_clause combined
929+
930+ it " chains multiple clauses" , ->
931+ a = db. clause { " a" }
932+ b = db. clause { " b" }
933+ c = db. clause { " c" }
934+ combined = a + b + c
935+ assert . same ' ((a)) OR ((b)) OR ((c))' , db. encode_clause combined
936+
937+ it " works with db.raw and db.NULL in clauses" , ->
938+ a = db. clause { status : db. raw " active" }
939+ b = db. clause { deleted : db. NULL }
940+ combined = a + b
941+ assert . same ' ("status" = active) OR ("deleted" IS NULL)' , db. encode_clause combined
942+
943+ it " works with db.list in clauses" , ->
944+ a = db. clause { id : db. list { 1 , 2 , 3 } }
945+ b = db. clause { " archived" }
946+ combined = a + b
947+ assert . same ' ("id" IN (1, 2, 3)) OR ((archived))' , db. encode_clause combined
948+
949+ it " errors when right operand is a plain table" , ->
950+ a = db. clause hello : " world"
951+ assert . has_error(
952+ -> a + { hello : " world" }
953+ " db.clause.__add: right operand must be a clause object"
954+ )
955+
956+ it " errors when right operand is a string" , ->
957+ a = db. clause hello : " world"
958+ assert . has_error(
959+ -> a + " not a clause"
960+ " db.clause.__add: right operand must be a clause object"
961+ )
962+
963+ it " errors when right operand is a number" , ->
964+ a = db. clause hello : " world"
965+ assert . has_error(
966+ -> a + 123
967+ " db.clause.__add: right operand must be a clause object"
968+ )
969+
970+ it " errors when right operand is nil" , ->
971+ a = db. clause hello : " world"
972+ assert . has_error(
973+ -> a + nil
974+ " db.clause.__add: right operand must be a clause object"
975+ )
976+
923977 describe " encode_assigns" , ->
924978 it " writes output to buffer" , ->
925979 buffer = { " hello" }
0 commit comments