manveru-innate 2009.04 → 2009.04.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +0 -258
  2. data/MANIFEST +22 -23
  3. data/README.md +9 -1
  4. data/Rakefile +6 -6
  5. data/example/app/retro_games.rb +8 -8
  6. data/example/app/todo/layout/{default.xhtml → default.erb} +1 -1
  7. data/example/app/todo/view/{index.xhtml → index.erb} +11 -11
  8. data/example/app/whywiki_erb/start.rb +1 -2
  9. data/example/app/whywiki_erb/view/{edit.erb → edit.html.erb} +0 -0
  10. data/example/app/whywiki_erb/view/{index.erb → index.html.erb} +0 -0
  11. data/example/howto_spec.rb +1 -1
  12. data/example/provides.rb +6 -9
  13. data/example/session.rb +3 -3
  14. data/innate.gemspec +14 -6
  15. data/lib/innate.rb +18 -12
  16. data/lib/innate/action.rb +11 -22
  17. data/lib/innate/cache/file_based.rb +0 -2
  18. data/lib/innate/core_compatibility/basic_object.rb +10 -0
  19. data/lib/innate/core_compatibility/string.rb +3 -0
  20. data/lib/innate/dynamap.rb +0 -5
  21. data/lib/innate/helper.rb +29 -20
  22. data/lib/innate/helper/cgi.rb +19 -32
  23. data/lib/innate/helper/link.rb +2 -2
  24. data/lib/innate/helper/partial.rb +93 -0
  25. data/lib/innate/helper/redirect.rb +1 -1
  26. data/lib/innate/helper/send_file.rb +1 -9
  27. data/lib/innate/mock.rb +3 -2
  28. data/lib/innate/node.rb +51 -78
  29. data/lib/innate/options.rb +1 -1
  30. data/lib/innate/request.rb +23 -3
  31. data/lib/innate/response.rb +7 -0
  32. data/lib/innate/session.rb +2 -1
  33. data/lib/innate/spec.rb +50 -6
  34. data/lib/innate/version.rb +1 -1
  35. data/lib/innate/view/erb.rb +1 -1
  36. data/lib/innate/view/etanni.rb +2 -2
  37. data/lib/innate/view/none.rb +1 -1
  38. data/spec/example/session.rb +14 -8
  39. data/spec/innate/action/layout.rb +1 -1
  40. data/spec/innate/action/layout/file_layout.erb +1 -0
  41. data/spec/innate/helper/aspect.rb +6 -6
  42. data/spec/innate/helper/flash.rb +47 -28
  43. data/spec/innate/helper/link.rb +0 -8
  44. data/spec/innate/helper/partial.rb +101 -0
  45. data/spec/innate/helper/redirect.rb +43 -58
  46. data/spec/innate/helper/view/aspect_hello.erb +1 -0
  47. data/spec/innate/helper/view/locals.erb +1 -0
  48. data/spec/innate/helper/view/loop.erb +4 -0
  49. data/spec/innate/helper/view/num.erb +1 -0
  50. data/spec/innate/helper/view/partial.erb +1 -0
  51. data/spec/innate/helper/view/recursive.erb +8 -0
  52. data/spec/innate/node/node.rb +13 -5
  53. data/spec/innate/node/view/another_layout/{another_layout.xhtml → another_layout.erb} +1 -1
  54. data/spec/innate/node/view/{bar.xhtml → bar.erb} +0 -0
  55. data/spec/innate/node/view/foo.html.erb +1 -0
  56. data/spec/innate/node/view/{only_view.xhtml → only_view.erb} +0 -0
  57. data/spec/innate/node/view/with_layout.erb +1 -0
  58. data/spec/innate/provides.rb +2 -2
  59. data/spec/innate/provides/list.html.erb +1 -0
  60. data/spec/innate/provides/list.txt.erb +1 -0
  61. data/spec/innate/session.rb +15 -14
  62. data/spec/innate/state/fiber.rb +7 -8
  63. data/tasks/bacon.rake +21 -38
  64. data/tasks/install_dependencies.rake +4 -2
  65. data/tasks/release.rake +9 -48
  66. metadata +57 -29
  67. data/lib/innate/helper/render.rb +0 -87
  68. data/spec/example/app/retro_games.rb +0 -30
  69. data/spec/example/provides.rb +0 -16
  70. data/spec/innate/action/layout/file_layout.xhtml +0 -1
  71. data/spec/innate/helper/render.rb +0 -133
  72. data/spec/innate/helper/view/aspect_hello.xhtml +0 -1
  73. data/spec/innate/helper/view/locals.xhtml +0 -1
  74. data/spec/innate/helper/view/loop.xhtml +0 -4
  75. data/spec/innate/helper/view/num.xhtml +0 -1
  76. data/spec/innate/helper/view/partial.xhtml +0 -1
  77. data/spec/innate/helper/view/recursive.xhtml +0 -7
  78. data/spec/innate/node/view/foo.html.xhtml +0 -1
  79. data/spec/innate/node/view/with_layout.xhtml +0 -1
  80. data/spec/innate/provides/list.html.xhtml +0 -1
  81. data/spec/innate/provides/list.txt.xhtml +0 -1
  82. data/tasks/setup.rake +0 -28
@@ -20,7 +20,7 @@ class SpecRedirectHelper
20
20
  end
21
21
 
22
22
  def redirect_referer_action
23
- redirect_referer(r(:noop))
23
+ redirect_referer
24
24
  end
25
25
 
26
26
  def no_actual_redirect
@@ -69,92 +69,77 @@ describe Innate::Helper::Redirect do
69
69
  end
70
70
 
71
71
  should 'redirect' do
72
- get("#@uri/redirection")
73
-
74
- last_response.status.should == 302
75
- last_response.headers['Location'].should == "#@uri/index"
76
- last_response.headers['Content-Type'].should == "text/html"
72
+ got = get("#@uri/redirection")
73
+ got.status.should == 302
74
+ got.headers['Location'].should == "#@uri/index"
75
+ got.headers['Content-Type'].should == "text/html"
77
76
  end
78
77
 
79
78
  should 'redirect twice' do
80
- get("#@uri/double_redirection")
81
-
82
- last_response.status.should == 302
83
- last_response.headers['Location'].should == "#@uri/redirection"
84
- last_response.headers['Content-Type'].should == "text/html"
79
+ got = get("#@uri/double_redirection")
80
+ got.status.should == 302
81
+ got.headers['Location'].should == "#@uri/redirection"
82
+ got.headers['Content-Type'].should == "text/html"
85
83
  end
86
84
 
87
85
  should 'redirect to referer' do
88
- header 'HTTP_REFERER', '/index'
89
- get("#@uri/redirect_referer_action")
90
-
91
- last_response.status.should == 302
92
- last_response.headers['Location'].should == "#@uri/index"
93
- last_response.headers['Content-Type'].should == "text/html"
94
- end
95
-
96
- should 'redirect to fallback if referrer is identical' do
97
- header 'HTTP_REFERER', "#@uri/redirect_referer_action"
98
- get("#@uri/redirect_referer_action")
99
-
100
- last_response.status.should == 302
101
- last_response.headers['Location'].should == "#@uri/noop"
102
- last_response.headers['Content-Type'].should == "text/html"
86
+ got = get("#@uri/redirect_referer_action", 'HTTP_REFERER' => '/noop')
87
+ got.status.should == 302
88
+ got.headers['Location'].should == "#@uri/noop"
89
+ got.headers['Content-Type'].should == "text/html"
90
+ got = get("#@uri/redirect_referer_action", 'HTTP_REFERER' => "#@uri/redirect_referer_action")
91
+ got.status.should == 302
92
+ got.headers['Location'].should == "#@uri/"
93
+ got.headers['Content-Type'].should == "text/html"
103
94
  end
104
95
 
105
96
  should 'use #r' do
106
- get("#@uri/redirect_method")
107
-
108
- last_response.status.should == 302
109
- last_response.headers['Location'].should == "#@uri/noop"
110
- last_response.headers['Content-Type'].should == "text/html"
97
+ got = get("#@uri/redirect_method")
98
+ got.status.should == 302
99
+ got.headers['Location'].should == "#@uri/noop"
100
+ got.headers['Content-Type'].should == "text/html"
111
101
  end
112
102
 
113
103
  should 'work with absolute uris' do
114
- get("#@uri/absolute_redirect")
115
-
116
- last_response.status.should == 302
117
- last_response.headers['Location'].should == "#@uri/noop"
118
- last_response.headers['Content-Type'].should == "text/html"
104
+ got = get("#@uri/absolute_redirect")
105
+ got.status.should == 302
106
+ got.headers['Location'].should == "#@uri/noop"
107
+ got.headers['Content-Type'].should == "text/html"
119
108
  end
120
109
 
121
110
  should 'support #respond' do
122
- get("#@uri/loop")
123
-
124
- last_response.status.should == 200
125
- last_response.body.should == 'no loop'
111
+ got = get("#@uri/loop")
112
+ got.status.should == 200
113
+ got.body.should == 'no loop'
126
114
  end
127
115
 
128
116
  should 'support #respond with status' do
129
- get("#@uri/respond_with_status")
130
-
131
- last_response.status.should == 404
132
- last_response.body.should == 'not found'
117
+ got = get("#@uri/respond_with_status")
118
+ got.status.should == 404
119
+ got.body.should == 'not found'
133
120
  end
134
121
 
135
122
  should 'support #respond!' do
136
- get("#@uri/destructive_respond")
137
-
138
- last_response.status.should == 200
139
- last_response.body.should == 'destructive'
123
+ got = get("#@uri/destructive_respond")
124
+ got.status.should == 200
125
+ got.body.should == 'destructive'
140
126
  end
141
127
 
142
128
  should 'redirect without modifying the target' do
143
- get("#@uri/redirect_unmodified")
144
-
145
- last_response.status.should == 302
146
- last_response.headers['Location'].should == '/noop'
129
+ got = get("#@uri/redirect_unmodified")
130
+ got.status.should == 302
131
+ got.headers['Location'].should == '/noop'
147
132
  end
148
133
 
149
134
  should 'catch redirection' do
150
- get("#@uri/no_actual_redirect")
151
- last_response.status.should == 200
152
- last_response.body.should == 'no actual redirect'
135
+ got = get("#@uri/no_actual_redirect")
136
+ got.status.should == 200
137
+ got.body.should == 'no actual redirect'
153
138
  end
154
139
 
155
140
  should 'catch double redirect' do
156
- get("#@uri/no_actual_double_redirect")
157
- last_response.status.should == 200
158
- last_response.body.should == 'no actual double redirect'
141
+ got = get("#@uri/no_actual_double_redirect")
142
+ got.status.should == 200
143
+ got.body.should == 'no actual double redirect'
159
144
  end
160
145
  end
@@ -0,0 +1 @@
1
+ <%= @foo %> <%= @bar %>!
@@ -0,0 +1 @@
1
+ <%= say %>, <%= to %>!
@@ -0,0 +1,4 @@
1
+ <% (1..5).each do |n| %>
2
+ <% @n = n %>
3
+ <%= render_template('num') %>
4
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= @n %>
@@ -0,0 +1 @@
1
+ From Partial <%= @here %>
@@ -0,0 +1,8 @@
1
+ {
2
+ <%= @n %>
3
+ <% if @n < 4 %>
4
+ <% @n += 1 %>
5
+ <%= render_template('recursive') %>
6
+ <% end %>
7
+ <%= @n %>
8
+ }
@@ -4,6 +4,8 @@ Innate.options.merge!(:views => 'view', :layouts => 'view')
4
4
 
5
5
  class SpecNode
6
6
  Innate.node('/')
7
+ provide(:html, :ERB)
8
+ provide(:erb, :None)
7
9
 
8
10
  def foo; end
9
11
  def bar; end
@@ -16,18 +18,24 @@ end
16
18
  class SpecNodeProvide
17
19
  Innate.node('/provide')
18
20
 
21
+ provide(:html, :ERB)
22
+ provide(:erb, :None)
23
+
19
24
  def foo
20
- '#{21 * 2}'
25
+ '<%= 21 * 2 %>'
21
26
  end
22
27
 
23
28
  def bar
24
- '#{84 / 2}'
29
+ '<%= 84 / 2 %>'
25
30
  end
26
31
  end
27
32
 
28
33
  class SpecNodeProvideTemplate
29
34
  Innate.node('/provide_template')
30
35
 
36
+ provide :html, :ERB
37
+ provide :erb, :None
38
+
31
39
  map_views '/'
32
40
  end
33
41
 
@@ -56,7 +64,7 @@ class SpecNodeWithLayoutMethod < SpecNodeProvide
56
64
  layout 'layout_method'
57
65
 
58
66
  def layout_method
59
- '<div class="content">#{@content}</div>'
67
+ '<div class="content"><%= @content %></div>'
60
68
  end
61
69
  end
62
70
 
@@ -88,14 +96,14 @@ describe 'Innate::Node' do
88
96
  should 'wrap with layout' do
89
97
  got = Innate::Mock.get('/layout/bar')
90
98
  got.status.should == 200
91
- got.body.should == %(<div class="content">42</div>)
99
+ got.body.should == %(<div class="content">42</div>\n)
92
100
  got['Content-Type'].should == 'text/html'
93
101
  end
94
102
 
95
103
  should 'find layout with view_root' do
96
104
  got = Innate::Mock.get('/another_layout/bar')
97
105
  got.status.should == 200
98
- got.body.should == %(<div class="content">\n 42\n</div>)
106
+ got.body.should == %(<div class="content">\n 42\n</div>\n)
99
107
  got['Content-Type'].should == 'text/html'
100
108
  end
101
109
 
@@ -1,3 +1,3 @@
1
1
  <div class="content">
2
- #{@content}
2
+ <%= @content %>
3
3
  </div>
@@ -0,0 +1 @@
1
+ <% 10.times do |n| %><%= n %><% end %>
@@ -0,0 +1 @@
1
+ <div class="content"><%= @content %></div>
@@ -12,7 +12,7 @@ Innate.options.merge!(:views => 'provides', :layouts => 'provides')
12
12
  class SpecNodeProvides
13
13
  Innate.node '/'
14
14
 
15
- provide(:html, :engine => :None)
15
+ provide(:html, :None)
16
16
  provide(:yaml, :type => 'text/yaml'){|a,s| s.to_yaml }
17
17
  provide(:json, :type => 'application/json'){|a,s| s.to_json }
18
18
 
@@ -31,7 +31,7 @@ class SpecNodeProvidesTemplates
31
31
 
32
32
  provide(:yaml, :type => 'text/yaml'){|a,s| s.to_yaml }
33
33
  provide(:json, :type => 'application/json'){|a,s| s.to_json }
34
- provide(:txt, :engine => :Etanni, :type => 'text/plain')
34
+ provide(:txt, :engine => :ERB, :type => 'text/plain')
35
35
 
36
36
  def list
37
37
  @users = %w[starbucks apollo athena]
@@ -0,0 +1 @@
1
+ <ul><% @users.each do |user| %><li><%= user %></li><% end %></ul>
@@ -0,0 +1 @@
1
+ <% @users.each do |user| %><%= "#{user}\n" %><% end %>
@@ -29,26 +29,27 @@ class SpecSession
29
29
  end
30
30
 
31
31
  describe Innate::Session do
32
- behaves_like :mock
32
+ behaves_like :session
33
33
 
34
34
  should 'initiate session as needed' do
35
- get '/'
36
- last_response.body.should == 'No session here'
37
- last_response['Set-Cookie'].should == nil
35
+ session do |mock|
36
+ response = mock.get('/')
37
+ response.body.should == 'No session here'
38
+ response['Set-Cookie'].should == nil
38
39
 
39
- get('/init')
40
- last_response.body.should == '0'
40
+ mock.get('/init').body.should == '0'
41
41
 
42
- 1.upto(10) do |n|
43
- get('/increment').body.should == n.to_s
44
- end
42
+ 1.upto(10) do |n|
43
+ mock.get('/increment').body.should == n.to_s
44
+ end
45
45
 
46
- get('/reset')
47
- get('/view').body.should == ''
48
- get('/init').body.should == '0'
46
+ mock.get('/reset')
47
+ mock.get('/view').body.should == ''
48
+ mock.get('/init').body.should == '0'
49
49
 
50
- -1.downto(-10) do |n|
51
- get('/decrement').body.should == n.to_s
50
+ -1.downto(-10) do |n|
51
+ mock.get('/decrement').body.should == n.to_s
52
+ end
52
53
  end
53
54
  end
54
55
  end
@@ -1,13 +1,12 @@
1
- require 'spec/helper'
1
+ begin
2
+ require 'fiber'
3
+ rescue LoadError
4
+ exit
5
+ end
2
6
 
3
- describe 'Innate::State::Fiber' do
4
- begin
5
- require 'fiber'
6
- rescue LoadError
7
- it('needs fiber'){ should.flunk('needed fiber') }
8
- exit
9
- end
7
+ require 'spec/helper'
10
8
 
9
+ describe Innate::State::Fiber do
11
10
  F = Innate::State::Fiber
12
11
 
13
12
  it 'sets value in current thread with #[]=' do
@@ -2,65 +2,48 @@ desc 'Run all bacon specs with pretty output'
2
2
  task :bacon => :install_dependencies do
3
3
  require 'open3'
4
4
  require 'scanf'
5
- require 'matrix'
6
5
 
7
6
  specs = PROJECT_SPECS
8
7
 
9
8
  some_failed = false
10
- specs_size = specs.size
9
+ total = specs.size
11
10
  len = specs.map{|s| s.size }.sort.last
12
- total_tests = total_assertions = total_failures = total_errors = 0
13
- totals = Vector[0, 0, 0, 0]
11
+ tt = ta = tf = te = 0
14
12
 
15
13
  red, yellow, green = "\e[31m%s\e[0m", "\e[33m%s\e[0m", "\e[32m%s\e[0m"
16
14
  left_format = "%4d/%d: %-#{len + 11}s"
17
15
  spec_format = "%d specifications (%d requirements), %d failures, %d errors"
18
16
 
19
17
  specs.each_with_index do |spec, idx|
20
- print(left_format % [idx + 1, specs_size, spec])
18
+ print(left_format % [idx + 1, total, spec])
21
19
 
22
20
  Open3.popen3(RUBY, spec) do |sin, sout, serr|
23
- out = sout.read.strip
24
- err = serr.read.strip
21
+ out = sout.read
22
+ err = serr.read
25
23
 
26
- # this is conventional, see spec/innate/state/fiber.rb for usage
27
- if out =~ /^Bacon::Error: (needed .*)/
28
- puts(yellow % ("%6s %s" % ['', $1]))
29
- else
30
- total = nil
24
+ ran = false
31
25
 
32
- out.each_line do |line|
33
- scanned = line.scanf(spec_format)
26
+ out.each_line do |line|
27
+ tests, assertions, failures, errors = all = line.scanf(spec_format)
28
+ next unless all.any?
29
+ ran = true
30
+ tt += tests; ta += assertions; tf += failures; te += errors
34
31
 
35
- next unless scanned.size == 4
36
-
37
- total = Vector[*scanned]
38
- break
39
- end
40
-
41
- if total
42
- totals += total
43
- tests, assertions, failures, errors = total_array = total.to_a
44
-
45
- if tests > 0 && failures + errors == 0
46
- puts((green % "%6d passed") % tests)
47
- else
48
- some_failed = true
49
- puts(red % " failed")
50
- puts out unless out.empty?
51
- puts err unless err.empty?
52
- end
32
+ if tests == 0 || failures + errors > 0
33
+ puts((red % spec_format) % all)
34
+ puts out
35
+ puts err
53
36
  else
54
- some_failed = true
55
- puts(red % " failed")
56
- puts out unless out.empty?
57
- puts err unless err.empty?
37
+ puts((green % "%6d passed") % tests)
58
38
  end
39
+
40
+ break
59
41
  end
42
+
43
+ puts(yellow % " skipped") unless ran
60
44
  end
61
45
  end
62
46
 
63
- total_color = some_failed ? red : green
64
- puts(total_color % (spec_format % totals.to_a))
47
+ puts(spec_format % [tt, ta, tf, te])
65
48
  exit 1 if some_failed
66
49
  end
@@ -1,4 +1,6 @@
1
- desc 'install dependencies from gemspec'
1
+ desc 'install dependencies'
2
2
  task :install_dependencies => [:gem_installer] do
3
- GemInstaller.new{ setup_gemspec(GEMSPEC) }
3
+ GemInstaller.new do
4
+ setup_gemspec(GEMSPEC)
5
+ end
4
6
  end
@@ -1,51 +1,12 @@
1
- namespace :release do
2
- task :all => [:release_github, :release_rubyforge]
1
+ desc 'publish to github'
2
+ task :release => [:reversion, :gemspec] do
3
+ name, version = GEMSPEC.name, GEMSPEC.version
3
4
 
4
- desc 'Display instructions to release on github'
5
- task :github => [:reversion, :gemspec] do
6
- name, version = GEMSPEC.name, GEMSPEC.version
5
+ sh("git add MANIFEST CHANGELOG #{name}.gemspec lib/#{name}/version.rb")
7
6
 
8
- puts <<INSTRUCTIONS
9
- First add the relevant files:
10
-
11
- git add MANIFEST CHANGELOG #{name}.gemspec lib/#{name}/version.rb
12
-
13
- Then commit them, tag the commit, and push:
14
-
15
- git commit -m 'Version #{version}'
16
- git tag -a -m '#{version}' '#{version}'
17
- git push
18
-
19
- INSTRUCTIONS
20
-
21
- end
22
-
23
- # TODO: Not tested
24
- desc 'Display instructions to release on rubyforge'
25
- task :rubyforge => [:reversion, :gemspec, :package] do
26
- name, version = GEMSPEC.name, GEMSPEC.version
27
-
28
- puts <<INSTRUCTIONS
29
- To publish to rubyforge do following:
30
-
31
- rubyforge login
32
- rubyforge add_release #{name} '#{version}' pkg/#{name}-#{version}.gem
33
-
34
- After you have done these steps, see:
35
-
36
- rake release:rubyforge_archives
37
-
38
- INSTRUCTIONS
39
- end
40
-
41
- desc 'Display instructions to add archives after release:rubyforge'
42
- task :rubyforge_archives do
43
- puts "Adding archives for distro packagers is:", ""
44
-
45
- Dir["pkg/#{name}-#{version}.{gz,zip}"].each do |file|
46
- puts "rubyforge add_file #{name} #{name} '#{version}' '#{file}'"
47
- end
48
-
49
- puts
50
- end
7
+ puts "I added the relevant files, you can now run:", ''
8
+ puts "git commit -m 'Version #{version}'"
9
+ puts "git tag -a -m '#{version}' '#{version}'"
10
+ puts "git push"
11
+ puts
51
12
  end