File tree Expand file tree Collapse file tree 5 files changed +34
-7
lines changed Expand file tree Collapse file tree 5 files changed +34
-7
lines changed Original file line number Diff line number Diff line change
1
+ # Unreleased
2
+ - [ feature] The SDK can now infer a default database URL if none is provided in
3
+ the config.
4
+
1
5
# v6.4.0
2
6
- [ changed] Functionally neutral source reorganization. (#5861 )
3
7
Original file line number Diff line number Diff line change @@ -67,7 +67,22 @@ + (FIRDatabase *)databaseForApp:(FIRApp *)app {
67
67
[NSException raise: @" InvalidFIRApp"
68
68
format: @" nil FIRApp instance passed to databaseForApp." ];
69
69
}
70
- return [FIRDatabase databaseForApp: app URL: app.options.databaseURL];
70
+ NSString *url = app.options .databaseURL ;
71
+ if (!url) {
72
+ if (!app.options .projectID ) {
73
+ [NSException
74
+ raise: @" MissingProjectId"
75
+ format: @" Can't determine Firebase Database URL. Be sure to "
76
+ @" include a Project ID when calling "
77
+ @" `FirebaseApp.configure()`." ];
78
+ }
79
+ FFLog (@" I-RDB024002" , @" Using default host for project %@ " ,
80
+ app.options .projectID );
81
+ url = [NSString
82
+ stringWithFormat: @" https://%@ -default-rtdb.firebaseio.com" ,
83
+ app.options.projectID];
84
+ }
85
+ return [FIRDatabase databaseForApp: app URL: url];
71
86
}
72
87
73
88
+ (FIRDatabase *)databaseForApp : (FIRApp *)app URL : (NSString *)url {
Original file line number Diff line number Diff line change 21
21
22
22
@interface FIRFakeApp : NSObject
23
23
24
- - (instancetype )initWithName : (NSString *)name URL : (NSString *)url ;
24
+ - (instancetype )initWithName : (NSString *)name URL : (NSString *_Nullable )url ;
25
25
26
26
@property (nonatomic , readonly ) FIRFakeOptions *options;
27
27
@property (nonatomic , copy , readonly ) NSString *name;
Original file line number Diff line number Diff line change 21
21
#import " SharedTestUtilities/FIRComponentTestUtilities.h"
22
22
23
23
@interface FIRFakeOptions : NSObject
24
- @property (nonatomic , readonly , copy ) NSString *databaseURL;
24
+ @property (nonatomic , readonly , copy ) NSString *_Nullable databaseURL;
25
+ @property (nonatomic , readonly , copy ) NSString *projectID;
25
26
@property (nonatomic , readonly , copy ) NSString *googleAppID;
26
- - (instancetype )initWithURL : (NSString *)url ;
27
+ - (instancetype )initWithURL : (NSString *_Nullable )url ;
27
28
@end
28
29
29
30
@implementation FIRFakeOptions
30
- - (instancetype )initWithURL : (NSString *)url {
31
+ - (instancetype )initWithURL : (NSString *_Nullable )url {
31
32
self = [super init ];
32
33
if (self) {
33
34
_databaseURL = url;
34
35
_googleAppID = @" fake-app-id" ;
36
+ _projectID = @" fake-project-id" ;
35
37
}
36
38
return self;
37
39
}
@@ -64,7 +66,7 @@ - (instancetype)initWithApp:(FIRApp *)app
64
66
65
67
@implementation FIRFakeApp
66
68
67
- - (instancetype )initWithName : (NSString *)name URL : (NSString *)url {
69
+ - (instancetype )initWithName : (NSString *)name URL : (NSString *_Nullable )url {
68
70
self = [super init ];
69
71
if (self) {
70
72
_name = name;
Original file line number Diff line number Diff line change @@ -49,7 +49,6 @@ - (void)testDatabaseForApp {
49
49
}
50
50
51
51
- (void )testDatabaseForAppWithInvalidURLs {
52
- XCTAssertThrows ([self databaseForURL: nil ]);
53
52
XCTAssertThrows ([self databaseForURL: @" not-a-url" ]);
54
53
XCTAssertThrows ([self databaseForURL: @" http://x.example.com/paths/are/bad" ]);
55
54
}
@@ -75,6 +74,13 @@ - (void)testDatabaseForAppWithHttpsURL {
75
74
XCTAssertEqualObjects (@" https://foo.bar.com" , [database reference ].URL );
76
75
}
77
76
77
+ - (void )testDatabaseForAppWithProjectId {
78
+ id app = [[FIRFakeApp alloc ] initWithName: @" testDatabaseForAppWithURL" URL: nil ];
79
+ FIRDatabase *database = [FIRDatabase databaseForApp: app];
80
+ XCTAssertEqualObjects (@" https://fake-project-id-default-rtdb.firebaseio.com" ,
81
+ [database reference ].URL );
82
+ }
83
+
78
84
- (void )testDifferentInstanceForAppWithURL {
79
85
id app = [[FIRFakeApp alloc ] initWithName: @" testDifferentInstanceForAppWithURL"
80
86
URL: kFirebaseTestAltNamespace ];
You can’t perform that action at this time.
0 commit comments