test/services/publisher_test.rb in propono-0.6.3 vs test/services/publisher_test.rb in propono-0.7.0
- old
+ new
@@ -120,9 +120,55 @@
assert_raises(PublisherError, "Topic is nil") do
Publisher.publish(nil, "foobar")
end
end
+ def test_tcp_uses_correct_message
+ Propono.config.tcp_host = "http://meducation.net"
+ Propono.config.tcp_port = 1234
+ topic_id = "my-fav-topic"
+ message = "foobar"
+ payload = {topic: topic_id, message: message}.to_json
+
+ socket = mock()
+ socket.expects(:write).with(payload)
+ socket.expects(:close)
+ TCPSocket.stubs(new: socket)
+
+ publisher = Publisher.new(topic_id, message)
+ publisher.send(:publish_via_tcp)
+ end
+
+ def test_tcp_uses_correct_message_host_and_port
+ host = "http://meducation.net"
+ port = 1234
+ Propono.config.tcp_host = host
+ Propono.config.tcp_port = port
+ topic_id = "my-fav-topic"
+ message = "foobar"
+ TCPSocket.expects(:new).with(host, port)
+
+ publisher = Publisher.new(topic_id, message)
+ publisher.send(:publish_via_tcp)
+ end
+
+ def test_exception_from_tcpsocket_caught_and_logged
+ host = "http://meducation.net"
+ port = 1234
+ Propono.config.tcp_host = host
+ Propono.config.tcp_port = port
+
+ client = Publisher.new("topic_id", "message")
+ Propono.config.logger.expects(:error).with() {|x| x =~ /^Propono failed to send : getaddrinfo:.*/}
+ client.send(:publish_via_tcp)
+ end
+
+ def test_publish_should_raise_exception_if_topic_is_nil
+ assert_raises(PublisherError, "Topic is nil") do
+ Publisher.publish(nil, "foobar")
+ end
+ end
+
def test_publish_should_raise_exception_if_message_is_nil
assert_raises(PublisherError, "Message is nil") do
Publisher.publish("foobar", nil)
end
end