honkster-jelly 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml
CHANGED
data/jelly.gemspec
CHANGED
@@ -5,6 +5,7 @@ module JellyController
|
|
5
5
|
def jelly_callback(callback_base_name = @action_name, options = {}, &block)
|
6
6
|
raw_jelly_callback(options) do
|
7
7
|
arguments = block.try(:call) || []
|
8
|
+
arguments = [arguments] unless arguments.is_a?(Array)
|
8
9
|
jelly_callback_hash("on_#{callback_base_name}", *arguments).merge(options)
|
9
10
|
end
|
10
11
|
end
|
@@ -15,6 +15,54 @@ describe ApplicationController do
|
|
15
15
|
@controller.respond_to?(:jelly_callback).should be_true
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "Arguments block" do
|
19
|
+
context "when an Array is returned from the block" do
|
20
|
+
it "sets the arguments to be an Array around the Hash" do
|
21
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
22
|
+
["foo", "bar"]
|
23
|
+
end
|
24
|
+
callback = JSON.parse(response.body)
|
25
|
+
callback["method"].should == "on_foo"
|
26
|
+
callback["arguments"].should == ["foo", "bar"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when a non-array is returned in the block" do
|
31
|
+
context "when the argument is a Hash" do
|
32
|
+
it "sets the arguments to be an Array around the Hash" do
|
33
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
34
|
+
{"foo" => "bar"}
|
35
|
+
end
|
36
|
+
callback = JSON.parse(response.body)
|
37
|
+
callback["method"].should == "on_foo"
|
38
|
+
callback["arguments"].should == [{"foo" => "bar"}]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when the argument is a String" do
|
43
|
+
it "sets the arguments to be an Array around the argument" do
|
44
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
45
|
+
"foobar"
|
46
|
+
end
|
47
|
+
callback = JSON.parse(response.body)
|
48
|
+
callback["method"].should == "on_foo"
|
49
|
+
callback["arguments"].should == ["foobar"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when the argument is a Number" do
|
54
|
+
it "sets the arguments to be an Array around the argument" do
|
55
|
+
@controller.send(:jelly_callback, 'foo', :format => :json) do
|
56
|
+
12345
|
57
|
+
end
|
58
|
+
callback = JSON.parse(response.body)
|
59
|
+
callback["method"].should == "on_foo"
|
60
|
+
callback["arguments"].should == [12345]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
18
66
|
context "when given a format" do
|
19
67
|
describe "json" do
|
20
68
|
it "responds with a json hash, even if the request is not xhr" do
|