From 91287442d2b7da769f67afa1a96c6a9b0cfcf0ad Mon Sep 17 00:00:00 2001 From: Paul Cantrell Date: Fri, 22 Jun 2018 13:56:20 -0500 Subject: [PATCH] Return a nil imageResource for a nil imageURL Fixes https://github.com/bustoutsolutions/siesta/issues/249 --- Siesta.xcodeproj/project.pbxproj | 4 +++ Source/SiestaUI/RemoteImageView.swift | 6 +++- Tests/Functional/RemoteImageViewSpec.swift | 38 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/RemoteImageViewSpec.swift diff --git a/Siesta.xcodeproj/project.pbxproj b/Siesta.xcodeproj/project.pbxproj index 7dbb6ecc..94fb06cb 100644 --- a/Siesta.xcodeproj/project.pbxproj +++ b/Siesta.xcodeproj/project.pbxproj @@ -184,6 +184,7 @@ DA8EF6D11BC20AFE002175EB /* ProgressSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA8EF6CF1BC1A917002175EB /* ProgressSpec.swift */; }; DA99B5C91B38C8E6009C6937 /* String+Siesta.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA99B5C81B38C8E6009C6937 /* String+Siesta.swift */; }; DA9AA8151CCAFDD20016DB18 /* ConfigurationPatternConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9AA8141CCAFDD20016DB18 /* ConfigurationPatternConvertible.swift */; }; + DA9E515420DD7A45000923BA /* RemoteImageViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9E515320DD7A45000923BA /* RemoteImageViewSpec.swift */; }; DA9F4BDC1B3DFE3700E8966F /* WeakCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9F4BDB1B3DFE3700E8966F /* WeakCache.swift */; }; DA9F4BDE1B3F8E2E00E8966F /* WeakCacheSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9F4BDD1B3F8E2E00E8966F /* WeakCacheSpec.swift */; }; DA9F4BE01B41C9CC00E8966F /* ResourceObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9F4BDF1B41C9CC00E8966F /* ResourceObserver.swift */; }; @@ -387,6 +388,7 @@ DA8EF6CF1BC1A917002175EB /* ProgressSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressSpec.swift; sourceTree = ""; }; DA99B5C81B38C8E6009C6937 /* String+Siesta.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Siesta.swift"; sourceTree = ""; }; DA9AA8141CCAFDD20016DB18 /* ConfigurationPatternConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationPatternConvertible.swift; sourceTree = ""; }; + DA9E515320DD7A45000923BA /* RemoteImageViewSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteImageViewSpec.swift; sourceTree = ""; }; DA9F4BDB1B3DFE3700E8966F /* WeakCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakCache.swift; sourceTree = ""; }; DA9F4BDD1B3F8E2E00E8966F /* WeakCacheSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakCacheSpec.swift; sourceTree = ""; }; DA9F4BDF1B41C9CC00E8966F /* ResourceObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResourceObserver.swift; sourceTree = ""; }; @@ -621,6 +623,7 @@ DA5A902F2054E0C500309D8B /* EntityCacheSpec.swift */, DA3314301B4DC11900A7A175 /* ResponseDataHandlingSpec.swift */, DA8EF6CF1BC1A917002175EB /* ProgressSpec.swift */, + DA9E515320DD7A45000923BA /* RemoteImageViewSpec.swift */, DA9F4BDD1B3F8E2E00E8966F /* WeakCacheSpec.swift */, DA4D61971B751FEE00F6BB9C /* ObjcCompatibilitySpec.m */, DA99B5C71B38C36A009C6937 /* Support */, @@ -1381,6 +1384,7 @@ DA49EA801B36174700AE1B8F /* SpecHelpers.swift in Sources */, DA9F4BDE1B3F8E2E00E8966F /* WeakCacheSpec.swift in Sources */, DA3314311B4DC11900A7A175 /* ResponseDataHandlingSpec.swift in Sources */, + DA9E515420DD7A45000923BA /* RemoteImageViewSpec.swift in Sources */, DA49EA7C1B35FE5F00AE1B8F /* ServiceSpec.swift in Sources */, DA788A8E1D6AC1580085C820 /* ObjcCompatibilitySpec.m in Sources */, DA4D619B1B7521EE00F6BB9C /* TestService.swift in Sources */, diff --git a/Source/SiestaUI/RemoteImageView.swift b/Source/SiestaUI/RemoteImageView.swift index c5780faa..de3c2d4e 100644 --- a/Source/SiestaUI/RemoteImageView.swift +++ b/Source/SiestaUI/RemoteImageView.swift @@ -39,7 +39,11 @@ open class RemoteImageView: UIImageView public var imageURL: String? { get { return imageResource?.url.absoluteString } - set { imageResource = imageService.resource(absoluteURL: newValue) } + set { + imageResource = (newValue == nil) + ? nil + : imageService.resource(absoluteURL: newValue) + } } /// Optional image transform applyed to placeholderImage and downloaded image diff --git a/Tests/Functional/RemoteImageViewSpec.swift b/Tests/Functional/RemoteImageViewSpec.swift new file mode 100644 index 00000000..69a73dbd --- /dev/null +++ b/Tests/Functional/RemoteImageViewSpec.swift @@ -0,0 +1,38 @@ +// +// RemoteImageViewSpec.swift +// Siesta +// +// Created by Paul on 2018/6/22. +// Copyright © 2018 Bust Out Solutions. All rights reserved. +// + +import Foundation + +import SiestaUI +import Quick +import Nimble +import Nocilla + +class RemoteImageViewSpec: SiestaSpec + { + override func spec() + { + let remoteImageView = specVar { RemoteImageView() } + + it("handles a nil imageResource") + { + remoteImageView().imageResource = nil + expect(remoteImageView().imageURL).to(beNil()) + expect(remoteImageView().imageResource).to(beNil()) + } + + it("handles a nil imageURL") + { + remoteImageView().imageURL = nil + expect(remoteImageView().imageURL).to(beNil()) + expect(remoteImageView().imageResource).to(beNil()) + } + + // TODO: build out SiestaUI tests + } + }