@@ -66,6 +66,16 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
6666 XCTAssertEqual ( rows [ 0 ] . scopes [ " team " ] !, [ " id " : 1 , " name " : " Reds " ] )
6767 }
6868
69+ func testDefaultScopeIncludingRequiredRestrictedSelection( ) throws {
70+ let dbQueue = try makeDatabaseQueue ( )
71+ let request = Player . select ( . allColumns( excluding: [ " name " ] ) ) . including ( required: Player . defaultTeam)
72+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
73+ XCTAssertEqual ( rows. count, 1 )
74+ XCTAssertEqual ( rows [ 0 ] . unscoped, [ " id " : 1 , " teamId " : 1 ] )
75+ XCTAssertEqual ( Set ( rows [ 0 ] . scopes. names) , [ " team " ] )
76+ XCTAssertEqual ( rows [ 0 ] . scopes [ " team " ] !, [ " id " : 1 , " name " : " Reds " ] )
77+ }
78+
6979 func testDefaultScopeAnnotatedWithRequired( ) throws {
7080 let dbQueue = try makeDatabaseQueue ( )
7181 let request = Player . annotated ( withRequired: Player . defaultTeam)
@@ -82,6 +92,14 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
8292 XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " teamName " : " Reds " ] )
8393 }
8494
95+ func testDefaultScopeAnnotatedWithRequiredRestrictedSelection( ) throws {
96+ let dbQueue = try makeDatabaseQueue ( )
97+ let request = Player . annotated ( withRequired: Player . defaultTeam. select ( . allColumns( excluding: [ " name " ] ) ) )
98+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
99+ XCTAssertEqual ( rows. count, 1 )
100+ XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " id " : 1 ] )
101+ }
102+
85103 func testDefaultScopeIncludingOptional( ) throws {
86104 let dbQueue = try makeDatabaseQueue ( )
87105 let request = Player . including ( optional: Player . defaultTeam)
@@ -113,6 +131,15 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
113131 XCTAssertEqual ( rows [ 1 ] , [ " id " : 2 , " teamId " : nil , " name " : " Barbara " , " teamName " : nil ] )
114132 }
115133
134+ func testDefaultScopeAnnotatedWithOptionalRestrictedSelection( ) throws {
135+ let dbQueue = try makeDatabaseQueue ( )
136+ let request = Player . annotated ( withOptional: Player . defaultTeam. select ( . allColumns( excluding: [ " name " ] ) ) )
137+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
138+ XCTAssertEqual ( rows. count, 2 )
139+ XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " id " : 1 ] )
140+ XCTAssertEqual ( rows [ 1 ] , [ " id " : 2 , " teamId " : nil , " name " : " Barbara " , " id " : nil ] )
141+ }
142+
116143 func testDefaultScopeJoiningRequired( ) throws {
117144 let dbQueue = try makeDatabaseQueue ( )
118145 let request = Player . joining ( required: Player . defaultTeam)
@@ -153,6 +180,16 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
153180 XCTAssertEqual ( rows [ 0 ] . scopes [ " customTeam " ] !, [ " id " : 1 , " name " : " Reds " ] )
154181 }
155182
183+ func testCustomScopeIncludingRequiredRestrictedSelection( ) throws {
184+ let dbQueue = try makeDatabaseQueue ( )
185+ let request = Player . select ( . allColumns( excluding: [ " name " ] ) ) . including ( required: Player . customTeam)
186+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
187+ XCTAssertEqual ( rows. count, 1 )
188+ XCTAssertEqual ( rows [ 0 ] . unscoped, [ " id " : 1 , " teamId " : 1 ] )
189+ XCTAssertEqual ( Set ( rows [ 0 ] . scopes. names) , [ " customTeam " ] )
190+ XCTAssertEqual ( rows [ 0 ] . scopes [ " customTeam " ] !, [ " id " : 1 , " name " : " Reds " ] )
191+ }
192+
156193 func testCustomScopeAnnotatedWithRequired( ) throws {
157194 let dbQueue = try makeDatabaseQueue ( )
158195 let request = Player . annotated ( withRequired: Player . customTeam)
@@ -169,6 +206,14 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
169206 XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " teamName " : " Reds " ] )
170207 }
171208
209+ func testCustomScopeAnnotatedWithRequiredRestrictedSelection( ) throws {
210+ let dbQueue = try makeDatabaseQueue ( )
211+ let request = Player . annotated ( withRequired: Player . customTeam. select ( . allColumns( excluding: [ " name " ] ) ) )
212+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
213+ XCTAssertEqual ( rows. count, 1 )
214+ XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " id " : 1 ] )
215+ }
216+
172217 func testCustomScopeIncludingOptional( ) throws {
173218 let dbQueue = try makeDatabaseQueue ( )
174219 let request = Player . including ( optional: Player . customTeam)
@@ -200,6 +245,15 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
200245 XCTAssertEqual ( rows [ 1 ] , [ " id " : 2 , " teamId " : nil , " name " : " Barbara " , " teamName " : nil ] )
201246 }
202247
248+ func testCustomScopeAnnotatedWithOptionalRestrictedSelection( ) throws {
249+ let dbQueue = try makeDatabaseQueue ( )
250+ let request = Player . annotated ( withOptional: Player . customTeam. select ( . allColumns( excluding: [ " name " ] ) ) )
251+ let rows = try dbQueue. inDatabase { try Row . fetchAll ( $0, request) }
252+ XCTAssertEqual ( rows. count, 2 )
253+ XCTAssertEqual ( rows [ 0 ] , [ " id " : 1 , " teamId " : 1 , " name " : " Arthur " , " id " : 1 ] )
254+ XCTAssertEqual ( rows [ 1 ] , [ " id " : 2 , " teamId " : nil , " name " : " Barbara " , " id " : nil ] )
255+ }
256+
203257 func testCustomPluralScopeIncludingRequired( ) throws {
204258 // Make sure explicit plural keys are preserved
205259 let dbQueue = try makeDatabaseQueue ( )
0 commit comments