happy 0.1.0.pre.4 → 0.1.0.pre.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/happy/controller.rb +1 -1
- data/lib/happy/controller_ext/actions.rb +13 -7
- data/lib/happy/version.rb +1 -1
- data/lib/happy.rb +1 -0
- data/spec/controller_ext/actions_spec.rb +42 -0
- data/spec/controller_ext/routing_spec.rb +14 -0
- metadata +19 -19
data/lib/happy/controller.rb
CHANGED
@@ -73,13 +73,19 @@ module Happy
|
|
73
73
|
response[name] = value
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
def run(thing, options = {}, &blk)
|
77
|
+
if thing.is_a?(Class) && thing.ancestors.include?(Happy::Controller)
|
78
|
+
# Happy controllers!
|
79
|
+
thing.new(env, options, &blk).perform
|
80
|
+
elsif thing.respond_to?(:call)
|
81
|
+
# Rack apps!
|
82
|
+
context.response = thing.call(request.env)
|
83
|
+
halt!
|
84
|
+
elsif thing.respond_to?(:to_s)
|
85
|
+
thing.to_s
|
86
|
+
else
|
87
|
+
raise "Don't know how to run #{thing.inspect} :("
|
88
|
+
end
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
data/lib/happy/version.rb
CHANGED
data/lib/happy.rb
CHANGED
@@ -63,6 +63,48 @@ module Happy
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
describe '#run' do
|
67
|
+
it "passes control to another controller" do
|
68
|
+
class InnerController < Controller
|
69
|
+
route { 'awesome!' }
|
70
|
+
end
|
71
|
+
|
72
|
+
def app
|
73
|
+
build_controller { run InnerController }
|
74
|
+
end
|
75
|
+
|
76
|
+
response_for { get '/' }.body.should == 'awesome!'
|
77
|
+
end
|
78
|
+
|
79
|
+
it "passes control to a Rack app" do
|
80
|
+
class SomeRackApp
|
81
|
+
def self.call(env)
|
82
|
+
Rack::Response.new('racksome!')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def app
|
87
|
+
build_controller { run SomeRackApp }
|
88
|
+
end
|
89
|
+
|
90
|
+
response_for { get '/' }.body.should == 'racksome!'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "falls back to .to_s" do
|
94
|
+
class SomeClass
|
95
|
+
def self.to_s
|
96
|
+
"stringsome!"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def app
|
101
|
+
build_controller { run SomeClass }
|
102
|
+
end
|
103
|
+
|
104
|
+
response_for { get '/' }.body.should == 'stringsome!'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
66
108
|
describe '#header' do
|
67
109
|
it "sets the specified header in the response" do
|
68
110
|
subject.send(:context).response.should_receive(:[]=).with('Content-type', 'text/css')
|
@@ -13,6 +13,11 @@ module Happy
|
|
13
13
|
serve! "Please provide a name."
|
14
14
|
end
|
15
15
|
path('number-:num') { serve! "num = #{params['num']}" }
|
16
|
+
path('return-value') { 'moo?' }
|
17
|
+
path('resource') do
|
18
|
+
get { 'GET resource' }
|
19
|
+
post { 'POST resource' }
|
20
|
+
end
|
16
21
|
serve! "root"
|
17
22
|
end
|
18
23
|
end
|
@@ -23,6 +28,10 @@ module Happy
|
|
23
28
|
response_for { get '/foo' }.body.should == 'bar'
|
24
29
|
end
|
25
30
|
|
31
|
+
it "renders its block's results if no other #serve! call is made" do
|
32
|
+
response_for { get '/return-value' }.body.should == 'moo?'
|
33
|
+
end
|
34
|
+
|
26
35
|
it "routes independently from the request method" do
|
27
36
|
response_for { post '/foo' }.body.should == 'bar'
|
28
37
|
end
|
@@ -40,6 +49,11 @@ module Happy
|
|
40
49
|
response_for { get '/hello' }.body.should == 'Please provide a name.'
|
41
50
|
end
|
42
51
|
|
52
|
+
it "just matches the method if no path name is given" do
|
53
|
+
response_for { get '/resource' }.body.should == 'GET resource'
|
54
|
+
response_for { post '/resource' }.body.should == 'POST resource'
|
55
|
+
end
|
56
|
+
|
43
57
|
it "parses parameters when the provided path is a symbol" do
|
44
58
|
response_for { get '/hello/hendrik' }.body.should == 'Hello hendrik'
|
45
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: happy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.5
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-31 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70252206125620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70252206125620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack
|
27
|
-
requirement: &
|
27
|
+
requirement: &70252206112780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.4'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70252206112780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: happy-helpers
|
38
|
-
requirement: &
|
38
|
+
requirement: &70252206112060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.1.0.pre.5
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70252206112060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: allowance
|
49
|
-
requirement: &
|
49
|
+
requirement: &70252206111260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.1.1
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70252206111260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70252206110820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70252206110820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70252206109960 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.8'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70252206109960
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec-html-matchers
|
82
|
-
requirement: &
|
82
|
+
requirement: &70252206109140 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70252206109140
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rack-test
|
93
|
-
requirement: &
|
93
|
+
requirement: &70252206108080 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70252206108080
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: watchr
|
104
|
-
requirement: &
|
104
|
+
requirement: &70252206107080 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70252206107080
|
113
113
|
description: A happy little toolkit for writing web applications.
|
114
114
|
email:
|
115
115
|
- hendrik@mans.de
|