test/streamit_test.rb in streamit-0.0.5 vs test/streamit_test.rb in streamit-0.0.6
- old
+ new
@@ -3,20 +3,25 @@
class StreamitTest < ActiveSupport::TestCase
def stream_store
Streamit.store
end
+ def wait_and_finish
+ Streamit.finish!
+ end
+
context "when user watches an item" do
setup do
TestWatching.class_eval do
stream :create, :actor => :watcher, :subject => :watched_item
end
@watch = TestWatching.new(:watcher => TestUser.create!, :watched_item => TestItem.create!)
end
should "create a stream if watching is created successfully" do
@watch.save
+ wait_and_finish
stream = stream_store.last
assert_not_nil stream
assert_equal "streamit.testwatchings.create", stream.stream_type
assert_equal @watch.watcher, stream.actor
assert_equal @watch.watched_item, stream.subject
@@ -25,11 +30,11 @@
should "not create a stream if failed to create a watching" do
TestWatching.class_eval do
before_create { return false }
end
- assert_no_difference("stream_store.count") { @watch.save }
+ assert_no_difference("stream_store.count") { @watch.save; wait_and_finish }
end
end
context "when create or update a user" do
setup do
@@ -42,10 +47,11 @@
should "create a stream" do
@user.singleton_class.class_eval do
stream :create
end
@user.save
+ wait_and_finish
stream = stream_store.last
assert_not_nil stream
assert_equal "streamit.testusers.create", stream.stream_type
assert_equal @user, stream.actor
assert_nil stream.subject
@@ -53,18 +59,20 @@
end
context "when user updates her attributes" do
setup do
@user.save
+ wait_and_finish
end
should "create a stream the attribute specified has changed" do
@user.singleton_class.class_eval do
stream :update, :attributes => :image_url
end
@user.image_url = "image"
@user.save
+ wait_and_finish
stream = stream_store.last
assert_not_nil stream
assert_equal "streamit.testusers.update.image_url", stream.stream_type
assert_equal @user, stream.actor
assert_nil stream.subject
@@ -75,10 +83,11 @@
@user.singleton_class.class_eval do
stream :update
end
@user.name = "davis"
@user.save
+ wait_and_finish
stream = stream_store.last
assert_not_nil stream
assert_equal "streamit.testusers.update.default", stream.stream_type
assert_equal @user, stream.actor
assert_nil stream.subject
@@ -89,10 +98,11 @@
@user.singleton_class.class_eval do
stream :update, :attributes => [:name, :image_url]
end
@user.name = "davis"
@user.save
+ wait_and_finish
stream = stream_store.last
assert_not_nil stream
assert_equal "streamit.testusers.update.default", stream.stream_type
assert_equal @user, stream.actor
assert_nil stream.subject
@@ -107,9 +117,10 @@
@user.singleton_class.class_eval do
stream :update, :attributes => :name
end
@user.image_url = "image"
@user.save
+ wait_and_finish
assert_equal 0, stream_store.count
end
end
end