Skip to content

Commit

Permalink
BehaviorSubject mistakenly refers to check_unsubscribed as a class me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
Bittrance committed Oct 21, 2017
1 parent baf10b6 commit 153da58
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/rx/subjects/behavior_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def has_observers?

# Gets the current value or throws an exception.
def value
gate.synchronize do
self.check_unsubscribed
gate.synchronize do
check_unsubscribed
raise @error if @error
@value
end
Expand All @@ -41,8 +41,8 @@ def value
# Notifies all subscribed observers about the end of the sequence.
def on_completed
os = nil
@gate.synchronize do
self.check_unsubscribed
@gate.synchronize do
check_unsubscribed

unless @stopped
os = @observers.clone
Expand All @@ -60,7 +60,7 @@ def on_error(error)

os = nil
@gate.synchronize do
self.check_unsubscribed
check_unsubscribed

unless @stopped
os = @observers.clone
Expand All @@ -77,7 +77,7 @@ def on_error(error)
def on_next(value)
os = nil
@gate.synchronize do
self.check_unsubscribed
check_unsubscribed
@value = value
os = @observers.clone unless @stopped
end
Expand All @@ -91,7 +91,7 @@ def subscribe(observer)

err = nil
gate.synchronize do
self.check_unsubscribed
check_unsubscribed

unless @stopped
observers.push(observer)
Expand Down
31 changes: 31 additions & 0 deletions test/rx/subjects/test_behavior_subject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

require 'test_helper'

class TestBehaviorSubject < Minitest::Test
def test_subscriber_notified_on_change
value = 0
subject = Rx::BehaviorSubject.new 0
subject.as_observable.subscribe { |update| value = update }
subject.on_next 1
assert_equal 1, value
end

def test_multiple_observers_notified_on_change
value1 = 0
value2 = 0
subject = Rx::BehaviorSubject.new 0
subject.as_observable.subscribe { |update| value1 = update }
subject.as_observable.subscribe { |update| value2 = update }
subject.on_next 1
assert_equal 1, value1
assert_equal 1, value2
end

def test_errors_on_next_when_unsubscribed
subject = Rx::BehaviorSubject.new 0
subject.as_observable.subscribe { }
subject.unsubscribe
assert_raises(RuntimeError) { subject.on_next 1 }
end
end

0 comments on commit 153da58

Please sign in to comment.