Skip to content
Browse files

Add :event option to render_sse

  • Loading branch information...
1 parent adc54f8 commit efdc6f7cade7c7f6646a0e5adcfbde895e784be6 @rookus rookus committed Sep 23, 2011
Showing with 7 additions and 1 deletion.
  1. +1 −0 lib/cramp/action.rb
  2. +6 −1 test/controller/sse_test.rb
View
1 lib/cramp/action.rb
@@ -64,6 +64,7 @@ def render_long_polling(data, *)
def render_sse(data, options = {})
result = "id: #{sse_event_id}\n"
+ result << "event: #{options[:event]}\n" if options[:event]
result << "retry: #{options[:retry]}\n" if options[:retry]
data.split(/\n/).each {|d| result << "data: #{d}\n" }
View
7 test/controller/sse_test.rb
@@ -9,6 +9,7 @@ class LiveController < Cramp::Action
def go_sse
render "Hello World"
render "Nothing", :retry => 10
+ render "Hello non-message event type", :event => :different
finish
end
end
@@ -28,7 +29,7 @@ def test_headers
end
def test_body
- get_body_chunks '/', :count => 2 do |chunks|
+ get_body_chunks '/', :count => 3 do |chunks|
# chunk1 = id: 1297999043\ndata: Hello World
first_chunk = chunks[0].split("\n")
assert first_chunk[0] =~ /\Aid: \d+\Z/, first_chunk.inspect
@@ -37,6 +38,10 @@ def test_body
second_chunk = chunks[1].split("\n")
assert_equal "retry: 10", second_chunk[1]
assert_equal "data: Nothing", second_chunk[2]
+
+ third_chunk = chunks[2].split("\n")
+ assert_equal "event: different", third_chunk[1]
+ assert_equal "data: Hello non-message event type", third_chunk[2]
end
end

0 comments on commit efdc6f7

Please sign in to comment.
Something went wrong with that request. Please try again.