-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from RxSwiftCommunity/mt-1.0.5
Mt 1.0.5
- Loading branch information
Showing
7 changed files
with
246 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
source 'https://github.com/CocoaPods/Specs.git' | ||
use_frameworks! | ||
|
||
target 'RxRealm_Example', :exclusive => true do | ||
platform :ios, '8.3' | ||
target 'RxRealm_Example' do | ||
platform :ios, '8.0' | ||
pod 'RxRealm', :path => '../' | ||
pod 'RxSwift' | ||
pod 'RxCocoa' | ||
pod 'RealmSwift' | ||
end | ||
|
||
target 'RxRealm_Tests', :exclusive => true do | ||
target 'RxRealm_Tests' do | ||
pod 'RxTests' | ||
|
||
pod 'RxRealm', :path => '../' | ||
pod 'RxSwift' | ||
pod 'RxCocoa' | ||
pod 'RealmSwift' | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// RxRealmRealmTests.swift | ||
// RxRealm | ||
// | ||
// Created by Marin Todorov on 5/22/16. | ||
// Copyright © 2016 CocoaPods. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
import RxSwift | ||
import RealmSwift | ||
import RxRealm | ||
import RxTests | ||
|
||
class RxRealmRealmTests: XCTestCase { | ||
private func realmInMemory(name: String) -> Realm { | ||
var conf = Realm.Configuration() | ||
conf.inMemoryIdentifier = name | ||
return try! Realm(configuration: conf) | ||
} | ||
|
||
func testRealmDidChangeNotifications() { | ||
let expectation1 = expectationWithDescription("Realm notification") | ||
|
||
let realm = realmInMemory(#function) | ||
let bag = DisposeBag() | ||
|
||
let scheduler = TestScheduler(initialClock: 0) | ||
let observer = scheduler.createObserver((Realm, Notification)) | ||
|
||
let realm$ = realm.asObservable().shareReplay(1) | ||
realm$.scan(0, accumulator: {acc, _ in return acc+1}) | ||
.filter { $0 == 2 }.map {_ in ()}.subscribeNext(expectation1.fulfill).addDisposableTo(bag) | ||
realm$ | ||
.subscribe(observer).addDisposableTo(bag) | ||
|
||
//interact with Realm here | ||
delay(0.1) { | ||
try! realm.write { | ||
realm.add(Message("first")) | ||
} | ||
} | ||
delayInBackground(0.3) {[unowned self] in | ||
let realm = self.realmInMemory(#function) | ||
try! realm.write { | ||
realm.add(Message("second")) | ||
} | ||
} | ||
|
||
scheduler.start() | ||
|
||
waitForExpectationsWithTimeout(0.5) {error in | ||
XCTAssertTrue(error == nil) | ||
XCTAssertEqual(observer.events.count, 2) | ||
XCTAssertEqual(observer.events[0].value.element!.1, Notification.DidChange) | ||
XCTAssertEqual(observer.events[1].value.element!.1, Notification.DidChange) | ||
} | ||
} | ||
|
||
func testRealmRefreshRequiredNotifications() { | ||
let expectation1 = expectationWithDescription("Realm notification") | ||
|
||
let realm = realmInMemory(#function) | ||
realm.autorefresh = false | ||
|
||
let bag = DisposeBag() | ||
|
||
let scheduler = TestScheduler(initialClock: 0) | ||
let observer = scheduler.createObserver((Realm, Notification)) | ||
|
||
let realm$ = realm.asObservable().shareReplay(1) | ||
realm$.scan(0, accumulator: {acc, _ in return acc+1}) | ||
.filter { $0 == 1 }.map {_ in ()}.subscribeNext(expectation1.fulfill).addDisposableTo(bag) | ||
realm$ | ||
.subscribe(observer).addDisposableTo(bag) | ||
|
||
//interact with Realm here from background | ||
delayInBackground(0.1) {[unowned self] in | ||
let realm = self.realmInMemory(#function) | ||
try! realm.write { | ||
realm.add(Message("second")) | ||
} | ||
} | ||
|
||
scheduler.start() | ||
|
||
waitForExpectationsWithTimeout(0.5) {error in | ||
XCTAssertTrue(error == nil) | ||
XCTAssertEqual(observer.events.count, 1) | ||
XCTAssertEqual(observer.events[0].value.element!.1, Notification.RefreshRequired) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters