high_voltage 2.2.0 → 3.0.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -4
- data/.travis.yml +15 -5
- data/Appraisals +7 -10
- data/CONTRIBUTING.md +4 -1
- data/Gemfile +4 -1
- data/Gemfile.lock +65 -43
- data/MIT-LICENSE +1 -1
- data/NEWS.md +18 -0
- data/README.md +86 -18
- data/Rakefile +9 -4
- data/app/controllers/concerns/high_voltage/static_page.rb +8 -11
- data/gemfiles/rails4.0.gemfile +9 -0
- data/gemfiles/rails4.1.gemfile +9 -0
- data/gemfiles/rails4.2.gemfile +9 -0
- data/gemfiles/rails50.gemfile +10 -0
- data/high_voltage.gemspec +0 -2
- data/lib/high_voltage/configuration.rb +4 -22
- data/lib/high_voltage/constraints/root_route.rb +17 -10
- data/lib/high_voltage/engine.rb +10 -3
- data/lib/high_voltage/page.rb +44 -0
- data/lib/high_voltage/page_collector.rb +23 -0
- data/lib/high_voltage/page_finder.rb +16 -2
- data/lib/high_voltage/version.rb +1 -1
- data/lib/high_voltage.rb +2 -0
- data/spec/constraints/root_route_spec.rb +23 -8
- data/spec/controllers/pages_controller_spec.rb +57 -52
- data/spec/fake_app.rb +15 -0
- data/spec/fixtures/app/views/pages/_partial.html.erb +1 -0
- data/spec/fixtures/app/views/pages/text.txt.erb +1 -0
- data/spec/fixtures/config/database.yml +3 -0
- data/spec/high_voltage/configuration_spec.rb +0 -57
- data/spec/high_voltage/page_collector_spec.rb +36 -0
- data/spec/high_voltage/page_finder_spec.rb +34 -14
- data/spec/high_voltage/page_spec.rb +65 -0
- data/spec/spec_helper.rb +21 -8
- data/spec/support/http_method_shim.rb +15 -0
- metadata +57 -127
- data/spec/controllers/action_caching_controller_spec.rb +0 -38
- data/spec/controllers/page_caching_controller_spec.rb +0 -37
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/config/application.rb +0 -43
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -25
- data/spec/dummy/config/environments/production.rb +0 -49
- data/spec/dummy/config/environments/test.rb +0 -30
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -10
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_key_base.rb +0 -1
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +0 -2
- data/spec/dummy/public/javascripts/controls.js +0 -965
- data/spec/dummy/public/javascripts/dragdrop.js +0 -974
- data/spec/dummy/public/javascripts/effects.js +0 -1123
- data/spec/dummy/public/javascripts/prototype.js +0 -6001
- data/spec/dummy/public/javascripts/rails.js +0 -191
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +0 -6
- /data/spec/{dummy → fixtures}/app/views/layouts/alternate.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/layouts/application.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/other/wrong.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/other_pages/also_dir/also_nested.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/other_pages/also_exists.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/also_dir/also_nested.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/also_exists.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/dir/nested.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/exists.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/exists_but_references_nonexistent_partial.html.erb +0 -0
- /data/spec/{dummy → fixtures}/app/views/pages/rot13.html.erb +0 -0
- /data/spec/{dummy → fixtures}/config/routes.rb +0 -0
- /data/spec/{dummy → fixtures}/public/pages/exists.html +0 -0
- /data/spec/{dummy → support}/app/controllers/alternative_finder_controller.rb +0 -0
- /data/spec/{dummy → support}/app/controllers/subclassed_pages_controller.rb +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
class Page
|
|
3
|
+
attr_reader :content_path, :file_path
|
|
4
|
+
|
|
5
|
+
def initialize(content_path, file_path)
|
|
6
|
+
@content_path = content_path
|
|
7
|
+
@file_path = file_path
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def id
|
|
11
|
+
file_path.gsub(content_path, "").gsub(html_file_pattern, "")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def valid?
|
|
15
|
+
exists? && file_in_content_path? && !directory? && !partial? && html?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def exists?
|
|
21
|
+
File.exists?(file_path)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def file_in_content_path?
|
|
25
|
+
file_path.start_with?(content_path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def directory?
|
|
29
|
+
FileTest.directory?(file_path)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def partial?
|
|
33
|
+
File.basename(file_path).first == "_"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def html?
|
|
37
|
+
!file_path.match(html_file_pattern).nil?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def html_file_pattern
|
|
41
|
+
/\.(html)(\.[a-z]+)?$/
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module HighVoltage
|
|
2
|
+
require "find"
|
|
3
|
+
|
|
4
|
+
class PageCollector
|
|
5
|
+
attr_reader :content_path
|
|
6
|
+
|
|
7
|
+
def initialize(content_path)
|
|
8
|
+
@content_path = content_path.to_s
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def page_ids
|
|
12
|
+
pages.select(&:valid?).map(&:id)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def pages
|
|
18
|
+
Find.find(content_path).map do |file_path|
|
|
19
|
+
HighVoltage::Page.new(content_path, file_path)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -27,11 +27,25 @@ module HighVoltage
|
|
|
27
27
|
|
|
28
28
|
def clean_path
|
|
29
29
|
path = Pathname.new("/#{clean_id}")
|
|
30
|
-
path.cleanpath.to_s[1..-1]
|
|
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
|
|
31
35
|
end
|
|
32
36
|
|
|
33
37
|
def clean_id
|
|
34
|
-
@page_id.tr("^#{VALID_CHARACTERS}",
|
|
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 == ".")
|
|
35
47
|
end
|
|
36
48
|
end
|
|
49
|
+
|
|
50
|
+
class InvalidPageIdError < StandardError; end
|
|
37
51
|
end
|
data/lib/high_voltage/version.rb
CHANGED
data/lib/high_voltage.rb
CHANGED
|
@@ -3,6 +3,8 @@ require 'active_support/core_ext/module/attribute_accessors'
|
|
|
3
3
|
|
|
4
4
|
require 'high_voltage/configuration'
|
|
5
5
|
require 'high_voltage/constraints/root_route'
|
|
6
|
+
require "high_voltage/page"
|
|
7
|
+
require "high_voltage/page_collector"
|
|
6
8
|
require 'high_voltage/page_finder'
|
|
7
9
|
require 'high_voltage/route_drawers/default'
|
|
8
10
|
require 'high_voltage/route_drawers/root'
|
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe HighVoltage::Constraints::RootRoute,
|
|
4
|
-
it
|
|
3
|
+
describe HighVoltage::Constraints::RootRoute, ".matches?" do
|
|
4
|
+
it "returns true when the view file exists" do
|
|
5
5
|
request = double(path: 'index')
|
|
6
|
-
|
|
6
|
+
file_path = Rails.root.join("app", "views", "pages", "index.html*").to_s
|
|
7
|
+
|
|
8
|
+
allow(Dir).to receive(:glob).with(file_path).and_return(["about.html.erb"])
|
|
9
|
+
|
|
10
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
|
11
|
+
|
|
12
|
+
expect(result).to be true
|
|
13
|
+
end
|
|
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"])
|
|
7
20
|
|
|
8
21
|
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
|
9
22
|
|
|
10
|
-
expect(result).to
|
|
23
|
+
expect(result).to be true
|
|
11
24
|
end
|
|
12
25
|
|
|
13
|
-
it
|
|
26
|
+
it "returns false when the view files does not exist" do
|
|
14
27
|
request = double(path: 'index')
|
|
15
|
-
|
|
28
|
+
file_path = Rails.root.join("app", "views", "pages", "index", ".html*").to_s
|
|
29
|
+
|
|
30
|
+
allow(File).to receive(:glob).with(file_path).and_return([])
|
|
16
31
|
|
|
17
32
|
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
|
18
33
|
|
|
19
|
-
expect(result).to
|
|
34
|
+
expect(result).to be false
|
|
20
35
|
end
|
|
21
36
|
end
|
|
@@ -1,108 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe HighVoltage::PagesController do
|
|
4
6
|
render_views
|
|
5
7
|
|
|
6
|
-
context
|
|
7
|
-
describe
|
|
8
|
-
before { get :show, :
|
|
8
|
+
context "using default configuration" do
|
|
9
|
+
describe "on GET to /pages/exists" do
|
|
10
|
+
before { get :show, id: "exists" }
|
|
9
11
|
|
|
10
|
-
it
|
|
12
|
+
it "responds with success and render template" do
|
|
11
13
|
expect(response).to be_success
|
|
12
|
-
expect(response).to render_template(
|
|
14
|
+
expect(response).to render_template("exists")
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
it
|
|
16
|
-
expect(response).to render_template(
|
|
17
|
+
it "uses the default layout used by ApplicationController" do
|
|
18
|
+
expect(response).to render_template("layouts/application")
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
describe
|
|
21
|
-
before { get :show, :
|
|
22
|
+
describe "on GET to /pages/dir/nested" do
|
|
23
|
+
before { get :show, id: "dir/nested" }
|
|
22
24
|
|
|
23
|
-
it
|
|
25
|
+
it "responds with success and render template" do
|
|
24
26
|
expect(response).to be_success
|
|
25
|
-
expect(response).to render_template(
|
|
27
|
+
expect(response).to render_template("pages/dir/nested")
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
it
|
|
30
|
-
expect { get :show, id:
|
|
31
|
-
|
|
31
|
+
it "raises a routing error for an invalid page" do
|
|
32
|
+
expect { get :show, id: "invalid" }.
|
|
33
|
+
to raise_error(ActionController::RoutingError)
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
it
|
|
35
|
-
expect { get :show, id:
|
|
36
|
-
|
|
36
|
+
it "raises a routing error for a page in another directory" do
|
|
37
|
+
expect { get :show, id: "../other/wrong" }.
|
|
38
|
+
to raise_error(ActionController::RoutingError)
|
|
37
39
|
end
|
|
38
40
|
|
|
39
|
-
it
|
|
40
|
-
expect { get :show, id:
|
|
41
|
-
|
|
41
|
+
it "raises a missing template error for valid page with invalid partial" do
|
|
42
|
+
expect { get :show, id: "exists_but_references_nonexistent_partial" }.
|
|
43
|
+
to raise_error(ActionView::MissingTemplate)
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
context
|
|
47
|
+
context "using custom layout" do
|
|
46
48
|
before(:each) do
|
|
47
|
-
HighVoltage.layout =
|
|
49
|
+
HighVoltage.layout = "alternate"
|
|
48
50
|
end
|
|
49
51
|
|
|
50
|
-
describe
|
|
51
|
-
before { get :show, :
|
|
52
|
+
describe "on GET to /pages/exists" do
|
|
53
|
+
before { get :show, id: "exists" }
|
|
52
54
|
|
|
53
|
-
it
|
|
54
|
-
expect(response).not_to render_template(
|
|
55
|
-
expect(response).to render_template(
|
|
55
|
+
it "uses the custom configured layout" do
|
|
56
|
+
expect(response).not_to render_template("layouts/application")
|
|
57
|
+
expect(response).to render_template("layouts/alternate")
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
context
|
|
62
|
+
context "using custom content path" do
|
|
61
63
|
before(:each) do
|
|
62
|
-
HighVoltage.content_path =
|
|
64
|
+
HighVoltage.content_path = "other_pages/"
|
|
63
65
|
Rails.application.reload_routes!
|
|
64
66
|
end
|
|
65
67
|
|
|
66
|
-
describe
|
|
67
|
-
before { get :show, :
|
|
68
|
+
describe "on GET to /other_pages/also_exists" do
|
|
69
|
+
before { get :show, id: "also_exists" }
|
|
68
70
|
|
|
69
|
-
it
|
|
71
|
+
it "responds with success and render template" do
|
|
70
72
|
expect(response).to be_success
|
|
71
|
-
expect(response).to render_template(
|
|
73
|
+
expect(response).to render_template("other_pages/also_exists")
|
|
72
74
|
end
|
|
73
75
|
end
|
|
74
76
|
|
|
75
|
-
describe
|
|
76
|
-
before { get :show, :
|
|
77
|
+
describe "on GET to /other_pages/also_dir/nested" do
|
|
78
|
+
before { get :show, id: "also_dir/also_nested" }
|
|
77
79
|
|
|
78
|
-
it
|
|
80
|
+
it "responds with success and render template" do
|
|
79
81
|
expect(response).to be_success
|
|
80
|
-
expect(response).to render_template(
|
|
82
|
+
expect(response).to render_template("other_pages/also_dir/also_nested")
|
|
81
83
|
end
|
|
82
84
|
end
|
|
83
85
|
|
|
84
|
-
it
|
|
85
|
-
expect { get :show, id:
|
|
86
|
-
|
|
86
|
+
it "raises a routing error for an invalid page" do
|
|
87
|
+
expect { get :show, id: "also_invalid" }.
|
|
88
|
+
to raise_error(ActionController::RoutingError)
|
|
89
|
+
|
|
90
|
+
expect { get :show, id: "√®ø" }.
|
|
91
|
+
to raise_error(ActionController::RoutingError)
|
|
87
92
|
end
|
|
88
93
|
|
|
89
|
-
context
|
|
90
|
-
it
|
|
91
|
-
expect { get :show, id:
|
|
92
|
-
|
|
94
|
+
context "page in another directory" do
|
|
95
|
+
it "raises a routing error" do
|
|
96
|
+
expect { get :show, id: "../other_wrong" }.
|
|
97
|
+
to raise_error(ActionController::RoutingError)
|
|
93
98
|
end
|
|
94
99
|
|
|
95
|
-
it
|
|
96
|
-
expect { get :show, id:
|
|
97
|
-
|
|
100
|
+
it "raises a routing error when using a Unicode exploit" do
|
|
101
|
+
expect { get :show, id: "/\\../other/wrong" }.
|
|
102
|
+
to raise_error(ActionController::RoutingError)
|
|
98
103
|
end
|
|
99
104
|
end
|
|
100
105
|
|
|
101
|
-
it
|
|
102
|
-
id =
|
|
106
|
+
it "raises a missing template error for valid page with invalid partial" do
|
|
107
|
+
id = "also_exists_but_references_nonexistent_partial"
|
|
103
108
|
|
|
104
|
-
expect { get :show, id: id }
|
|
105
|
-
|
|
109
|
+
expect { get :show, id: id }.
|
|
110
|
+
to raise_error(ActionView::MissingTemplate)
|
|
106
111
|
end
|
|
107
112
|
end
|
|
108
113
|
end
|
data/spec/fake_app.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ApplicationController < ActionController::Base
|
|
2
|
+
protect_from_forgery
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
# Create a rails app
|
|
6
|
+
module Dummy
|
|
7
|
+
class Application < Rails::Application
|
|
8
|
+
config.secret_key_base = "test"
|
|
9
|
+
config.eager_load = false
|
|
10
|
+
config.action_controller.perform_caching = true
|
|
11
|
+
config.action_controller.cache_store = :memory_store
|
|
12
|
+
config.root = "spec/fixtures"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
Dummy::Application.initialize!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
partial
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
text page
|
|
@@ -7,11 +7,8 @@ describe HighVoltage::Configuration do
|
|
|
7
7
|
before(:each) do
|
|
8
8
|
HighVoltage.configure do |config|
|
|
9
9
|
ActiveSupport::Deprecation.silence do
|
|
10
|
-
config.action_caching = config_value
|
|
11
|
-
config.action_caching_layout = config_value
|
|
12
10
|
config.content_path = config_value
|
|
13
11
|
config.layout = config_value
|
|
14
|
-
config.page_caching = config_value
|
|
15
12
|
config.parent_engine = config_value
|
|
16
13
|
config.route_drawer = config_value
|
|
17
14
|
config.routes = config_value
|
|
@@ -25,64 +22,10 @@ describe HighVoltage::Configuration do
|
|
|
25
22
|
end
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
it { expect(HighVoltage.action_caching).to eq config_value }
|
|
29
|
-
it { expect(HighVoltage.action_caching_layout).to eq config_value }
|
|
30
25
|
it { expect(HighVoltage.content_path).to eq config_value }
|
|
31
26
|
it { expect(HighVoltage.layout).to eq config_value }
|
|
32
|
-
it { expect(HighVoltage.page_caching).to eq config_value }
|
|
33
27
|
it { expect(HighVoltage.parent_engine).to eq config_value }
|
|
34
28
|
it { expect(HighVoltage.route_drawer).to eq config_value }
|
|
35
29
|
it { expect(HighVoltage.routes).to eq config_value }
|
|
36
30
|
end
|
|
37
|
-
|
|
38
|
-
describe '#action_caching=' do
|
|
39
|
-
it 'displays a deprecation warning' do
|
|
40
|
-
allow(ActiveSupport::Deprecation).to receive(:warn)
|
|
41
|
-
|
|
42
|
-
HighVoltage.configure do |config|
|
|
43
|
-
config.action_caching = true
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
|
47
|
-
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe '#action_caching_layout=' do
|
|
52
|
-
it 'displays a deprecation warning' do
|
|
53
|
-
allow(ActiveSupport::Deprecation).to receive(:warn)
|
|
54
|
-
|
|
55
|
-
HighVoltage.configure do |config|
|
|
56
|
-
config.action_caching_layout = true
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
|
60
|
-
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe '#page_caching=' do
|
|
65
|
-
it 'displays a deprecation warning' do
|
|
66
|
-
allow(ActiveSupport::Deprecation).to receive(:warn)
|
|
67
|
-
|
|
68
|
-
HighVoltage.configure do |config|
|
|
69
|
-
config.page_caching = true
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
|
73
|
-
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe '#set_default_configuration' do
|
|
78
|
-
it 'defaults caching without a deprecation warning' do
|
|
79
|
-
allow(ActiveSupport::Deprecation).to receive(:warn)
|
|
80
|
-
|
|
81
|
-
Class.new do
|
|
82
|
-
extend HighVoltage::Configuration
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
expect(ActiveSupport::Deprecation).not_to have_received(:warn)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
31
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe HighVoltage::PageCollector do
|
|
4
|
+
it "produces an array of all page_ids under pages/" do
|
|
5
|
+
expect(HighVoltage.page_ids).to eq [
|
|
6
|
+
"also_dir/also_nested",
|
|
7
|
+
"also_exists",
|
|
8
|
+
"also_exists_but_references_nonexistent_partial",
|
|
9
|
+
"dir/nested",
|
|
10
|
+
"exists",
|
|
11
|
+
"exists_but_references_nonexistent_partial",
|
|
12
|
+
"rot13"
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "produces an array of all page_ids under other_pages/" do
|
|
17
|
+
with_content_path("other_pages/") do
|
|
18
|
+
expect(HighVoltage.page_ids).to eq [
|
|
19
|
+
"also_dir/also_nested",
|
|
20
|
+
"also_exists",
|
|
21
|
+
"also_exists_but_references_nonexistent_partial",
|
|
22
|
+
]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def with_content_path(path)
|
|
29
|
+
original_content_path = HighVoltage.content_path
|
|
30
|
+
HighVoltage.content_path = path
|
|
31
|
+
|
|
32
|
+
yield
|
|
33
|
+
|
|
34
|
+
HighVoltage.content_path = original_content_path
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,34 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
2
4
|
|
|
3
5
|
describe HighVoltage::PageFinder do
|
|
4
|
-
it
|
|
5
|
-
expect(find(
|
|
6
|
+
it "produces the name of an existing template" do
|
|
7
|
+
expect(find("existing")).to eq "pages/existing"
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
it
|
|
9
|
-
expect(find(
|
|
10
|
+
it "produces the name of a nested template" do
|
|
11
|
+
expect(find("dir/nested")).to eq "pages/dir/nested"
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
it
|
|
13
|
-
with_content_path(
|
|
14
|
-
expect(find(
|
|
14
|
+
it "uses a custom content path" do
|
|
15
|
+
with_content_path("other_pages/") do
|
|
16
|
+
expect(find("also_exists")).to eq "other_pages/also_exists"
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
it
|
|
19
|
-
with_content_path(
|
|
20
|
-
expect(page_finder.content_path).to eq
|
|
20
|
+
it "exposes the content path" do
|
|
21
|
+
with_content_path("another_thing/") do
|
|
22
|
+
expect(page_finder.content_path).to eq "another_thing/"
|
|
21
23
|
end
|
|
22
24
|
end
|
|
23
25
|
|
|
24
|
-
it
|
|
26
|
+
it "provides the page_id" do
|
|
25
27
|
subclass = Class.new(HighVoltage::PageFinder) do
|
|
26
28
|
def page_name
|
|
27
29
|
"the page is #{page_id}"
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
expect(subclass.new(
|
|
33
|
+
expect(subclass.new("sweet page").page_name).to eq "the page is sweet page"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "removes invalid characters from the page_id" do
|
|
37
|
+
expect(find("b\\a…d√")).to eq "pages/bad"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "sanitized page_id" do
|
|
41
|
+
it "throws an exception if the page_id is empty" do
|
|
42
|
+
expect { find("\\…√") }.to raise_error HighVoltage::InvalidPageIdError
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "throws an exception if the page_id is just a file extension" do
|
|
46
|
+
expect { find("\\√.zip") }.to raise_error HighVoltage::InvalidPageIdError
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "throws an exception if the path is empty" do
|
|
51
|
+
expect { find("關於我們/合作伙伴") }.to raise_error HighVoltage::InvalidPageIdError
|
|
32
52
|
end
|
|
33
53
|
|
|
34
54
|
private
|
|
@@ -37,7 +57,7 @@ describe HighVoltage::PageFinder do
|
|
|
37
57
|
page_finder(page_id).find
|
|
38
58
|
end
|
|
39
59
|
|
|
40
|
-
def page_finder(page_id =
|
|
60
|
+
def page_finder(page_id = "whatever")
|
|
41
61
|
HighVoltage::PageFinder.new(page_id)
|
|
42
62
|
end
|
|
43
63
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe HighVoltage::Page do
|
|
4
|
+
it "produces the id for a page" do
|
|
5
|
+
page = page(full_file_path("exists.html.erb"))
|
|
6
|
+
|
|
7
|
+
expect(page.id).to eq "exists"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "produces the id for a page in a subdirectory" do
|
|
11
|
+
page = page(full_file_path("dir/nested.html.erb"))
|
|
12
|
+
|
|
13
|
+
expect(page.id).to eq "dir/nested"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "is valid for a page" do
|
|
17
|
+
page = page(full_file_path("exists.html.erb"))
|
|
18
|
+
|
|
19
|
+
expect(page).to be_valid
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "is valid for a page in a subdirectory" do
|
|
23
|
+
page = page(full_file_path("dir/nested.html.erb"))
|
|
24
|
+
|
|
25
|
+
expect(page).to be_valid
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "is invalid for a directory" do
|
|
29
|
+
page = page(full_file_path("dir"))
|
|
30
|
+
|
|
31
|
+
expect(page).to_not be_valid
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "is invalid for a partial" do
|
|
35
|
+
page = page(full_file_path("_partial.html.erb"))
|
|
36
|
+
|
|
37
|
+
expect(page).to_not be_valid
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "is invalid for a non-existent page" do
|
|
41
|
+
page = page(full_file_path("nonexistent.html.erb"))
|
|
42
|
+
|
|
43
|
+
expect(page).to_not be_valid
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "is invalid for a text page" do
|
|
47
|
+
page = page(full_file_path("text.txt.erb"))
|
|
48
|
+
|
|
49
|
+
expect(page).to_not be_valid
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def full_content_path
|
|
55
|
+
HighVoltage.full_path.to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def page(file_path)
|
|
59
|
+
HighVoltage::Page.new(full_content_path, file_path)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def full_file_path(file_path)
|
|
63
|
+
"#{full_content_path}#{file_path}"
|
|
64
|
+
end
|
|
65
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
ENV[
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "pry"
|
|
4
|
+
require "active_model/railtie"
|
|
5
|
+
require "action_controller/railtie"
|
|
6
|
+
require "action_view/railtie"
|
|
7
|
+
require "rspec/rails"
|
|
4
8
|
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require 'rspec/expectations'
|
|
8
|
-
require 'rspec/rails'
|
|
9
|
+
require "high_voltage"
|
|
10
|
+
require "fake_app"
|
|
9
11
|
|
|
10
12
|
Rails.backtrace_cleaner.remove_silencers!
|
|
11
13
|
|
|
12
|
-
Dir[File.dirname(__FILE__) +
|
|
14
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |file| require file }
|
|
13
15
|
|
|
14
16
|
RSpec.configure do |config|
|
|
17
|
+
config.infer_spec_type_from_file_location!
|
|
18
|
+
|
|
15
19
|
config.after(:each) do
|
|
16
20
|
HighVoltage.set_default_configuration
|
|
17
21
|
Rails.application.reload_routes!
|
|
@@ -23,5 +27,14 @@ RSpec.configure do |config|
|
|
|
23
27
|
|
|
24
28
|
config.include RSpec::Matchers
|
|
25
29
|
config.mock_with :rspec
|
|
26
|
-
config.order =
|
|
30
|
+
config.order = "random"
|
|
31
|
+
|
|
32
|
+
if Rails::VERSION::MAJOR >= 5
|
|
33
|
+
require "rails-controller-testing"
|
|
34
|
+
|
|
35
|
+
config.include(
|
|
36
|
+
Rails::Controller::Testing::TemplateAssertions,
|
|
37
|
+
type: :controller,
|
|
38
|
+
)
|
|
39
|
+
end
|
|
27
40
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Rails 5 deprecates calling HTTP action methods with positional arguments
|
|
2
|
+
# in favor of keyword arguments. However, the keyword argument form is only
|
|
3
|
+
# supported in Rails 5+. Since we support back to 4, we need some sort of shim
|
|
4
|
+
# to avoid super noisy deprecations when running tests.
|
|
5
|
+
module HTTPMethodShim
|
|
6
|
+
def get(path, params = nil, headers = nil)
|
|
7
|
+
super(path, params: params, headers: headers)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
if Rails::VERSION::MAJOR >= 5
|
|
12
|
+
RSpec.configure do |config|
|
|
13
|
+
config.include HTTPMethodShim, type: :controller
|
|
14
|
+
end
|
|
15
|
+
end
|