manveru-innate 2009.02.06 → 2009.02.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,4 +63,24 @@ describe Innate::Helper::Link do
63
63
  FNL.a('duh/bar', 'duh/bar', :x => :y).should == '<a href="/foo/duh/bar?x=y">duh/bar</a>'
64
64
  FNL.a('foo', :/, :x => :y).should == '<a href="/foo/?x=y">foo</a>'
65
65
  end
66
+
67
+ should 'return module when Module is given to #each' do
68
+ Innate::HelpersHelper.each_extend(self, Innate::Helper::Link) do |p|
69
+ p.should == Innate::Helper::Link
70
+ end
71
+ end
72
+
73
+ should 'raise if helpers are not found' do
74
+ lambda{
75
+ Innate::HelpersHelper.each(:foo, :bar)
76
+ }.should.raise(LoadError).
77
+ message.should == "Helper foo not found"
78
+ end
79
+
80
+ should 'raise if helper is not found' do
81
+ lambda{
82
+ Innate::HelpersHelper.try_require(:foo)
83
+ }.should.raise(LoadError).
84
+ message.should == "Helper foo not found"
85
+ end
66
86
  end
@@ -3,9 +3,7 @@ Innate.options.app.root = File.dirname(__FILE__)
3
3
  Innate.options.app.view = ''
4
4
 
5
5
  class AspectSpec
6
- include Innate::Node
7
- map '/'
8
- provide :html => :none
6
+ Innate.node('/', self).provide(:html => :none)
9
7
 
10
8
  before(:with_before){ $aspect_spec_before += 40 }
11
9
  def with_before; $aspect_spec_before += 2; end
@@ -15,15 +13,13 @@ class AspectSpec
15
13
 
16
14
  wrap(:with_wrap){ $aspect_spec_wrap += 20 }
17
15
  def with_wrap; $aspect_spec_wrap += 2; end
18
-
16
+
19
17
  before(:with_instance_var){ @foo = 'Hello'; @bar = 'World' }
20
18
  def with_instance_var; "#{@foo} #{@bar}"; end
21
19
  end
22
20
 
23
21
  class AspectAllSpec
24
- include Innate::Node
25
- map '/all'
26
- provide :html => :none
22
+ Innate.node('/all', self).provide(:html => :none)
27
23
 
28
24
  before_all{ $aspect_spec_before_all += 40; @foo = 'Hello'; @bar = 'World' }
29
25
  after_all{ $aspect_spec_after_all += 40 }
@@ -34,6 +30,7 @@ class AspectAllSpec
34
30
  end
35
31
 
36
32
  class AspecNoMethodSpec
33
+ Innate.node('/without_method', self)
37
34
  include Innate::Node
38
35
  map '/without_method'
39
36
  view_root 'view'
@@ -16,10 +16,6 @@ class SpecFlash
16
16
  "Bye #{flash[:name]}"
17
17
  end
18
18
 
19
- def box
20
- flashbox
21
- end
22
-
23
19
  def check_empty
24
20
  flash.empty?.to_s
25
21
  end
@@ -35,13 +31,6 @@ class SpecFlash
35
31
  "Bye #{flash[:name]}"
36
32
  end
37
33
 
38
- def set(*hash)
39
- Hash[*hash].each do |key, value|
40
- flash[key] = value
41
- end
42
- hash.inspect
43
- end
44
-
45
34
  def merge!
46
35
  flash.merge!(:name => 'feagliir').inspect
47
36
  end
@@ -54,6 +54,12 @@ describe Innate::Helper::Link do
54
54
  Two.route('/foo/bar', :a => :b).should == URI('/two/foo/bar?a=b')
55
55
  Two.route(:foo, :bar, :a => :b).should == URI('/two/foo/bar?a=b')
56
56
  end
57
+
58
+ should 'prefix the links as defined in the options' do
59
+ Innate.options.app.prefix = '/bar'
60
+ One.route('/foo').should == URI('/bar/foo')
61
+ Innate.options.app.prefix = '/'
62
+ end
57
63
  end
58
64
 
59
65
  describe '#anchor' do
@@ -1,8 +1,8 @@
1
1
  require 'spec/helper'
2
2
 
3
+ Innate.options.app.root = File.dirname(__FILE__)
3
4
  class SpecHelperPartial
4
- include Innate::Node
5
- map '/'
5
+ Innate.node '/'
6
6
 
7
7
  def index
8
8
  '<html><head><title><%= render_partial("/title") %></title></head></html>'
@@ -25,17 +25,24 @@ class SpecHelperPartial
25
25
  'From Action | ' << render_template("partial.erb")
26
26
  end
27
27
 
28
- def recursive(locals = false)
29
- respond render_template('recursive_locals.erb', :n => 1) if locals
28
+ def recursive
30
29
  @n = 1
31
30
  end
32
31
 
33
32
  def without_ext
34
- render_template('title')
33
+ render_template('partial')
35
34
  end
36
35
  end
37
36
 
38
- Innate.options.app.root = File.dirname(__FILE__)
37
+ class SpecHelperPartialWithLayout < SpecHelperPartial
38
+ Innate.node '/with_layout'
39
+ layout('layout')
40
+ view_root '/'
41
+
42
+ def layout
43
+ '<h1>with layout</h1><%= @content %>'
44
+ end
45
+ end
39
46
 
40
47
  describe Innate::Helper::Partial do
41
48
  behaves_like :mock
@@ -61,6 +68,10 @@ describe Innate::Helper::Partial do
61
68
  end
62
69
 
63
70
  should 'not require file extension' do
64
- get('/without_ext').body.should == 'Title'
71
+ get('/without_ext').body.should == "From Partial \n"
72
+ end
73
+
74
+ should 'render template with layout' do
75
+ get('/with_layout/without_ext').body.should == "<h1>with layout</h1>From Partial \n"
65
76
  end
66
77
  end
data/spec/innate/node.rb CHANGED
@@ -5,9 +5,7 @@ Innate.options.app.view = ''
5
5
  Innate.options.app.layout = 'node'
6
6
 
7
7
  class SpecNode
8
- include Innate::Node
9
- map '/'
10
- provide :html => :erb, :erb => :none
8
+ Innate.node('/').provide(:html => :erb, :erb => :none)
11
9
 
12
10
  def foo; end
13
11
  def bar; end
@@ -18,10 +16,7 @@ class SpecNode
18
16
  end
19
17
 
20
18
  class SpecNodeProvide
21
- include Innate::Node
22
- map '/provide'
23
-
24
- provide :html => :erb, :erb => :none
19
+ Innate.node('/provide').provide(:html => :erb, :erb => :none)
25
20
 
26
21
  def foo
27
22
  '<%= 21 * 2 %>'
@@ -33,10 +28,8 @@ class SpecNodeProvide
33
28
  end
34
29
 
35
30
  class SpecNodeProvideTemplate
36
- include Innate::Node
37
- map '/provide_template'
38
-
39
- provide :html => :erb, :erb => :none
31
+ Innate.node('/provide_template')
32
+ provide(:html => :erb, :erb => :none, :yaml => :yaml, :json => :json)
40
33
 
41
34
  view_root 'node'
42
35
  end
@@ -52,15 +45,36 @@ class SpecNodeWithLayout < SpecNodeProvide
52
45
  map '/layout'
53
46
  end
54
47
 
48
+ class SpecNodeWithLayoutView < SpecNodeProvide
49
+ view_root 'node/another_layout'
50
+ layout 'another_layout'
51
+ map '/another_layout'
52
+ end
53
+
54
+ class SpecNodeWithLayoutMethod < SpecNodeProvide
55
+ map '/layout_method'
56
+ layout 'layout_method'
57
+
58
+ def layout_method
59
+ '<div class="content"><%= @content %></div>'
60
+ end
61
+ end
62
+
55
63
  class SpecNodeIndex
56
- include Innate::Node
57
- map '/spec_index'
64
+ Innate.node('/spec_index')
58
65
 
59
66
  def index
60
67
  "I have no parameters"
61
68
  end
62
69
  end
63
70
 
71
+ class SpecNodeAliasView < SpecNodeProvideTemplate
72
+ map '/alias_view'
73
+ view_root 'node'
74
+
75
+ alias_view :aliased, :bar
76
+ end
77
+
64
78
  describe 'Innate::Node' do
65
79
  behaves_like :mock
66
80
 
@@ -72,6 +86,12 @@ describe 'Innate::Node' do
72
86
  end
73
87
  end
74
88
 
89
+ def assert_wish(url, body, content_type)
90
+ got = get(url)
91
+ got.body.strip.should == body
92
+ got.headers['Content-Type'].should == content_type
93
+ end
94
+
75
95
  should 'resolve actions with methods' do
76
96
  SpecNode.resolve('/').should.be.nil
77
97
  SpecNode.resolve('/index').should.be.nil
@@ -116,12 +136,6 @@ describe 'Innate::Node' do
116
136
  SpecNodeSub.resolve('/bar').should.be.nil
117
137
  end
118
138
 
119
- def assert_wish(url, body, content_type)
120
- got = get(url)
121
- got.body.strip.should == body
122
- got.headers['Content-Type'].should == content_type
123
- end
124
-
125
139
  should 'provide html if no wish given' do
126
140
  assert_wish('/provide/foo', '42', 'text/html')
127
141
  assert_wish('/provide/bar', '42', 'text/html')
@@ -143,7 +157,7 @@ describe 'Innate::Node' do
143
157
  assert_wish('/provide_template/bar.erb', "<h1>Hello, World!</h1>",
144
158
  'text/html')
145
159
 
146
- expected = (0..9).to_a.join
160
+ expected = '0123456789'
147
161
  assert_wish('/provide_template/foo.html', expected, 'text/html')
148
162
  # assert_wish('/provide_template/foo.erb', expected, 'text/plain')
149
163
  end
@@ -151,7 +165,7 @@ describe 'Innate::Node' do
151
165
  should 'respond with 404 if no action was found' do
152
166
  got = Innate::Mock.get('/does_not_exist')
153
167
  got.status.should == 404
154
- got.body.should == 'Action not found at: "/does_not_exist"'
168
+ got.body.should == 'No action found at: "/does_not_exist"'
155
169
  got['Content-Type'].should == 'text/plain'
156
170
  end
157
171
 
@@ -172,9 +186,27 @@ describe 'Innate::Node' do
172
186
  got['Content-Type'].should == 'text/html'
173
187
  end
174
188
 
189
+ should 'find layout with view_root' do
190
+ got = Innate::Mock.get('/another_layout/bar')
191
+ got.status.should == 200
192
+ got.body.should == %(<div class="content">\n 42\n</div>\n)
193
+ got['Content-Type'].should == 'text/html'
194
+ end
195
+
196
+ should 'find layout from method' do
197
+ got = Innate::Mock.get('/layout_method/bar')
198
+ got.status.should == 200
199
+ got.body.should == %(<div class="content">42</div>)
200
+ got['Content-Type'].should == 'text/html'
201
+ end
202
+
175
203
  should 'not get an action with wrong parameters' do
176
204
  got = Innate::Mock.get('/spec_index/bar')
177
205
  got.status.should == 404
178
- got.body.should == 'Action not found at: "/bar"'
206
+ got.body.should == 'No action found at: "/bar"'
207
+ end
208
+
209
+ should 'use alias_view' do
210
+ assert_wish('/alias_view/aliased', "<h1>Hello, World!</h1>", 'text/html')
179
211
  end
180
212
  end
@@ -0,0 +1,3 @@
1
+ <div class="content">
2
+ <%= @content %>
3
+ </div>
@@ -1,10 +1,4 @@
1
- require 'lib/innate/core_compatibility/basic_object'
2
- require 'lib/innate/options/dsl'
3
-
4
- require 'bacon'
5
-
6
- Bacon.extend(Bacon::TestUnitOutput)
7
- Bacon.summary_on_exit
1
+ require 'spec/helper'
8
2
 
9
3
  Options = Innate::Options
10
4
 
@@ -51,7 +45,8 @@ describe Options do
51
45
  end
52
46
 
53
47
  should 'get sub-sub option' do
54
- @options.get(:deep, :down, :me).should == {:value => :too, :doc => 'deep down'}
48
+ @options.get(:deep, :down, :me).
49
+ should == {:value => :too, :doc => 'deep down', :trigger=> nil}
55
50
  end
56
51
 
57
52
  should 'respond with nil on getting missing option' do
@@ -87,4 +82,12 @@ describe Options do
87
82
  @options.pretty_print(p)
88
83
  p.output.should =~ /:value=>4000/
89
84
  end
85
+
86
+ should 'trigger block when option is changed' do
87
+ set = nil
88
+ @options.trigger(:port){|value| set = value }
89
+ set.should.be.nil
90
+ @options.port = 300
91
+ set.should == 300
92
+ end
90
93
  end
data/spec/innate/route.rb CHANGED
@@ -126,4 +126,12 @@ describe Innate::Rewrite do
126
126
  got.status.should == 200
127
127
  got.body.should == 'this is bar'
128
128
  end
129
+
130
+ it 'should rewite with (key, val)' do
131
+ Innate::Rewrite[ %r!^/(.+)$! ] = nil
132
+ Innate::Rewrite(%r!^/(.+)$!, "/string/%s")
133
+ got = Innate::Mock.get('/hello')
134
+ got.status.should == 200
135
+ got.body.should == 'String: hello'
136
+ end
129
137
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec/helper'
2
2
 
3
- class SessionSpec
4
- include Innate::Node
5
- map '/'
6
- provide :html => :none
3
+ class SpecSession
4
+ Innate.node('/').provide(:html => :none)
7
5
 
8
6
  def index
9
7
  'No session here'
@@ -30,29 +28,27 @@ class SessionSpec
30
28
  end
31
29
  end
32
30
 
33
- Innate.options.cache.default = Innate::Cache::Memory
31
+ describe Innate::Session do
32
+ behaves_like :session
34
33
 
35
- Innate.setup_dependencies
36
-
37
- describe 'Innate::Session' do
38
34
  should 'initiate session as needed' do
39
- Innate::Mock.session do |session|
40
- response = session.get('/')
35
+ session do |mock|
36
+ response = mock.get('/')
41
37
  response.body.should == 'No session here'
42
38
  response['Set-Cookie'].should == nil
43
39
 
44
- session.get('/init').body.should == '0'
40
+ mock.get('/init').body.should == '0'
45
41
 
46
42
  1.upto(10) do |n|
47
- session.get('/increment').body.should == n.to_s
43
+ mock.get('/increment').body.should == n.to_s
48
44
  end
49
45
 
50
- session.get('/reset')
51
- session.get('/view').body.should == ''
52
- session.get('/init').body.should == '0'
46
+ mock.get('/reset')
47
+ mock.get('/view').body.should == ''
48
+ mock.get('/init').body.should == '0'
53
49
 
54
50
  -1.downto(-10) do |n|
55
- session.get('/decrement').body.should == n.to_s
51
+ mock.get('/decrement').body.should == n.to_s
56
52
  end
57
53
  end
58
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manveru-innate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2009.02.06
4
+ version: 2009.02.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael 'manveru' Fellinger
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-05 00:00:00 -08:00
12
+ date: 2009-02-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -100,6 +101,8 @@ files:
100
101
  - spec/example/hello.rb
101
102
  - spec/example/link.rb
102
103
  - spec/helper.rb
104
+ - spec/innate/action/layout.rb
105
+ - spec/innate/action/layout/file_layout.erb
103
106
  - spec/innate/cache/common.rb
104
107
  - spec/innate/cache/marshal.rb
105
108
  - spec/innate/cache/memory.rb
@@ -121,6 +124,7 @@ files:
121
124
  - spec/innate/helper/view/recursive.erb
122
125
  - spec/innate/mock.rb
123
126
  - spec/innate/node.rb
127
+ - spec/innate/node/another_layout/another_layout.erb
124
128
  - spec/innate/node/bar.html
125
129
  - spec/innate/node/foo.html.erb
126
130
  - spec/innate/node/with_layout.erb