pakada-dispatch 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/lib/pakada/dispatch/controller.rb +8 -0
- data/lib/pakada/dispatch/version.rb +1 -1
- data/spec/controller_spec.rb +31 -0
- metadata +5 -5
data/LICENSE
CHANGED
@@ -47,6 +47,12 @@ class Pakada
|
|
47
47
|
throw :finish
|
48
48
|
end
|
49
49
|
|
50
|
+
def json(obj)
|
51
|
+
response.headers["Content-Type"] = "application/json"
|
52
|
+
response.write obj.respond_to?(:json) ? obj.to_json : Yajl::Encoder.encode(obj)
|
53
|
+
finish!
|
54
|
+
end
|
55
|
+
|
50
56
|
def redirect(*args)
|
51
57
|
response.status = (Fixnum === args[0]) ? args.shift : 303
|
52
58
|
|
@@ -56,6 +62,8 @@ class Pakada
|
|
56
62
|
url = args[0].to_url
|
57
63
|
elsif args[0]
|
58
64
|
url = args[0]
|
65
|
+
else
|
66
|
+
raise ArgumentError, "Controller#redirect needs a URL"
|
59
67
|
end
|
60
68
|
|
61
69
|
response.headers["Location"] = url
|
data/spec/controller_spec.rb
CHANGED
@@ -223,6 +223,13 @@ describe "SomeController" do
|
|
223
223
|
|
224
224
|
controller.response.status.should == 303
|
225
225
|
end
|
226
|
+
|
227
|
+
it "raises an ArgumentError if the arguments don't include a URL" do
|
228
|
+
controller = subject.new({})
|
229
|
+
|
230
|
+
proc { controller.redirect }.should raise_error(ArgumentError)
|
231
|
+
proc { controller.redirect 303 }.should raise_error(ArgumentError)
|
232
|
+
end
|
226
233
|
end
|
227
234
|
|
228
235
|
describe "#not_found" do
|
@@ -282,6 +289,30 @@ describe "SomeController" do
|
|
282
289
|
end
|
283
290
|
end
|
284
291
|
end
|
292
|
+
|
293
|
+
describe "#json" do
|
294
|
+
it "sets the JSON Content-Type header, writes JSON output and finishes" do
|
295
|
+
subject.action(:foo) { json :key => "value" }
|
296
|
+
controller = subject.new({})
|
297
|
+
|
298
|
+
controller.should_receive :finish!
|
299
|
+
controller.call_action :foo
|
300
|
+
|
301
|
+
controller.response.headers["Content-Type"].should == "application/json"
|
302
|
+
Yajl::Parser.parse(controller.response.body.join).should == {"key" => "value"}
|
303
|
+
end
|
304
|
+
|
305
|
+
it "tries to call #to_json and use its result as output" do
|
306
|
+
obj = double "output", :to_json => '{"key":"value"}'
|
307
|
+
obj.should_receive :to_json
|
308
|
+
|
309
|
+
subject.action(:foo) { json obj }
|
310
|
+
controller = subject.new({})
|
311
|
+
controller.call_action :foo
|
312
|
+
|
313
|
+
Yajl::Parser.parse(controller.response.body.join).should == {"key" => "value"}
|
314
|
+
end
|
315
|
+
end
|
285
316
|
end
|
286
317
|
|
287
318
|
describe Pakada::Dispatch::NOT_FOUND_ENDPOINT do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pakada-dispatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lars Gierth
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-11 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
requirements:
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
112
|
+
hash: 530646867
|
113
113
|
segments:
|
114
114
|
- 0
|
115
115
|
version: "0"
|
@@ -118,14 +118,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements:
|
119
119
|
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
hash:
|
121
|
+
hash: 530646867
|
122
122
|
segments:
|
123
123
|
- 0
|
124
124
|
version: "0"
|
125
125
|
requirements: []
|
126
126
|
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.5.
|
128
|
+
rubygems_version: 1.5.2
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
131
|
summary: Routing And Action Controllers For Pakada
|