From 98a269d459b9f9d53d50ffcc92ad10364e010fc9 Mon Sep 17 00:00:00 2001 From: JP Wright Date: Mon, 30 Jul 2018 00:27:06 +0200 Subject: [PATCH 1/3] Update depedencies --- Cartfile.resolved | 4 ++-- Carthage/Checkouts/DVR | 2 +- Carthage/Checkouts/Nimble | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 7329172b..b47840df 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ github "JensRavens/Interstellar" "2.2.0" -github "Quick/Nimble" "v7.1.2" -github "venmo/DVR" "v1.1.0" +github "Quick/Nimble" "v7.1.3" +github "venmo/DVR" "v1.2.0" diff --git a/Carthage/Checkouts/DVR b/Carthage/Checkouts/DVR index 890067e0..d41094d2 160000 --- a/Carthage/Checkouts/DVR +++ b/Carthage/Checkouts/DVR @@ -1 +1 @@ -Subproject commit 890067e0abb361e80514806f2232c3de4592bf28 +Subproject commit d41094d26e4d97e20a79e8260ecff84e4b36ff66 diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 8023e398..9c1379fd 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 8023e3980d91b470ad073d6da843b73f2eeb1844 +Subproject commit 9c1379fdcd58c4f2278aea5e029394ba9a2b8f07 From 0b973a1412df930c138e7978b6e57f1226f62058 Mon Sep 17 00:00:00 2001 From: JP Wright Date: Mon, 30 Jul 2018 00:27:31 +0200 Subject: [PATCH 2/3] Debug Asset accessors not respecting fallback chain logic --- Sources/Contentful/Asset.swift | 17 ++----- .../Data/localizable-asset.json | 45 +++++++++++++++++++ Tests/ContentfulTests/LocalizationTests.swift | 19 ++++++++ 3 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 Tests/ContentfulTests/Data/localizable-asset.json diff --git a/Sources/Contentful/Asset.swift b/Sources/Contentful/Asset.swift index edb3f47c..de653c2c 100644 --- a/Sources/Contentful/Asset.swift +++ b/Sources/Contentful/Asset.swift @@ -52,6 +52,7 @@ public class Asset: LocalizableResource, AssetProtocol { /// The URL for the underlying media file. Returns nil if the url was omitted from the response (i.e. `select` operation in query) /// or if the underlying media file is still processing with Contentful. public var url: URL? { + guard let url = file?.url else { return nil } return url } @@ -65,27 +66,17 @@ public class Asset: LocalizableResource, AssetProtocol { /// The title of the asset. Optional for compatibility with `select` operator queries. public var title: String? { - return localizedString(path: "title") + return fields["title"] as? String } /// Description of the asset. Optional for compatibility with `select` operator queries. public var description: String? { - return localizedString(path: "description") + return fields["description"] as? String } /// Metadata describing the file associated with the asset. Optional for compatibility with `select` operator queries. public var file: FileMetadata? { - let localizableValue = localizableFields["file"] - let value = localizableValue?[currentlySelectedLocale.code] as? FileMetadata - return value - } - - // MARK: Private - - private func localizedString(path: String) -> String? { - let localizableValue = localizableFields[path] - let value = localizableValue?[currentlySelectedLocale.code] as? String - return value + return fields["file"] as? FileMetadata } } diff --git a/Tests/ContentfulTests/Data/localizable-asset.json b/Tests/ContentfulTests/Data/localizable-asset.json new file mode 100644 index 00000000..cad17fbf --- /dev/null +++ b/Tests/ContentfulTests/Data/localizable-asset.json @@ -0,0 +1,45 @@ +{ + "sys": { + "space": { + "sys": { + "type": "Link", + "linkType": "Space", + "id": "cfexampleapi" + } + }, + "id": "1x0xpXu4pSGS4OukSyWGUK", + "type": "Asset", + "createdAt": "2013-11-06T09:45:10.000Z", + "updatedAt": "2013-12-18T13:27:14.917Z", + "environment": { + "sys": { + "id": "master", + "type": "Link", + "linkType": "Environment" + } + }, + "revision": 6 + }, + "fields": { + "title": { + "en-US": "Doge" + }, + "description": { + "en-US": "nice picture" + }, + "file": { + "en-US": { + "url": "//images.ctfassets.net/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg", + "details": { + "size": 522943, + "image": { + "width": 5800, + "height": 4350 + } + }, + "fileName": "doge.jpg", + "contentType": "image/jpeg" + } + } + } +} \ No newline at end of file diff --git a/Tests/ContentfulTests/LocalizationTests.swift b/Tests/ContentfulTests/LocalizationTests.swift index 58213124..7cd47011 100644 --- a/Tests/ContentfulTests/LocalizationTests.swift +++ b/Tests/ContentfulTests/LocalizationTests.swift @@ -90,5 +90,24 @@ class LocalizationTests: XCTestCase { waitForExpectations(timeout: 10.0, handler: nil) } + + func testWalkingFallbackchainOnAsset() { + let jsonDecoder = JSONDecoder.withoutLocalizationContext() + let localesJSONData = JSONDecodingTests.jsonData("all-locales") + let localesResponse = try! jsonDecoder.decode(ArrayResponse.self, from: localesJSONData) + jsonDecoder.update(with: LocalizationContext(locales: localesResponse.items)!) + + + let assetJSONData = JSONDecodingTests.jsonData("localizable-asset") + let asset = try! jsonDecoder.decode(Asset.self, from: assetJSONData) + + expect(asset.sys.id).to(equal("1x0xpXu4pSGS4OukSyWGUK")) + expect(asset.urlString).to(equal("https://images.ctfassets.net/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg")) + + asset.setLocale(withCode: "tlh") + expect(asset.urlString).to(equal("https://images.ctfassets.net/cfexampleapi/1x0xpXu4pSGS4OukSyWGUK/cc1239c6385428ef26f4180190532818/doge.jpg")) + + + } } From 93b13b0353dd8944ee963a884c284f6ae479ee51 Mon Sep 17 00:00:00 2001 From: JP Wright Date: Mon, 30 Jul 2018 00:49:22 +0200 Subject: [PATCH 3/3] Update CHANGELOG; bump to 2.2.1 --- .env | 2 +- .envrc | 2 +- CHANGELOG.md | 10 +++++++++- Config.xcconfig | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 2ffdd07b..6a18f0ec 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -CONTENTFUL_SDK_VERSION=2.2.0 +CONTENTFUL_SDK_VERSION=2.2.1 diff --git a/.envrc b/.envrc index e39ef284..5eec314c 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -export CONTENFUL_SDK_VERSION=2.2.0 +export CONTENFUL_SDK_VERSION=2.2.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a76bbda..d1958ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from ## Table of contents #### 2.x Releases -- `2.2.0` Releases - [2.2.0](#220) +- `2.2.0` Releases - [2.2.0](#220) | [2.2.1](#221) - `2.1.0` Releases - [2.1.0](#210) - `2.0.0` Releases - [2.0.0](#200) @@ -31,6 +31,14 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from --- +## [`2.2.1`](https://github.com/contentful/contentful.swift/releases/tag/2.2.1) +Released on 2018-07-30 + +#### Fixed +- Accessing fields on assets was not respecting fallback chain logic when assets were requested with a multi-locale format. This is now fixed. + +--- + ## [`2.2.0`](https://github.com/contentful/contentful.swift/releases/tag/2.2.0) Released on 2018-06-13 diff --git a/Config.xcconfig b/Config.xcconfig index 2ffdd07b..6a18f0ec 100644 --- a/Config.xcconfig +++ b/Config.xcconfig @@ -1 +1 @@ -CONTENTFUL_SDK_VERSION=2.2.0 +CONTENTFUL_SDK_VERSION=2.2.1