Skip to content

Commit

Permalink
Merge pull request #259 from bustoutsolutions/fix-imageresource-nil-u…
Browse files Browse the repository at this point in the history
…rl-handling

Return a nil imageResource for a nil imageURL
  • Loading branch information
pcantrell authored Jun 22, 2018
2 parents 27dd4f9 + 9128744 commit 64ea41c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Siesta.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -387,6 +388,7 @@
DA8EF6CF1BC1A917002175EB /* ProgressSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProgressSpec.swift; sourceTree = "<group>"; };
DA99B5C81B38C8E6009C6937 /* String+Siesta.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Siesta.swift"; sourceTree = "<group>"; };
DA9AA8141CCAFDD20016DB18 /* ConfigurationPatternConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationPatternConvertible.swift; sourceTree = "<group>"; };
DA9E515320DD7A45000923BA /* RemoteImageViewSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteImageViewSpec.swift; sourceTree = "<group>"; };
DA9F4BDB1B3DFE3700E8966F /* WeakCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakCache.swift; sourceTree = "<group>"; };
DA9F4BDD1B3F8E2E00E8966F /* WeakCacheSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeakCacheSpec.swift; sourceTree = "<group>"; };
DA9F4BDF1B41C9CC00E8966F /* ResourceObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResourceObserver.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -621,6 +623,7 @@
DA5A902F2054E0C500309D8B /* EntityCacheSpec.swift */,
DA3314301B4DC11900A7A175 /* ResponseDataHandlingSpec.swift */,
DA8EF6CF1BC1A917002175EB /* ProgressSpec.swift */,
DA9E515320DD7A45000923BA /* RemoteImageViewSpec.swift */,
DA9F4BDD1B3F8E2E00E8966F /* WeakCacheSpec.swift */,
DA4D61971B751FEE00F6BB9C /* ObjcCompatibilitySpec.m */,
DA99B5C71B38C36A009C6937 /* Support */,
Expand Down Expand Up @@ -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 */,
Expand Down
6 changes: 5 additions & 1 deletion Source/SiestaUI/RemoteImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions Tests/Functional/RemoteImageViewSpec.swift
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 64ea41c

Please sign in to comment.