high_voltage 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +26 -5
- data/Appraisals +1 -8
- data/Gemfile +0 -3
- data/Gemfile.lock +78 -58
- data/MIT-LICENSE +1 -1
- data/NEWS.md +9 -0
- data/README.md +11 -7
- data/app/controllers/concerns/high_voltage/static_page.rb +4 -1
- data/gemfiles/rails4.2.gemfile +0 -2
- data/gemfiles/{rails4.0.gemfile → rails5.0.gemfile} +1 -3
- data/gemfiles/{rails4.1.gemfile → rails5.1.gemfile} +1 -3
- data/gemfiles/rails5.2.gemfile +7 -0
- data/high_voltage.gemspec +6 -2
- data/lib/high_voltage/constraints/root_route.rb +17 -16
- data/lib/high_voltage/page.rb +11 -7
- data/lib/high_voltage/page_finder.rb +7 -24
- data/lib/high_voltage/route_drawers/root.rb +1 -1
- data/lib/high_voltage/version.rb +1 -1
- data/spec/constraints/root_route_spec.rb +17 -24
- data/spec/controllers/alternative_finder_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +4 -4
- data/spec/controllers/subclassed_pages_controller_spec.rb +15 -15
- data/spec/fake_app.rb +1 -0
- data/spec/features/current_page_helper_spec.rb +9 -0
- data/spec/features/view_page_spec.rb +9 -0
- data/spec/fixtures/app/views/pages/about.html.erb +1 -0
- data/spec/fixtures/app/views/pages/current_page_helper.html.erb +1 -0
- data/spec/fixtures/app/views/pages/exists_without_html_extension.erb +1 -0
- data/spec/high_voltage/page_collector_spec.rb +6 -2
- data/spec/high_voltage/page_finder_spec.rb +34 -13
- data/spec/high_voltage/page_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -2
- data/spec/support/http_method_shim.rb +6 -2
- metadata +72 -6
- data/gemfiles/rails50.gemfile +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 223b265a8f841aac5236e6a7f2e635785d1799c9
|
4
|
+
data.tar.gz: f38250b134ab9303a6c0b4b0b577b1a87a1fa629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0543bae3871a0087e610c70417c4c98158c265d9a9972336f990c7d30c2f1375ccf0cede3c068e57feee604985ce3c837e4948dedf35543f5cb4c454b3af0c2f
|
7
|
+
data.tar.gz: 44ee90083858b224de20a07b8e971a02a40aaa1018896679700eb90ed16c19eb10fbf0503d576c8de524b36e08c95054676e6ce32a870892baceda703625c62b
|
data/.travis.yml
CHANGED
@@ -1,16 +1,37 @@
|
|
1
|
+
branches:
|
2
|
+
only:
|
3
|
+
- "master"
|
1
4
|
gemfile:
|
2
|
-
- gemfiles/rails4.0.gemfile
|
3
|
-
- gemfiles/rails4.1.gemfile
|
4
5
|
- gemfiles/rails4.2.gemfile
|
6
|
+
- gemfiles/rails5.0.gemfile
|
7
|
+
- gemfiles/rails5.1.gemfile
|
8
|
+
- gemfiles/rails5.2.gemfile
|
5
9
|
install:
|
6
10
|
- 'travis_retry bundle install'
|
7
11
|
language:
|
8
12
|
- ruby
|
9
13
|
rvm:
|
10
14
|
- 2.0.0-p648
|
11
|
-
- 2.1.
|
12
|
-
- 2.2.
|
13
|
-
- 2.3.
|
15
|
+
- 2.1.10
|
16
|
+
- 2.2.9
|
17
|
+
- 2.3.6
|
18
|
+
- 2.4.3
|
19
|
+
- 2.5.0
|
20
|
+
matrix:
|
21
|
+
exclude:
|
22
|
+
- rvm: 2.0.0-p648
|
23
|
+
gemfile: gemfiles/rails5.0.gemfile
|
24
|
+
- rvm: 2.0.0-p648
|
25
|
+
gemfile: gemfiles/rails5.1.gemfile
|
26
|
+
- rvm: 2.0.0-p648
|
27
|
+
gemfile: gemfiles/rails5.2.gemfile
|
28
|
+
- rvm: 2.1.10
|
29
|
+
gemfile: gemfiles/rails5.0.gemfile
|
30
|
+
- rvm: 2.1.10
|
31
|
+
gemfile: gemfiles/rails5.1.gemfile
|
32
|
+
- rvm: 2.1.10
|
33
|
+
gemfile: gemfiles/rails5.2.gemfile
|
34
|
+
|
14
35
|
script: 'bundle exec rake spec'
|
15
36
|
notifications:
|
16
37
|
email: false
|
data/Appraisals
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
rails_versions = ['~> 4.0.0', '~>
|
2
|
-
|
1
|
+
rails_versions = ['~> 4.2.0', '~> 5.0.0', '~> 5.1.0', '~> 5.2.0']
|
3
2
|
rails_versions.each do |rails_version|
|
4
3
|
appraise "rails#{rails_version.slice(/\d+\.\d+/)}" do
|
5
4
|
gem 'rails', rails_version
|
6
5
|
end
|
7
6
|
end
|
8
|
-
|
9
|
-
appraise "rails50" do
|
10
|
-
gem "rails", "~> 5.0.0.beta3"
|
11
|
-
gem "rspec-rails", "3.5.0.beta1"
|
12
|
-
gem "rails-controller-testing"
|
13
|
-
end
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,90 +1,108 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
high_voltage (3.
|
4
|
+
high_voltage (3.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actionpack (
|
10
|
-
actionview (=
|
11
|
-
activesupport (=
|
12
|
-
rack (~>
|
13
|
-
rack-test (~> 0.6.
|
14
|
-
rails-dom-testing (~>
|
9
|
+
actionpack (5.1.1)
|
10
|
+
actionview (= 5.1.1)
|
11
|
+
activesupport (= 5.1.1)
|
12
|
+
rack (~> 2.0)
|
13
|
+
rack-test (~> 0.6.3)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
15
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
16
|
-
actionview (
|
17
|
-
activesupport (=
|
16
|
+
actionview (5.1.1)
|
17
|
+
activesupport (= 5.1.1)
|
18
18
|
builder (~> 3.1)
|
19
|
-
|
20
|
-
rails-dom-testing (~>
|
21
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
22
|
-
activesupport (
|
19
|
+
erubi (~> 1.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
22
|
+
activesupport (5.1.1)
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
24
|
i18n (~> 0.7)
|
24
|
-
json (~> 1.7, >= 1.7.7)
|
25
25
|
minitest (~> 5.1)
|
26
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
27
26
|
tzinfo (~> 1.1)
|
27
|
+
addressable (2.5.1)
|
28
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
28
29
|
appraisal (1.0.2)
|
29
30
|
bundler
|
30
31
|
rake
|
31
32
|
thor (>= 0.14.0)
|
32
|
-
builder (3.2.
|
33
|
+
builder (3.2.3)
|
34
|
+
capybara (2.14.3)
|
35
|
+
addressable
|
36
|
+
mime-types (>= 1.16)
|
37
|
+
nokogiri (>= 1.3.3)
|
38
|
+
rack (>= 1.0.0)
|
39
|
+
rack-test (>= 0.5.4)
|
40
|
+
xpath (~> 2.0)
|
33
41
|
coderay (1.1.0)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
concurrent-ruby (1.0.5)
|
43
|
+
crass (1.0.4)
|
44
|
+
diff-lcs (1.3)
|
45
|
+
erubi (1.6.0)
|
46
|
+
i18n (0.8.4)
|
47
|
+
loofah (2.2.2)
|
48
|
+
crass (~> 1.0.2)
|
39
49
|
nokogiri (>= 1.5.9)
|
40
50
|
method_source (0.8.2)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
mime-types (3.1)
|
52
|
+
mime-types-data (~> 3.2015)
|
53
|
+
mime-types-data (3.2016.0521)
|
54
|
+
mini_portile2 (2.3.0)
|
55
|
+
minitest (5.10.2)
|
56
|
+
nokogiri (1.8.2)
|
57
|
+
mini_portile2 (~> 2.3.0)
|
45
58
|
pry (0.10.1)
|
46
59
|
coderay (~> 1.1.0)
|
47
60
|
method_source (~> 0.8.1)
|
48
61
|
slop (~> 3.4)
|
49
|
-
|
62
|
+
public_suffix (2.0.5)
|
63
|
+
rack (2.0.3)
|
50
64
|
rack-test (0.6.3)
|
51
65
|
rack (>= 1.0)
|
52
|
-
rails-
|
53
|
-
|
54
|
-
|
55
|
-
activesupport (
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
rails-controller-testing (1.0.2)
|
67
|
+
actionpack (~> 5.x, >= 5.0.1)
|
68
|
+
actionview (~> 5.x, >= 5.0.1)
|
69
|
+
activesupport (~> 5.x)
|
70
|
+
rails-dom-testing (2.0.3)
|
71
|
+
activesupport (>= 4.2.0)
|
72
|
+
nokogiri (>= 1.6)
|
73
|
+
rails-html-sanitizer (1.0.4)
|
74
|
+
loofah (~> 2.2, >= 2.2.2)
|
75
|
+
railties (5.1.1)
|
76
|
+
actionpack (= 5.1.1)
|
77
|
+
activesupport (= 5.1.1)
|
78
|
+
method_source
|
63
79
|
rake (>= 0.8.7)
|
64
80
|
thor (>= 0.18.1, < 2.0)
|
65
|
-
rake (
|
66
|
-
rspec-core (3.
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-expectations (3.
|
81
|
+
rake (12.0.0)
|
82
|
+
rspec-core (3.6.0)
|
83
|
+
rspec-support (~> 3.6.0)
|
84
|
+
rspec-expectations (3.6.0)
|
69
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
70
|
-
rspec-support (~> 3.
|
71
|
-
rspec-mocks (3.
|
86
|
+
rspec-support (~> 3.6.0)
|
87
|
+
rspec-mocks (3.6.0)
|
72
88
|
diff-lcs (>= 1.2.0, < 2.0)
|
73
|
-
rspec-support (~> 3.
|
74
|
-
rspec-rails (3.
|
75
|
-
actionpack (>= 3.0
|
76
|
-
activesupport (>= 3.0
|
77
|
-
railties (>= 3.0
|
78
|
-
rspec-core (~> 3.
|
79
|
-
rspec-expectations (~> 3.
|
80
|
-
rspec-mocks (~> 3.
|
81
|
-
rspec-support (~> 3.
|
82
|
-
rspec-support (3.
|
89
|
+
rspec-support (~> 3.6.0)
|
90
|
+
rspec-rails (3.6.0)
|
91
|
+
actionpack (>= 3.0)
|
92
|
+
activesupport (>= 3.0)
|
93
|
+
railties (>= 3.0)
|
94
|
+
rspec-core (~> 3.6.0)
|
95
|
+
rspec-expectations (~> 3.6.0)
|
96
|
+
rspec-mocks (~> 3.6.0)
|
97
|
+
rspec-support (~> 3.6.0)
|
98
|
+
rspec-support (3.6.0)
|
83
99
|
slop (3.6.0)
|
84
|
-
thor (0.19.
|
85
|
-
thread_safe (0.3.
|
86
|
-
tzinfo (1.2.
|
100
|
+
thor (0.19.4)
|
101
|
+
thread_safe (0.3.6)
|
102
|
+
tzinfo (1.2.3)
|
87
103
|
thread_safe (~> 0.1)
|
104
|
+
xpath (2.1.0)
|
105
|
+
nokogiri (~> 1.3)
|
88
106
|
|
89
107
|
PLATFORMS
|
90
108
|
ruby
|
@@ -92,9 +110,11 @@ PLATFORMS
|
|
92
110
|
DEPENDENCIES
|
93
111
|
activesupport (>= 3.1.0)
|
94
112
|
appraisal
|
113
|
+
capybara
|
95
114
|
high_voltage!
|
96
115
|
pry
|
97
|
-
|
116
|
+
rails-controller-testing
|
117
|
+
rspec-rails (~> 3.5)
|
98
118
|
|
99
119
|
BUNDLED WITH
|
100
|
-
1.
|
120
|
+
1.16.1
|
data/MIT-LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
New for 3.1.0
|
2
|
+
+ Fix bugs around finding pages via page_ids's that contain non-ASCII characters
|
3
|
+
+ Trailing slash is no longer required for finding pages
|
4
|
+
+ Some other improvements around page lookups
|
5
|
+
+ Don't require format in extension for looking up page id's HAML and Slim do
|
6
|
+
not require them.
|
7
|
+
+ Test against Rails 5, 5.1, 5.2
|
8
|
+
+ Test against Ruby 2.4, 2.5
|
9
|
+
|
1
10
|
New for 3.0.0
|
2
11
|
+ HighVoltage now supports Rails 5.0.0.beta3 and up.
|
3
12
|
+ Properly handle extensions in root route constraint requests.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# High Voltage [![Build Status](https://travis-ci.org/thoughtbot/high_voltage.
|
1
|
+
# High Voltage [![Build Status](https://travis-ci.org/thoughtbot/high_voltage.svg?branch=master)](https://travis-ci.org/thoughtbot/high_voltage)
|
2
2
|
|
3
3
|
Rails engine for static pages.
|
4
4
|
|
@@ -10,12 +10,16 @@ Yeah, like "About us", "Directions", marketing pages, etc.
|
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
13
|
+
There are two ways to install High Voltage.
|
14
|
+
|
15
|
+
You can run:
|
16
|
+
|
13
17
|
$ gem install high_voltage
|
14
18
|
|
15
|
-
|
19
|
+
Or you can include in your Gemfile:
|
16
20
|
|
17
21
|
```ruby
|
18
|
-
gem 'high_voltage', '~> 3.
|
22
|
+
gem 'high_voltage', '~> 3.1'
|
19
23
|
```
|
20
24
|
|
21
25
|
## Usage
|
@@ -139,7 +143,7 @@ meta-data on High Voltage pages.
|
|
139
143
|
|
140
144
|
```ruby
|
141
145
|
# app/views/pages/about.html.erb
|
142
|
-
|
146
|
+
<% content_for :page_title, 'About Us - Custom page title' %>
|
143
147
|
```
|
144
148
|
|
145
149
|
Then print the contents of `:title` into the layout:
|
@@ -316,7 +320,7 @@ Make sure that there are corresponding locale files
|
|
316
320
|
/config/locale/hi.yml
|
317
321
|
```
|
318
322
|
|
319
|
-
One last note is there is a [
|
323
|
+
One last note is there is a [known
|
320
324
|
issue](https://github.com/thoughtbot/high_voltage/issues/59) with High Voltage.
|
321
325
|
|
322
326
|
You'll need to specify routes like this `<%= link_to "About Us", page_path(id:
|
@@ -358,14 +362,14 @@ Thank you, [contributors]!
|
|
358
362
|
|
359
363
|
## License
|
360
364
|
|
361
|
-
High Voltage is copyright © 2009-
|
365
|
+
High Voltage is copyright © 2009-2018 thoughtbot. It is free software, and may
|
362
366
|
be redistributed under the terms specified in the [`LICENSE`] file.
|
363
367
|
|
364
368
|
[`LICENSE`]: /MIT-LICENSE
|
365
369
|
|
366
370
|
## About thoughtbot
|
367
371
|
|
368
|
-
![thoughtbot](
|
372
|
+
![thoughtbot](http://presskit.thoughtbot.com/images/thoughtbot-logo-for-readmes.svg)
|
369
373
|
|
370
374
|
High Voltage is maintained and funded by thoughtbot, inc.
|
371
375
|
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
data/gemfiles/rails4.2.gemfile
CHANGED
data/high_voltage.gemspec
CHANGED
@@ -16,6 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.add_development_dependency(
|
20
|
-
s.add_development_dependency(
|
19
|
+
s.add_development_dependency('activesupport', '>= 3.1.0')
|
20
|
+
s.add_development_dependency('appraisal')
|
21
|
+
s.add_development_dependency('capybara')
|
22
|
+
s.add_development_dependency('pry')
|
23
|
+
s.add_development_dependency('rails-controller-testing')
|
24
|
+
s.add_development_dependency('rspec-rails', '~> 3.5')
|
21
25
|
end
|
@@ -2,27 +2,28 @@ module HighVoltage
|
|
2
2
|
module Constraints
|
3
3
|
# Routing constraint to validate request.path has a corresponding view
|
4
4
|
class RootRoute
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def initialize
|
6
|
+
@lookup_context = ActionView::LookupContext.new(
|
7
|
+
Rails.configuration.paths["app/views"],
|
8
|
+
)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def matches?(request)
|
12
|
+
page_id = clean_page_path(request.path)
|
13
|
+
template = File.join(content_path, page_id)
|
14
|
+
lookup_context.exists? template
|
15
|
+
end
|
12
16
|
|
13
|
-
|
17
|
+
private
|
14
18
|
|
15
|
-
|
16
|
-
request_path.sub(/\.html$/, "")
|
17
|
-
end
|
19
|
+
attr_reader :lookup_context
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def clean_page_path(request_path)
|
22
|
+
request_path.sub(/\.html$/, "")
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
25
|
+
def content_path
|
26
|
+
HighVoltage.content_path
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/lib/high_voltage/page.rb
CHANGED
@@ -8,17 +8,21 @@ module HighVoltage
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def id
|
11
|
-
file_path.gsub(content_path, "").
|
11
|
+
file_path.gsub(content_path, "").split(".").first
|
12
12
|
end
|
13
13
|
|
14
14
|
def valid?
|
15
|
-
exists? && file_in_content_path? && !directory? && !partial? &&
|
15
|
+
exists? && file_in_content_path? && !directory? && !partial? && handled?
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
+
def handler_extension
|
21
|
+
File.extname(file_path).delete(".")
|
22
|
+
end
|
23
|
+
|
20
24
|
def exists?
|
21
|
-
File.
|
25
|
+
File.exist?(file_path)
|
22
26
|
end
|
23
27
|
|
24
28
|
def file_in_content_path?
|
@@ -33,12 +37,12 @@ module HighVoltage
|
|
33
37
|
File.basename(file_path).first == "_"
|
34
38
|
end
|
35
39
|
|
36
|
-
def
|
37
|
-
|
40
|
+
def handled?
|
41
|
+
available_handlers.include? handler_extension
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
41
|
-
|
44
|
+
def available_handlers
|
45
|
+
ActionView::Template.template_handler_extensions
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -2,8 +2,6 @@ module HighVoltage
|
|
2
2
|
# A command for finding pages by id. This encapsulates the concepts of
|
3
3
|
# mapping page names to file names.
|
4
4
|
class PageFinder
|
5
|
-
VALID_CHARACTERS = "a-zA-Z0-9~!@$%^&*()#`_+-=<>\"{}|[];',?".freeze
|
6
|
-
|
7
5
|
def initialize(page_id)
|
8
6
|
@page_id = page_id
|
9
7
|
end
|
@@ -11,7 +9,11 @@ module HighVoltage
|
|
11
9
|
# Produce a template path to the page, in a format understood by
|
12
10
|
# `render :template => find`
|
13
11
|
def find
|
14
|
-
"
|
12
|
+
path = clean_content_pathname.join(page_id.tr("\\", "/")).cleanpath.to_s
|
13
|
+
if !path.start_with?("#{clean_content_pathname}/")
|
14
|
+
raise InvalidPageIdError.new "Invalid page id: #{page_id}"
|
15
|
+
end
|
16
|
+
path
|
15
17
|
end
|
16
18
|
|
17
19
|
def content_path
|
@@ -23,27 +25,8 @@ module HighVoltage
|
|
23
25
|
# The raw page id passed in by the user
|
24
26
|
attr_reader :page_id
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
def clean_path
|
29
|
-
path = Pathname.new("/#{clean_id}")
|
30
|
-
path.cleanpath.to_s[1..-1].tap do |p|
|
31
|
-
if p.blank?
|
32
|
-
raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def clean_id
|
38
|
-
@page_id.tr("^#{VALID_CHARACTERS}", "").tap do |id|
|
39
|
-
if invalid_page_id?(id)
|
40
|
-
raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def invalid_page_id?(id)
|
46
|
-
id.blank? || (id.first == ".")
|
28
|
+
def clean_content_pathname
|
29
|
+
Pathname.new(content_path).cleanpath
|
47
30
|
end
|
48
31
|
end
|
49
32
|
|
data/lib/high_voltage/version.rb
CHANGED
@@ -1,36 +1,29 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe HighVoltage::Constraints::RootRoute
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
describe HighVoltage::Constraints::RootRoute do
|
4
|
+
describe "#matches?" do
|
5
|
+
it "returns true when the view file exists" do
|
6
|
+
request = double(path: "exists")
|
7
7
|
|
8
|
-
|
8
|
+
result = described_class.new.matches?(request)
|
9
9
|
|
10
|
-
|
10
|
+
expect(result).to be true
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
it "returns true when the view file exists and url ends with .html" do
|
16
|
-
request = double(path: "index.html")
|
17
|
-
file_path = Rails.root.join("app", "views", "pages", "index.html*").to_s
|
18
|
-
|
19
|
-
allow(Dir).to receive(:glob).with(file_path).and_return(["about.html.erb"])
|
13
|
+
it "returns true when the view file exists and url ends with .html" do
|
14
|
+
request = double(path: "exists.html")
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
expect(result).to be true
|
24
|
-
end
|
16
|
+
result = described_class.new.matches?(request)
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
file_path = Rails.root.join("app", "views", "pages", "index", ".html*").to_s
|
18
|
+
expect(result).to be true
|
19
|
+
end
|
29
20
|
|
30
|
-
|
21
|
+
it "returns false when the view files does not exist" do
|
22
|
+
request = double(path: "index")
|
31
23
|
|
32
|
-
|
24
|
+
result = described_class.new.matches?(request)
|
33
25
|
|
34
|
-
|
26
|
+
expect(result).to be false
|
27
|
+
end
|
35
28
|
end
|
36
29
|
end
|
@@ -10,7 +10,7 @@ describe HighVoltage::PagesController do
|
|
10
10
|
before { get :show, id: "exists" }
|
11
11
|
|
12
12
|
it "responds with success and render template" do
|
13
|
-
expect(response).to
|
13
|
+
expect(response).to be_successful
|
14
14
|
expect(response).to render_template("exists")
|
15
15
|
end
|
16
16
|
|
@@ -23,7 +23,7 @@ describe HighVoltage::PagesController do
|
|
23
23
|
before { get :show, id: "dir/nested" }
|
24
24
|
|
25
25
|
it "responds with success and render template" do
|
26
|
-
expect(response).to
|
26
|
+
expect(response).to be_successful
|
27
27
|
expect(response).to render_template("pages/dir/nested")
|
28
28
|
end
|
29
29
|
end
|
@@ -69,7 +69,7 @@ describe HighVoltage::PagesController do
|
|
69
69
|
before { get :show, id: "also_exists" }
|
70
70
|
|
71
71
|
it "responds with success and render template" do
|
72
|
-
expect(response).to
|
72
|
+
expect(response).to be_successful
|
73
73
|
expect(response).to render_template("other_pages/also_exists")
|
74
74
|
end
|
75
75
|
end
|
@@ -78,7 +78,7 @@ describe HighVoltage::PagesController do
|
|
78
78
|
before { get :show, id: "also_dir/also_nested" }
|
79
79
|
|
80
80
|
it "responds with success and render template" do
|
81
|
-
expect(response).to
|
81
|
+
expect(response).to be_successful
|
82
82
|
expect(response).to render_template("other_pages/also_dir/also_nested")
|
83
83
|
end
|
84
84
|
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe SubclassedPagesController do
|
4
4
|
render_views
|
5
5
|
|
6
|
-
describe
|
7
|
-
before { get :show, :
|
6
|
+
describe "on GET to /subclassed_pages/also_exists" do
|
7
|
+
before { get :show, id: "also_exists" }
|
8
8
|
|
9
|
-
it
|
10
|
-
expect(response).to
|
11
|
-
expect(response).to render_template(
|
9
|
+
it "responds with success and render template" do
|
10
|
+
expect(response).to be_successful
|
11
|
+
expect(response).to render_template("also_exists")
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
expect(response).not_to render_template(
|
16
|
-
expect(response).to render_template(
|
14
|
+
it "uses the custom configured layout" do
|
15
|
+
expect(response).not_to render_template("layouts/application")
|
16
|
+
expect(response).to render_template("layouts/alternate")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'raises a routing error for an invalid page' do
|
21
|
-
expect { get :show, id:
|
22
|
-
|
21
|
+
expect { get :show, id: "invalid" }.
|
22
|
+
to raise_error(ActionController::RoutingError)
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'raises a routing error for a page in another directory' do
|
26
|
-
expect { get :show, id:
|
27
|
-
|
26
|
+
expect { get :show, id: "../other/wrong" }.
|
27
|
+
to raise_error(ActionController::RoutingError)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'raises a missing template error for valid page with invalid partial' do
|
31
|
-
expect { get :show, id:
|
32
|
-
|
31
|
+
expect { get :show, id: "also_exists_but_references_nonexistent_partial" }.
|
32
|
+
to raise_error(ActionView::MissingTemplate)
|
33
33
|
end
|
34
34
|
end
|
data/spec/fake_app.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<h1>About Us</h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Current Page: <%= current_page %></h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Exists without html extension</h1>
|
@@ -2,14 +2,18 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe HighVoltage::PageCollector do
|
4
4
|
it "produces an array of all page_ids under pages/" do
|
5
|
-
expect(HighVoltage.page_ids).to
|
5
|
+
expect(HighVoltage.page_ids).to match_array [
|
6
|
+
"about",
|
6
7
|
"also_dir/also_nested",
|
7
8
|
"also_exists",
|
8
9
|
"also_exists_but_references_nonexistent_partial",
|
10
|
+
"current_page_helper",
|
9
11
|
"dir/nested",
|
10
12
|
"exists",
|
11
13
|
"exists_but_references_nonexistent_partial",
|
12
|
-
"rot13"
|
14
|
+
"rot13",
|
15
|
+
"exists_without_html_extension",
|
16
|
+
"text",
|
13
17
|
]
|
14
18
|
end
|
15
19
|
|
@@ -11,12 +11,26 @@ describe HighVoltage::PageFinder do
|
|
11
11
|
expect(find("dir/nested")).to eq "pages/dir/nested"
|
12
12
|
end
|
13
13
|
|
14
|
+
it "produces the name of a dotfile" do
|
15
|
+
expect(find(".file")).to eq "pages/.file"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "supports non-ASCII characters" do
|
19
|
+
expect(find("résumé")).to eq "pages/résumé"
|
20
|
+
end
|
21
|
+
|
14
22
|
it "uses a custom content path" do
|
15
23
|
with_content_path("other_pages/") do
|
16
24
|
expect(find("also_exists")).to eq "other_pages/also_exists"
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
28
|
+
it "allows the trailing slash to be omitted from the content path" do
|
29
|
+
with_content_path("forgot_slash") do
|
30
|
+
expect(find("thing")).to eq "forgot_slash/thing"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
20
34
|
it "exposes the content path" do
|
21
35
|
with_content_path("another_thing/") do
|
22
36
|
expect(page_finder.content_path).to eq "another_thing/"
|
@@ -33,24 +47,31 @@ describe HighVoltage::PageFinder do
|
|
33
47
|
expect(subclass.new("sweet page").page_name).to eq "the page is sweet page"
|
34
48
|
end
|
35
49
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
expect { find("
|
50
|
+
context "bad page_id" do
|
51
|
+
it "throws an exception if page_id resolves to empty" do
|
52
|
+
expect { find("") }.to raise_error HighVoltage::InvalidPageIdError
|
53
|
+
expect { find("/") }.to raise_error HighVoltage::InvalidPageIdError
|
54
|
+
expect { find(".") }.to raise_error HighVoltage::InvalidPageIdError
|
55
|
+
expect { find("\\.") }.to raise_error HighVoltage::InvalidPageIdError
|
56
|
+
expect { find("/\\.") }.to raise_error HighVoltage::InvalidPageIdError
|
57
|
+
expect { find("dummy/..") }.to raise_error HighVoltage::InvalidPageIdError
|
43
58
|
end
|
44
59
|
|
45
|
-
it "throws an exception if
|
46
|
-
expect { find("
|
60
|
+
it "throws an exception if page_id resolves to outside the content path" do
|
61
|
+
expect { find("..") }.to raise_error HighVoltage::InvalidPageIdError
|
62
|
+
expect { find("\\..") }.to raise_error HighVoltage::InvalidPageIdError
|
63
|
+
expect { find("/\\..") }.to raise_error HighVoltage::InvalidPageIdError
|
64
|
+
expect { find("../secret") }.
|
65
|
+
to raise_error HighVoltage::InvalidPageIdError
|
66
|
+
expect { find("\\../secret") }.
|
67
|
+
to raise_error HighVoltage::InvalidPageIdError
|
68
|
+
expect { find("/\\../secret") }.
|
69
|
+
to raise_error HighVoltage::InvalidPageIdError
|
70
|
+
expect { find("dummy/../../secret") }.
|
71
|
+
to raise_error HighVoltage::InvalidPageIdError
|
47
72
|
end
|
48
73
|
end
|
49
74
|
|
50
|
-
it "throws an exception if the path is empty" do
|
51
|
-
expect { find("關於我們/合作伙伴") }.to raise_error HighVoltage::InvalidPageIdError
|
52
|
-
end
|
53
|
-
|
54
75
|
private
|
55
76
|
|
56
77
|
def find(page_id)
|
@@ -43,10 +43,10 @@ describe HighVoltage::Page do
|
|
43
43
|
expect(page).to_not be_valid
|
44
44
|
end
|
45
45
|
|
46
|
-
it "is
|
47
|
-
page = page(full_file_path("
|
46
|
+
it "is valid for files without a format present" do
|
47
|
+
page = page(full_file_path("exists_without_html_extension.erb"))
|
48
48
|
|
49
|
-
expect(page).
|
49
|
+
expect(page).to be_valid
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
data/spec/spec_helper.rb
CHANGED
@@ -4,10 +4,9 @@ require "pry"
|
|
4
4
|
require "active_model/railtie"
|
5
5
|
require "action_controller/railtie"
|
6
6
|
require "action_view/railtie"
|
7
|
-
require "rspec/rails"
|
8
|
-
|
9
7
|
require "high_voltage"
|
10
8
|
require "fake_app"
|
9
|
+
require "rspec/rails"
|
11
10
|
|
12
11
|
Rails.backtrace_cleaner.remove_silencers!
|
13
12
|
|
@@ -3,8 +3,12 @@
|
|
3
3
|
# supported in Rails 5+. Since we support back to 4, we need some sort of shim
|
4
4
|
# to avoid super noisy deprecations when running tests.
|
5
5
|
module HTTPMethodShim
|
6
|
-
def get(path, params = nil,
|
7
|
-
|
6
|
+
def get(path, params = nil, *args)
|
7
|
+
if args.any?
|
8
|
+
raise ArgumentError, "Unexpected arguments passed to shim: #{args.inspect}"
|
9
|
+
else
|
10
|
+
super(path, params: params)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: high_voltage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Jankowski
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date:
|
19
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activesupport
|
@@ -32,6 +32,34 @@ dependencies:
|
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 3.1.0
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: appraisal
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: capybara
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
35
63
|
- !ruby/object:Gem::Dependency
|
36
64
|
name: pry
|
37
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,6 +74,34 @@ dependencies:
|
|
46
74
|
- - ">="
|
47
75
|
- !ruby/object:Gem::Version
|
48
76
|
version: '0'
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rails-controller-testing
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec-rails
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.5'
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.5'
|
49
105
|
description: Fire in the disco. Fire in the ... taco bell.
|
50
106
|
email:
|
51
107
|
- support@thoughtbot.com
|
@@ -66,10 +122,10 @@ files:
|
|
66
122
|
- app/controllers/concerns/high_voltage/static_page.rb
|
67
123
|
- app/controllers/high_voltage/pages_controller.rb
|
68
124
|
- config/routes.rb
|
69
|
-
- gemfiles/rails4.0.gemfile
|
70
|
-
- gemfiles/rails4.1.gemfile
|
71
125
|
- gemfiles/rails4.2.gemfile
|
72
|
-
- gemfiles/
|
126
|
+
- gemfiles/rails5.0.gemfile
|
127
|
+
- gemfiles/rails5.1.gemfile
|
128
|
+
- gemfiles/rails5.2.gemfile
|
73
129
|
- high_voltage.gemspec
|
74
130
|
- lib/high_voltage.rb
|
75
131
|
- lib/high_voltage/configuration.rb
|
@@ -86,6 +142,8 @@ files:
|
|
86
142
|
- spec/controllers/pages_controller_spec.rb
|
87
143
|
- spec/controllers/subclassed_pages_controller_spec.rb
|
88
144
|
- spec/fake_app.rb
|
145
|
+
- spec/features/current_page_helper_spec.rb
|
146
|
+
- spec/features/view_page_spec.rb
|
89
147
|
- spec/fixtures/app/views/layouts/alternate.html.erb
|
90
148
|
- spec/fixtures/app/views/layouts/application.html.erb
|
91
149
|
- spec/fixtures/app/views/other/wrong.html.erb
|
@@ -93,12 +151,15 @@ files:
|
|
93
151
|
- spec/fixtures/app/views/other_pages/also_exists.html.erb
|
94
152
|
- spec/fixtures/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb
|
95
153
|
- spec/fixtures/app/views/pages/_partial.html.erb
|
154
|
+
- spec/fixtures/app/views/pages/about.html.erb
|
96
155
|
- spec/fixtures/app/views/pages/also_dir/also_nested.html.erb
|
97
156
|
- spec/fixtures/app/views/pages/also_exists.html.erb
|
98
157
|
- spec/fixtures/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb
|
158
|
+
- spec/fixtures/app/views/pages/current_page_helper.html.erb
|
99
159
|
- spec/fixtures/app/views/pages/dir/nested.html.erb
|
100
160
|
- spec/fixtures/app/views/pages/exists.html.erb
|
101
161
|
- spec/fixtures/app/views/pages/exists_but_references_nonexistent_partial.html.erb
|
162
|
+
- spec/fixtures/app/views/pages/exists_without_html_extension.erb
|
102
163
|
- spec/fixtures/app/views/pages/rot13.html.erb
|
103
164
|
- spec/fixtures/app/views/pages/text.txt.erb
|
104
165
|
- spec/fixtures/config/database.yml
|
@@ -137,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
198
|
version: '0'
|
138
199
|
requirements: []
|
139
200
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.6.8
|
141
202
|
signing_key:
|
142
203
|
specification_version: 4
|
143
204
|
summary: Simple static page rendering controller
|
@@ -147,6 +208,8 @@ test_files:
|
|
147
208
|
- spec/controllers/pages_controller_spec.rb
|
148
209
|
- spec/controllers/subclassed_pages_controller_spec.rb
|
149
210
|
- spec/fake_app.rb
|
211
|
+
- spec/features/current_page_helper_spec.rb
|
212
|
+
- spec/features/view_page_spec.rb
|
150
213
|
- spec/fixtures/app/views/layouts/alternate.html.erb
|
151
214
|
- spec/fixtures/app/views/layouts/application.html.erb
|
152
215
|
- spec/fixtures/app/views/other/wrong.html.erb
|
@@ -154,12 +217,15 @@ test_files:
|
|
154
217
|
- spec/fixtures/app/views/other_pages/also_exists.html.erb
|
155
218
|
- spec/fixtures/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb
|
156
219
|
- spec/fixtures/app/views/pages/_partial.html.erb
|
220
|
+
- spec/fixtures/app/views/pages/about.html.erb
|
157
221
|
- spec/fixtures/app/views/pages/also_dir/also_nested.html.erb
|
158
222
|
- spec/fixtures/app/views/pages/also_exists.html.erb
|
159
223
|
- spec/fixtures/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb
|
224
|
+
- spec/fixtures/app/views/pages/current_page_helper.html.erb
|
160
225
|
- spec/fixtures/app/views/pages/dir/nested.html.erb
|
161
226
|
- spec/fixtures/app/views/pages/exists.html.erb
|
162
227
|
- spec/fixtures/app/views/pages/exists_but_references_nonexistent_partial.html.erb
|
228
|
+
- spec/fixtures/app/views/pages/exists_without_html_extension.erb
|
163
229
|
- spec/fixtures/app/views/pages/rot13.html.erb
|
164
230
|
- spec/fixtures/app/views/pages/text.txt.erb
|
165
231
|
- spec/fixtures/config/database.yml
|