vanilla 1.17.6 → 1.17.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -29,7 +29,7 @@ end
29
29
  if Object.const_defined?(:Gem)
30
30
 
31
31
  def files_for_inclusion
32
- base_files = %w(Rakefile README .gemtest) + Dir.glob("{test,lib,bin,pristine_app}/**/*")
32
+ base_files = %w(Rakefile README .gemtest) + Dir.glob("{test,lib,bin,pristine_app}/**/*").select { |f| File.file?(f) }
33
33
  files_to_ignore = File.readlines(".gitignore").inject([]) do |a,p|
34
34
  path = p.strip
35
35
  a += Dir.glob(path)
data/lib/vanilla/app.rb CHANGED
@@ -6,6 +6,7 @@ module Vanilla
6
6
  # be subclassed for each instance of Vanilla that you want to run.
7
7
  class App
8
8
  include Vanilla::Routing
9
+ class NotFound < RuntimeError; end
9
10
 
10
11
  class << self
11
12
  attr_reader :config
@@ -42,7 +43,11 @@ module Vanilla
42
43
 
43
44
  begin
44
45
  output = render_in_format(request.snip, request.part, request.format)
46
+ rescue NotFound => e
47
+ @response.status = 404
48
+ output = e.to_s
45
49
  rescue => e
50
+ raise e if config.raise_errors
46
51
  @response.status = 500
47
52
  output = e.to_s + e.backtrace.join("\n")
48
53
  end
@@ -116,6 +121,7 @@ module Vanilla
116
121
  renderer_instance = renderer_for(snip).new(self)
117
122
  yield renderer_instance
118
123
  rescue Exception => e
124
+ raise e if config.raise_errors
119
125
  response.status = 500
120
126
  snip_name = snip ? snip.name : nil
121
127
  "<pre>[Error rendering '#{snip_name}' - \"" +
@@ -124,6 +130,7 @@ module Vanilla
124
130
  end
125
131
 
126
132
  def render_in_format(snip, part=nil, format=nil)
133
+ format = nil unless snip
127
134
  case format
128
135
  when 'html', nil
129
136
  layout = layout_for(snip)
@@ -137,7 +144,7 @@ module Vanilla
137
144
  when 'text', 'atom', 'xml'
138
145
  render(snip, part)
139
146
  else
140
- raise "Unknown format '#{format}'"
147
+ raise NotFound, "Unknown format '#{format}'"
141
148
  end
142
149
  end
143
150
 
@@ -22,7 +22,8 @@ module Vanilla
22
22
  :soups,
23
23
  :renderers,
24
24
  :default_layout_snip,
25
- :default_renderer
25
+ :default_renderer,
26
+ :raise_errors
26
27
 
27
28
  def initialize
28
29
  @root = Dir.pwd
@@ -30,6 +31,7 @@ module Vanilla
30
31
  @soups = ["soups/base", "soups/system"]
31
32
  @default_layout_snip = "layout"
32
33
  @default_renderer = Vanilla::Renderers::Base
34
+ @raise_errors = false
33
35
  @renderers = {
34
36
  "base" => Vanilla::Renderers::Base,
35
37
  "markdown" => Vanilla::Renderers::Markdown,
@@ -95,7 +95,12 @@ module Vanilla
95
95
  end
96
96
 
97
97
  def render_without_including_snips(snip, part=:content)
98
- process_text(raw_content(snip, part))
98
+ if content = raw_content(snip, part)
99
+ process_text(content)
100
+ else
101
+ app.response.status = 404
102
+ %{Couldn't find part "#{part}" for snip "#{snip.name}"}
103
+ end
99
104
  end
100
105
 
101
106
  # Handles processing the text of the content.
data/lib/vanilla.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Vanilla
2
- VERSION = "1.17.6"
2
+ VERSION = "1.17.8"
3
3
 
4
4
  autoload :Renderers, "vanilla/renderers"
5
5
  autoload :App, "vanilla/app"
@@ -132,8 +132,8 @@ context "When presenting" do
132
132
  end
133
133
 
134
134
  context "requesting an unknown format" do
135
- should "return a 500 status code" do
136
- assert_response_status 500, "/test.monkey"
135
+ should "return a 404 status code" do
136
+ assert_response_status 404, "/test.monkey"
137
137
  end
138
138
  end
139
139
  end
@@ -43,4 +43,32 @@ context "The current_snip dynasnip" do
43
43
  assert_equal 404, page.status_code
44
44
  end
45
45
  end
46
+
47
+ context "when the requested snip with extension is missing" do
48
+ setup do
49
+ set_main_template "<layout>{current_snip}</layout>"
50
+ visit "/monkey.png"
51
+ end
52
+
53
+ should "set the response code to 404" do
54
+ assert_equal 404, page.status_code
55
+ end
56
+ end
57
+
58
+ context "when the requested part of a snip is missing" do
59
+ setup do
60
+ set_main_template "<layout>{current_snip}</layout>"
61
+ create_snip :name => "test", :content => "test"
62
+
63
+ visit "/test/monkey"
64
+ end
65
+
66
+ should "render an explanatory message" do
67
+ assert page.has_content?(%{Couldn't find part "monkey" for snip "test"})
68
+ end
69
+
70
+ should "set the response code to 404" do
71
+ assert_equal 404, page.status_code
72
+ end
73
+ end
46
74
  end
@@ -0,0 +1,67 @@
1
+ require "test_helper"
2
+
3
+ context "The rack app" do
4
+ should "handle exceptions by default" do
5
+ create_snip :name => "test", :content => "test"
6
+
7
+ app.stubs(:render_in_format).raises("exception-message")
8
+
9
+ assert_nothing_raised { visit "/test" }
10
+ assert_equal 500, page.status_code
11
+ end
12
+
13
+ should "handle exceptions when raise_errors is false" do
14
+ create_snip :name => "test", :content => "test"
15
+
16
+ app.stubs(:render_in_format).raises("exception-message")
17
+
18
+ with_raise_errors(false) do
19
+ assert_nothing_raised { visit "/test" }
20
+ assert_equal 500, page.status_code
21
+ end
22
+ end
23
+
24
+ should "raise exceptions when raise_errors is true" do
25
+ create_snip :name => "test", :content => "test"
26
+
27
+ app.stubs(:render_in_format).raises("exception-message")
28
+
29
+ with_raise_errors(true) do
30
+ assert_raises("exception-message") { visit "/test" }
31
+ end
32
+ end
33
+
34
+ should "handle missing renderer by default" do
35
+ create_snip :name => "test", :content => "test", :render_as => "unknown"
36
+
37
+ assert_nothing_raised { visit "/test" }
38
+ assert_equal 500, page.status_code
39
+ end
40
+
41
+ should "handle missing renderer when raise_errors is false" do
42
+ create_snip :name => "test", :content => "test", :render_as => "unknown"
43
+
44
+ with_raise_errors(false) do
45
+ assert_nothing_raised { visit "/test" }
46
+ assert_equal 500, page.status_code
47
+ end
48
+ end
49
+
50
+ should "raise exceptions when raise_errors is true" do
51
+ create_snip :name => "test", :content => "test", :render_as => "unknown"
52
+
53
+ with_raise_errors(true) do
54
+ assert_raises("exception-message") { visit "/test" }
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def with_raise_errors(raise_errors)
61
+ original_raise_errors = app.config.raise_errors
62
+ app.config.raise_errors = raise_errors
63
+ yield
64
+ ensure
65
+ app.config.raise_errors = original_raise_errors
66
+ end
67
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.6
4
+ version: 1.17.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-12-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -252,6 +252,7 @@ files:
252
252
  - test/pristine_app/link_to_current_snip_test.rb
253
253
  - test/pristine_app/link_to_test.rb
254
254
  - test/pristine_app/page_title_test.rb
255
+ - test/pristine_app/raise_errors_test.rb
255
256
  - test/pristine_app/raw_test.rb
256
257
  - test/pristine_app/site_test.rb
257
258
  - test/pristine_app/test_helper.rb
@@ -329,7 +330,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
330
  version: '0'
330
331
  segments:
331
332
  - 0
332
- hash: -2037710849477528713
333
+ hash: 2864118613837164250
333
334
  required_rubygems_version: !ruby/object:Gem::Requirement
334
335
  none: false
335
336
  requirements:
@@ -338,7 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
339
  version: '0'
339
340
  segments:
340
341
  - 0
341
- hash: -2037710849477528713
342
+ hash: 2864118613837164250
342
343
  requirements: []
343
344
  rubyforge_project: vanilla
344
345
  rubygems_version: 1.8.23