sinatra-pages 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/sinatra/pages.rb +9 -1
  2. data/spec/pages_spec.rb +10 -1
  3. metadata +1 -1
data/lib/sinatra/pages.rb CHANGED
@@ -7,8 +7,16 @@ module Sinatra
7
7
  get route do
8
8
  params[:page] = 'home' if params[:page].nil?
9
9
 
10
- haml params[:page].to_sym
10
+ begin
11
+ haml params[:page].to_sym
12
+ rescue
13
+ halt 404
14
+ end
11
15
  end
12
16
  end
17
+
18
+ not_found do
19
+ haml :not_found
20
+ end
13
21
  end
14
22
  end
data/spec/pages_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Sinatra::Pages do
7
7
  Sinatra::Pages
8
8
  end
9
9
 
10
- PAGES = ['Home', 'Generic', 'Generic Test', 'Another Generic Test']
10
+ PAGES = ['Home', 'Generic', 'Generic Test', 'Another Generic Test', 'Not Found']
11
11
 
12
12
  file_of = ->(page){page.downcase.gsub ' ', '_'}
13
13
  create_file_for = ->(page){File.open("views/#{file_of.(page)}.haml", 'w'){|file| file << page}}
@@ -39,6 +39,15 @@ describe Sinatra::Pages do
39
39
  last_response.body.chomp.should == page
40
40
  end
41
41
  end
42
+
43
+ it "should render the Not Found page if the given route can't find its static page on the 'views' directory." do
44
+ File.exist?("views/#{file_of.('Do Not Exist')}.haml").should be_false
45
+
46
+ get "/#{file_of.('Do Not Exist')}"
47
+
48
+ last_response.should be_not_found
49
+ last_response.body.chomp.should == 'Not Found'
50
+ end
42
51
  end
43
52
 
44
53
  after :all do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Javier Cicchelli