Skip to content

Commit 12dff4c

Browse files
author
Bittrance
committed
BehaviorSubject mistakenly refers to check_unsubscribed as a class method
1 parent b84964d commit 12dff4c

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

lib/rx/subjects/behavior_subject.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def has_observers?
3131

3232
# Gets the current value or throws an exception.
3333
def value
34-
gate.synchronize do
35-
self.check_unsubscribed
34+
gate.synchronize do
35+
check_unsubscribed
3636
raise @error if @error
3737
@value
3838
end
@@ -41,8 +41,8 @@ def value
4141
# Notifies all subscribed observers about the end of the sequence.
4242
def on_completed
4343
os = nil
44-
@gate.synchronize do
45-
self.check_unsubscribed
44+
@gate.synchronize do
45+
check_unsubscribed
4646

4747
unless @stopped
4848
os = @observers.clone
@@ -60,7 +60,7 @@ def on_error(error)
6060

6161
os = nil
6262
@gate.synchronize do
63-
self.check_unsubscribed
63+
check_unsubscribed
6464

6565
unless @stopped
6666
os = @observers.clone
@@ -77,7 +77,7 @@ def on_error(error)
7777
def on_next(value)
7878
os = nil
7979
@gate.synchronize do
80-
self.check_unsubscribed
80+
check_unsubscribed
8181
@value = value
8282
os = @observers.clone unless @stopped
8383
end
@@ -91,7 +91,7 @@ def subscribe(observer)
9191

9292
err = nil
9393
gate.synchronize do
94-
self.check_unsubscribed
94+
check_unsubscribed
9595

9696
unless @stopped
9797
observers.push(observer)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2+
3+
require 'test_helper'
4+
5+
class TestBehaviorSubject < Minitest::Test
6+
def test_subscriber_notified_on_change
7+
value = 0
8+
subject = Rx::BehaviorSubject.new 0
9+
subject.as_observable.subscribe { |update| value = update }
10+
subject.on_next 1
11+
assert_equal 1, value
12+
end
13+
14+
def test_multiple_observers_notified_on_change
15+
value1 = 0
16+
value2 = 0
17+
subject = Rx::BehaviorSubject.new 0
18+
subject.as_observable.subscribe { |update| value1 = update }
19+
subject.as_observable.subscribe { |update| value2 = update }
20+
subject.on_next 1
21+
assert_equal 1, value1
22+
assert_equal 1, value2
23+
end
24+
25+
def test_errors_on_next_when_unsubscribed
26+
subject = Rx::BehaviorSubject.new 0
27+
subject.as_observable.subscribe { }
28+
subject.unsubscribe
29+
assert_raises(RuntimeError) { subject.on_next 1 }
30+
end
31+
end

0 commit comments

Comments
 (0)