Skip to content

Commit 2a45fbf

Browse files
committed
Replace all classNameWithoutNamespace() calls with entityName()
Done via ``` find . \( -path './DerivedData' -o -path './.git' -o -path './vendor' \) \ -prune -o -type f -name "*.swift" \ -exec sed -i '' -E 's/forEntityName: ([A-Za-z_][A-Za-z0-9_]*)\.classNameWithoutNamespaces\(\)/forEntityName: \1.entityName()/g' {} + ``` The goal is to have a single way to get the entity name so we can adapt it to the new WordPressData setup in one go.
1 parent 84973ec commit 2a45fbf

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

Tests/KeystoneTests/Tests/Features/Aztec/MediaProgressCoordinatorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MediaProgressCoordinatorTests: CoreDataTestCase {
99
var mediaProgressCoordinator: MediaProgressCoordinator!
1010

1111
fileprivate func makeTestMedia() -> Media {
12-
return NSEntityDescription.insertNewObject(forEntityName: Media.classNameWithoutNamespaces(), into: mainContext) as! Media
12+
return NSEntityDescription.insertNewObject(forEntityName: Media.entityName(), into: mainContext) as! Media
1313
}
1414

1515
override func setUp() {

Tests/KeystoneTests/Tests/Models/MediaTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import XCTest
55
class MediaTests: CoreDataTestCase {
66

77
fileprivate func newTestMedia() -> Media {
8-
return NSEntityDescription.insertNewObject(forEntityName: Media.classNameWithoutNamespaces(), into: mainContext) as! Media
8+
return NSEntityDescription.insertNewObject(forEntityName: Media.entityName(), into: mainContext) as! Media
99
}
1010

1111
func testThatAbsoluteURLsWork() {

Tests/KeystoneTests/Tests/Services/FollowCommentsServiceTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class FollowCommentsServiceTests: CoreDataTestCase {
153153
// MARK: - Helpers
154154

155155
func seedReaderListTopic() -> ReaderListTopic {
156-
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderListTopic
156+
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.entityName(), into: mainContext) as! ReaderListTopic
157157
topic.path = "/list/topic1"
158158
topic.title = "topic1"
159159
topic.type = ReaderListTopic.TopicType
@@ -168,7 +168,7 @@ class FollowCommentsServiceTests: CoreDataTestCase {
168168
}
169169

170170
func seedReaderTeamTopic() -> ReaderTeamTopic {
171-
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderTeamTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderTeamTopic
171+
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderTeamTopic.entityName(), into: mainContext) as! ReaderTeamTopic
172172
topic.path = "/a8c/topic2"
173173
topic.title = "topic2"
174174
topic.type = ReaderTeamTopic.TopicType
@@ -183,7 +183,7 @@ class FollowCommentsServiceTests: CoreDataTestCase {
183183
}
184184

185185
func seedReaderPostForTopic(_ topic: ReaderAbstractTopic) -> ReaderPost {
186-
let post = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.classNameWithoutNamespaces(), into: mainContext) as! ReaderPost
186+
let post = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.entityName(), into: mainContext) as! ReaderPost
187187
post.siteID = siteID
188188
post.postID = postID
189189
post.topic = topic
@@ -198,7 +198,7 @@ class FollowCommentsServiceTests: CoreDataTestCase {
198198
}
199199

200200
func seedBlog(isWPForTeams: Bool) {
201-
let blog = NSEntityDescription.insertNewObject(forEntityName: Blog.classNameWithoutNamespaces(), into: mainContext) as! Blog
201+
let blog = NSEntityDescription.insertNewObject(forEntityName: Blog.entityName(), into: mainContext) as! Blog
202202
blog.dotComID = siteID
203203
blog.xmlrpc = "http://test.blog/xmlrpc.php"
204204
blog.url = "http://test.blog/"

Tests/KeystoneTests/Tests/Services/ReaderTopicServiceTest.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ final class ReaderTopicSwiftTest: CoreDataTestCase {
2121
// MARK: - Config / Helpers
2222

2323
func seedTopics() {
24-
let topic1 = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderListTopic
24+
let topic1 = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.entityName(), into: mainContext) as! ReaderListTopic
2525
topic1.path = "/list/topic1"
2626
topic1.title = "topic1"
2727
topic1.type = ReaderListTopic.TopicType
2828

29-
let topic2 = NSEntityDescription.insertNewObject(forEntityName: ReaderTagTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderTagTopic
29+
let topic2 = NSEntityDescription.insertNewObject(forEntityName: ReaderTagTopic.entityName(), into: mainContext) as! ReaderTagTopic
3030
topic2.path = "/tags/topic2"
3131
topic2.title = "topic2"
3232
topic2.type = ReaderTagTopic.TopicType
3333

34-
let topic3 = NSEntityDescription.insertNewObject(forEntityName: ReaderTagTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderTagTopic
34+
let topic3 = NSEntityDescription.insertNewObject(forEntityName: ReaderTagTopic.entityName(), into: mainContext) as! ReaderTagTopic
3535
topic3.path = "/list/topic3"
3636
topic3.title = "topic3"
3737
topic3.type = ReaderTagTopic.TopicType
@@ -49,19 +49,19 @@ final class ReaderTopicSwiftTest: CoreDataTestCase {
4949
}
5050

5151
func seedPostsForTopic(_ topic: ReaderAbstractTopic) {
52-
let post1 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.classNameWithoutNamespaces(), into: mainContext) as! ReaderPost
52+
let post1 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.entityName(), into: mainContext) as! ReaderPost
5353
post1.postID = NSNumber(value: 1)
5454
post1.postTitle = "post1"
5555
post1.content = "post1"
5656
post1.topic = topic
5757

58-
let post2 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.classNameWithoutNamespaces(), into: mainContext) as! ReaderPost
58+
let post2 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.entityName(), into: mainContext) as! ReaderPost
5959
post2.postID = NSNumber(value: 2)
6060
post2.postTitle = "post2"
6161
post2.content = "post2"
6262
post2.topic = topic
6363

64-
let post3 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.classNameWithoutNamespaces(), into: mainContext) as! ReaderPost
64+
let post3 = NSEntityDescription.insertNewObject(forEntityName: ReaderPost.entityName(), into: mainContext) as! ReaderPost
6565
post3.postID = NSNumber(value: 3)
6666
post3.postTitle = "post3"
6767
post3.content = "post3"
@@ -356,7 +356,7 @@ final class ReaderTopicSwiftTest: CoreDataTestCase {
356356
*/
357357
func testPostsDeletedWhenTopicDeleted() {
358358
// setup
359-
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.classNameWithoutNamespaces(), into: mainContext) as! ReaderListTopic
359+
let topic = NSEntityDescription.insertNewObject(forEntityName: ReaderListTopic.entityName(), into: mainContext) as! ReaderListTopic
360360
topic.path = "/list/topic"
361361
topic.title = "topic"
362362
topic.type = ReaderListTopic.TopicType

WordPress/Classes/Models/PublicizeConnection+Creation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension PublicizeConnection {
1111
///
1212
static func createOrReplace(from remoteConnection: RemotePublicizeConnection, in context: NSManagedObjectContext) -> PublicizeConnection {
1313
let pubConnection = findPublicizeConnection(byID: remoteConnection.connectionID, in: context)
14-
?? NSEntityDescription.insertNewObject(forEntityName: PublicizeConnection.classNameWithoutNamespaces(),
14+
?? NSEntityDescription.insertNewObject(forEntityName: PublicizeConnection.entityName(),
1515
into: context) as! PublicizeConnection
1616

1717
pubConnection.connectionID = remoteConnection.connectionID

WordPress/Classes/Services/ReaderTopicService+Subscriptions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ extension ReaderTopicService {
3030
}
3131

3232
if siteTopic.postSubscription == nil {
33-
siteTopic.postSubscription = NSEntityDescription.insertNewObject(forEntityName: ReaderSiteInfoSubscriptionPost.classNameWithoutNamespaces(),
33+
siteTopic.postSubscription = NSEntityDescription.insertNewObject(forEntityName: ReaderSiteInfoSubscriptionPost.entityName(),
3434
into: context) as? ReaderSiteInfoSubscriptionPost
3535
}
3636

3737
if siteTopic.emailSubscription == nil {
38-
siteTopic.emailSubscription = NSEntityDescription.insertNewObject(forEntityName: ReaderSiteInfoSubscriptionEmail.classNameWithoutNamespaces(),
38+
siteTopic.emailSubscription = NSEntityDescription.insertNewObject(forEntityName: ReaderSiteInfoSubscriptionEmail.entityName(),
3939
into: context) as? ReaderSiteInfoSubscriptionEmail
4040
}
4141

WordPress/Classes/Services/SharingService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ import WordPressKit
323323
private func createOrReplaceFromRemotePublicizeService(_ remoteService: RemotePublicizeService, in context: NSManagedObjectContext) -> PublicizeService {
324324
var pubService = try? PublicizeService.lookupPublicizeServiceNamed(remoteService.serviceID, in: context)
325325
if pubService == nil {
326-
pubService = NSEntityDescription.insertNewObject(forEntityName: PublicizeService.classNameWithoutNamespaces(),
326+
pubService = NSEntityDescription.insertNewObject(forEntityName: PublicizeService.entityName(),
327327
into: context) as? PublicizeService
328328
}
329329
pubService?.connectURL = remoteService.connectURL
@@ -451,7 +451,7 @@ import WordPressKit
451451
private func createOrReplaceFromRemoteSharingButton(_ remoteButton: RemoteSharingButton, blog: Blog, in context: NSManagedObjectContext) -> SharingButton {
452452
var shareButton = try? SharingButton.lookupSharingButton(byID: remoteButton.buttonID, for: blog, in: context)
453453
if shareButton == nil {
454-
shareButton = NSEntityDescription.insertNewObject(forEntityName: SharingButton.classNameWithoutNamespaces(),
454+
shareButton = NSEntityDescription.insertNewObject(forEntityName: SharingButton.entityName(),
455455
into: context) as? SharingButton
456456
}
457457

0 commit comments

Comments
 (0)