Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #992: Update empty bookmark title from desktop sync. (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub authored and Joel Reis committed Mar 22, 2019
1 parent 60d264f commit e628bb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Data/models/Bookmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public final class Bookmark: NSManagedObject, WebsitePresentable, Syncable, CRUD
// MARK: Update

public func update(customTitle: String?, url: String?) {
// Title can't be empty, except when coming from Sync
let isTitleEmpty = customTitle?.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == true
if customTitle == nil || isTitleEmpty { return }
updateInternal(customTitle: customTitle, url: url)
}

Expand Down Expand Up @@ -313,10 +316,8 @@ extension Bookmark {
return
}

if let ct = customTitle, !ct.isEmpty {
bookmarkToUpdate.customTitle = ct
bookmarkToUpdate.title = ct
}
bookmarkToUpdate.customTitle = customTitle
bookmarkToUpdate.title = customTitle

if let u = url, !u.isEmpty {
bookmarkToUpdate.url = url
Expand Down
3 changes: 2 additions & 1 deletion DataTests/FavoriteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ class FavoriteTests: CoreDataTestCase {
func testEditFavoriteURL() {
let url = "http://brave.com"
let newUrl = "http://updated.example.com"
let newTitle = "newtitle"

let object = createAndWait(url: URL(string: url), title: "title")

XCTAssertEqual(object.displayTitle, "title")
XCTAssertEqual(object.url, url)

backgroundSaveAndWaitForExpectation {
object.update(customTitle: nil, url: newUrl)
object.update(customTitle: newTitle, url: newUrl)
}
// Make sure only one record was added to DB
XCTAssertEqual(try! DataController.viewContext.count(for: fetchRequest), 1)
Expand Down

0 comments on commit e628bb6

Please sign in to comment.