Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: lifo/cramp
base: adc54f88ce
...
head fork: lifo/cramp
compare: 5d3be6e09f
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 23, 2011
@rookus rookus Add :event option to render_sse efdc6f7
@lifo Merge pull request #28 from rookus/master
Specifying an SSE event name as an option to render
5d3be6e
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

No commit comments for this range

Something went wrong with that request. Please try again.