high_voltage 2.1.0 → 2.2.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 +2 -2
- data/Appraisals +2 -2
- data/Gemfile.lock +54 -46
- data/MIT-LICENSE +1 -1
- data/NEWS.md +8 -0
- data/README.md +28 -31
- data/config/routes.rb +1 -1
- data/high_voltage.gemspec +0 -1
- data/lib/high_voltage.rb +1 -0
- data/lib/high_voltage/configuration.rb +27 -6
- data/lib/high_voltage/engine.rb +4 -2
- data/lib/high_voltage/version.rb +1 -1
- data/spec/constraints/root_route_spec.rb +10 -14
- data/spec/controllers/action_caching_controller_spec.rb +21 -10
- data/spec/controllers/alternative_finder_controller_spec.rb +2 -2
- data/spec/controllers/page_caching_controller_spec.rb +19 -10
- data/spec/controllers/pages_controller_spec.rb +43 -53
- data/spec/controllers/subclassed_pages_controller_spec.rb +15 -21
- data/spec/dummy/config/environments/test.rb +2 -1
- data/spec/high_voltage/configuration_spec.rb +82 -19
- data/spec/high_voltage/page_finder_spec.rb +5 -5
- data/spec/high_voltage_spec.rb +3 -3
- data/spec/integration/navigation_spec.rb +2 -4
- data/spec/requests/home_page_spec.rb +1 -1
- data/spec/routing/routes_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -3
- metadata +3 -21
- data/spec/support/caching.rb +0 -15
- data/spec/support/concern_reload.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f93b914b6966f7141851a562ce82ffe1e218e01
|
4
|
+
data.tar.gz: d6456e304488fec82214e584d9dbd8f261151d69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eabead4dde04710b58c97047ca3d0b18af4694696b0e800af9ad0618d08d37c358071999f2fb4a56455857c501d1204a1df73c91c85f58e1fe4d9c71a915d93d
|
7
|
+
data.tar.gz: 8a0b9a4dabe052d01a1b2f4edc91cc7bd15a36eff75ab49d7db3e4c18fe9509203edc214fc2a5d2767022cdfac32c384b94af8023583a5e39944fd94830be8ba
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
if RUBY_VERSION >= '2.0'
|
2
|
-
rails_versions = ['~> 3.2.13', '~> 4.0.0']
|
2
|
+
rails_versions = ['~> 3.2.13', '~> 4.0.0', '~> 4.1.0']
|
3
3
|
else
|
4
4
|
rails_versions = ['~> 3.1.12', '~> 3.2.13']
|
5
5
|
end
|
@@ -8,7 +8,7 @@ rails_versions.each do |rails_version|
|
|
8
8
|
appraise "rails#{rails_version.slice(/\d+\.\d+/)}" do
|
9
9
|
gem 'rails', rails_version
|
10
10
|
|
11
|
-
if
|
11
|
+
if ['~> 4.0.0', '~> 4.1.0'].include? rails_version
|
12
12
|
gem 'actionpack-action_caching'
|
13
13
|
gem 'actionpack-page_caching'
|
14
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,62 +1,71 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
high_voltage (2.
|
4
|
+
high_voltage (2.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
actionpack (4.1.1)
|
10
|
+
actionview (= 4.1.1)
|
11
|
+
activesupport (= 4.1.1)
|
12
|
+
rack (~> 1.5.2)
|
13
|
+
rack-test (~> 0.6.2)
|
14
|
+
actionview (4.1.1)
|
15
|
+
activesupport (= 4.1.1)
|
16
|
+
builder (~> 3.1)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
activemodel (4.1.1)
|
19
|
+
activesupport (= 4.1.1)
|
20
|
+
builder (~> 3.1)
|
21
|
+
activesupport (4.1.1)
|
22
|
+
i18n (~> 0.6, >= 0.6.9)
|
23
|
+
json (~> 1.7, >= 1.7.7)
|
24
|
+
minitest (~> 5.1)
|
25
|
+
thread_safe (~> 0.1)
|
26
|
+
tzinfo (~> 1.1)
|
27
|
+
appraisal (1.0.0)
|
12
28
|
bundler
|
13
29
|
rake
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
ffi (1.9.0)
|
26
|
-
method_source (0.8.1)
|
27
|
-
mime-types (1.23)
|
28
|
-
mini_portile (0.5.1)
|
29
|
-
multi_json (1.7.7)
|
30
|
-
nokogiri (1.6.0)
|
31
|
-
mini_portile (~> 0.5.0)
|
32
|
-
pry (0.9.12.2)
|
33
|
-
coderay (~> 1.0.5)
|
30
|
+
thor (>= 0.14.0)
|
31
|
+
builder (3.2.2)
|
32
|
+
coderay (1.1.0)
|
33
|
+
diff-lcs (1.2.5)
|
34
|
+
erubis (2.7.0)
|
35
|
+
i18n (0.6.9)
|
36
|
+
json (1.8.1)
|
37
|
+
method_source (0.8.2)
|
38
|
+
minitest (5.3.3)
|
39
|
+
pry (0.9.12.6)
|
40
|
+
coderay (~> 1.0)
|
34
41
|
method_source (~> 0.8)
|
35
42
|
slop (~> 3.4)
|
36
43
|
rack (1.5.2)
|
37
44
|
rack-test (0.6.2)
|
38
45
|
rack (>= 1.0)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
rspec-
|
46
|
-
|
47
|
-
|
48
|
-
rspec-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
railties (4.1.1)
|
47
|
+
actionpack (= 4.1.1)
|
48
|
+
activesupport (= 4.1.1)
|
49
|
+
rake (>= 0.8.7)
|
50
|
+
thor (>= 0.18.1, < 2.0)
|
51
|
+
rake (10.3.1)
|
52
|
+
rspec-core (2.14.8)
|
53
|
+
rspec-expectations (2.14.5)
|
54
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
55
|
+
rspec-mocks (2.14.6)
|
56
|
+
rspec-rails (2.14.2)
|
57
|
+
actionpack (>= 3.0)
|
58
|
+
activemodel (>= 3.0)
|
59
|
+
activesupport (>= 3.0)
|
60
|
+
railties (>= 3.0)
|
61
|
+
rspec-core (~> 2.14.0)
|
62
|
+
rspec-expectations (~> 2.14.0)
|
63
|
+
rspec-mocks (~> 2.14.0)
|
64
|
+
slop (3.5.0)
|
65
|
+
thor (0.19.1)
|
66
|
+
thread_safe (0.3.3)
|
67
|
+
tzinfo (1.1.0)
|
68
|
+
thread_safe (~> 0.1)
|
60
69
|
|
61
70
|
PLATFORMS
|
62
71
|
ruby
|
@@ -64,7 +73,6 @@ PLATFORMS
|
|
64
73
|
DEPENDENCIES
|
65
74
|
activesupport (>= 3.1.0)
|
66
75
|
appraisal
|
67
|
-
capybara (= 2.0.3)
|
68
76
|
high_voltage!
|
69
77
|
pry
|
70
78
|
rspec-rails
|
data/MIT-LICENSE
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
New for 2.2.0:
|
2
|
+
+ Deprecate caching because page and action caching was removed in Rails 4
|
3
|
+
+ Refactor test suite to use rspec `expect` syntax consistently.
|
4
|
+
+ Added Rails 4.1 to test suite.
|
5
|
+
+ Remove Ruby 1.9.2 from test suite.
|
6
|
+
+ Remove Capybara from test suite.
|
7
|
+
+ Support dependency injection for Rails engine to define routes on
|
8
|
+
|
1
9
|
New for 2.1.0:
|
2
10
|
+ Extract configuration options into a module
|
3
11
|
+ Add ability to configure whether layout is cached with action_caching
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Yeah, like "About us", "Directions", marketing pages, etc.
|
|
15
15
|
Include in your Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem 'high_voltage', '~> 2.
|
18
|
+
gem 'high_voltage', '~> 2.2.0'
|
19
19
|
```
|
20
20
|
|
21
21
|
For Rails versions prior to 3.0, use the 0.9.2 tag of high_voltage:
|
@@ -113,6 +113,18 @@ HighVoltage.configure do |config|
|
|
113
113
|
end
|
114
114
|
```
|
115
115
|
|
116
|
+
#### Specifying Rails engine for routes
|
117
|
+
|
118
|
+
If you are using multiple Rails engines within your application, you can
|
119
|
+
specify which engine to define the default HighVoltage routes on.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
# config/initializers/high_voltage.rb
|
123
|
+
HighVoltage.configure do |config|
|
124
|
+
config.parent_engine = MyEngine
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
116
128
|
#### Page titles and meta-data
|
117
129
|
|
118
130
|
We suggest using `content_for` and `yield` for setting custom page titles and
|
@@ -145,36 +157,12 @@ end
|
|
145
157
|
|
146
158
|
#### Caching
|
147
159
|
|
148
|
-
|
160
|
+
Caching has been deprecated and will be removed in the next release.
|
149
161
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
#
|
154
|
-
HighVolgate.configure do |config|
|
155
|
-
config.action_caching = true
|
156
|
-
config.action_caching_layout = false # optionally do not cache layout. default is true.
|
157
|
-
end
|
158
|
-
```
|
159
|
-
|
160
|
-
To enable page-caching:
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
# config/initializers/high_voltage.rb
|
164
|
-
HighVolgate.configure do |config|
|
165
|
-
config.page_caching = true
|
166
|
-
end
|
167
|
-
```
|
168
|
-
|
169
|
-
High Voltage will use your default cache store to store action caches.
|
170
|
-
|
171
|
-
Using caching with Ruby on Rails 4 or higher requires gems:
|
172
|
-
|
173
|
-
```ruby
|
174
|
-
# Gemfile
|
175
|
-
gem 'actionpack-action_caching'
|
176
|
-
gem 'actionpack-page_caching'
|
177
|
-
```
|
162
|
+
Page caching and action caching can be done via Rails. Visit the [Caching with
|
163
|
+
Rails: An overview](http://guides.rubyonrails.org/caching_with_rails.html) guide
|
164
|
+
for more details. You can utilize the methods described there by overriding the
|
165
|
+
HighVoltage controller as described [below](#override).
|
178
166
|
|
179
167
|
## Override
|
180
168
|
|
@@ -230,6 +218,15 @@ class PagesController < ApplicationController
|
|
230
218
|
end
|
231
219
|
```
|
232
220
|
|
221
|
+
To set up a different layout for all High Voltage static pages, use an initializer:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
# config/initializers/high_voltage.rb
|
225
|
+
HighVoltage.configure do |config|
|
226
|
+
config.layout = 'your_layout'
|
227
|
+
end
|
228
|
+
```
|
229
|
+
|
233
230
|
## Custom finding
|
234
231
|
|
235
232
|
You can further control the algorithm used to find pages by overriding
|
@@ -309,5 +306,5 @@ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
|
309
306
|
|
310
307
|
## License
|
311
308
|
|
312
|
-
High Voltage is Copyright © 2009-
|
309
|
+
High Voltage is Copyright © 2009-2014 thoughtbot. It is free software, and may
|
313
310
|
be redistributed under the terms specified in the MIT-LICENSE file.
|
data/config/routes.rb
CHANGED
data/high_voltage.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency("activesupport", ">= 3.1.0")
|
20
20
|
s.add_development_dependency("appraisal")
|
21
|
-
s.add_development_dependency("capybara", "= 2.0.3")
|
22
21
|
s.add_development_dependency("pry")
|
23
22
|
s.add_development_dependency("rspec-rails")
|
24
23
|
end
|
data/lib/high_voltage.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
module HighVoltage
|
2
2
|
module Configuration
|
3
|
+
CACHING_DEPRECATION_WARNING = <<-WARNING.strip_heredoc.squish
|
4
|
+
Caching support has been deprecated and will be removed
|
5
|
+
in the next release.
|
6
|
+
WARNING
|
7
|
+
|
3
8
|
attr_accessor(
|
4
|
-
:action_caching,
|
5
|
-
:action_caching_layout,
|
6
9
|
:content_path,
|
7
10
|
:home_page,
|
8
11
|
:layout,
|
9
|
-
:
|
12
|
+
:parent_engine,
|
10
13
|
:route_drawer,
|
11
14
|
:routes,
|
12
15
|
)
|
13
16
|
|
17
|
+
attr_reader :action_caching, :action_caching_layout, :page_caching
|
18
|
+
|
14
19
|
def configure
|
15
20
|
yield self
|
16
21
|
end
|
@@ -19,13 +24,29 @@ module HighVoltage
|
|
19
24
|
base.set_default_configuration
|
20
25
|
end
|
21
26
|
|
27
|
+
def action_caching=(value)
|
28
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
29
|
+
@action_caching = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def action_caching_layout=(value)
|
33
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
34
|
+
@action_caching_layout = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def page_caching=(value)
|
38
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
39
|
+
@page_caching = value
|
40
|
+
end
|
41
|
+
|
22
42
|
def set_default_configuration
|
23
|
-
|
24
|
-
|
43
|
+
@action_caching = false
|
44
|
+
@action_caching_layout = true
|
45
|
+
@page_caching = false
|
46
|
+
|
25
47
|
self.content_path = 'pages/'
|
26
48
|
self.home_page = nil
|
27
49
|
self.layout = 'application'
|
28
|
-
self.page_caching = false
|
29
50
|
self.route_drawer = HighVoltage::RouteDrawers::Default
|
30
51
|
self.routes = true
|
31
52
|
end
|
data/lib/high_voltage/engine.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
module HighVoltage
|
2
2
|
class Engine < Rails::Engine
|
3
|
+
initializer 'Set up default parent engine' do |app|
|
4
|
+
HighVoltage.parent_engine ||= Rails.application
|
5
|
+
end
|
6
|
+
|
3
7
|
initializer 'Require concerns path' do |app|
|
4
8
|
concerns_path = 'app/controllers/concerns'
|
5
9
|
|
6
10
|
unless app.paths.keys.include?(concerns_path)
|
7
11
|
app.paths.add(concerns_path)
|
8
12
|
end
|
9
|
-
|
10
|
-
require 'concerns/high_voltage/static_page'
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/high_voltage/version.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe HighVoltage::Constraints::RootRoute, '.matches?' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Dir.stub(:glob).and_return(['about.html.erb'])
|
4
|
+
it 'returns true when the view file exists' do
|
5
|
+
request = double(path: 'index')
|
6
|
+
Dir.stub(:glob).and_return(['about.html.erb'])
|
8
7
|
|
9
|
-
|
8
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
10
9
|
|
11
|
-
|
12
|
-
end
|
10
|
+
expect(result).to be_true
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
File.stub(:glob).and_return([])
|
13
|
+
it 'returns false when the view files does not exist' do
|
14
|
+
request = double(path: 'index')
|
15
|
+
File.stub(:glob).and_return([])
|
19
16
|
|
20
|
-
|
17
|
+
result = HighVoltage::Constraints::RootRoute.matches?(request)
|
21
18
|
|
22
|
-
|
23
|
-
end
|
19
|
+
expect(result).to be_false
|
24
20
|
end
|
25
21
|
end
|
@@ -4,24 +4,35 @@ describe HighVoltage::PagesController, '#action_caching' do
|
|
4
4
|
let(:page_name) { :exists }
|
5
5
|
|
6
6
|
context 'action_caching set to true' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
after do
|
8
|
+
set_action_caching_without_deprecation(false)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'caches the action' do
|
12
|
+
allow(controller).to receive(:_save_fragment)
|
13
|
+
set_action_caching_without_deprecation(true)
|
14
|
+
|
15
|
+
get :show, id: page_name
|
10
16
|
|
11
|
-
expect
|
17
|
+
expect(controller).to have_received(:_save_fragment)
|
18
|
+
.with("test.host#{page_path(page_name)}", {})
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
15
22
|
context 'action_caching set to false' do
|
16
|
-
it 'does not cache the action'
|
17
|
-
|
18
|
-
|
23
|
+
it 'does not cache the action' do
|
24
|
+
allow(controller).to receive(:_save_fragment)
|
25
|
+
set_action_caching_without_deprecation(false)
|
19
26
|
|
20
|
-
|
27
|
+
get :show, id: page_name
|
28
|
+
|
29
|
+
expect(controller).not_to have_received(:_save_fragment)
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
|
-
def
|
25
|
-
|
33
|
+
def set_action_caching_without_deprecation(value)
|
34
|
+
ActiveSupport::Deprecation.silence do
|
35
|
+
HighVoltage.action_caching = value
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
@@ -6,7 +6,7 @@ describe AlternativeFinderController do
|
|
6
6
|
it 'renders the file from the alternative directory' do
|
7
7
|
get :show, :id => 'ebg13'
|
8
8
|
|
9
|
-
response.
|
10
|
-
response.
|
9
|
+
expect(response).to be_success
|
10
|
+
expect(response).to render_template('rot13')
|
11
11
|
end
|
12
12
|
end
|
@@ -4,25 +4,34 @@ describe HighVoltage::PagesController, '#cache_page' do
|
|
4
4
|
let(:page_name) { :exists }
|
5
5
|
|
6
6
|
context 'page_caching set to true' do
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
after do
|
8
|
+
set_page_caching_without_deprecation(false)
|
9
|
+
end
|
10
10
|
|
11
|
-
|
11
|
+
it 'caches the page' do
|
12
|
+
allow(controller).to receive(:cache_page)
|
13
|
+
set_page_caching_without_deprecation(true)
|
12
14
|
|
13
15
|
get :show, id: page_name
|
16
|
+
|
17
|
+
expect(controller).to have_received(:cache_page)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
21
|
context 'page_caching set to false' do
|
18
|
-
it 'does not cache the page'
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
controller.should_receive(:cache_page).never
|
22
|
+
it 'does not cache the page' do
|
23
|
+
allow(controller).to receive(:cache_page)
|
24
|
+
set_page_caching_without_deprecation(false)
|
23
25
|
|
24
26
|
get :show, id: page_name
|
27
|
+
|
28
|
+
expect(controller).not_to have_received(:cache_page)
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
28
31
|
|
32
|
+
def set_page_caching_without_deprecation(value)
|
33
|
+
ActiveSupport::Deprecation.silence do
|
34
|
+
HighVoltage.page_caching = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -7,44 +7,38 @@ describe HighVoltage::PagesController do
|
|
7
7
|
describe 'on GET to /pages/exists' do
|
8
8
|
before { get :show, :id => 'exists' }
|
9
9
|
|
10
|
-
it '
|
11
|
-
response.
|
12
|
-
response.
|
10
|
+
it 'responds with success and render template' do
|
11
|
+
expect(response).to be_success
|
12
|
+
expect(response).to render_template('exists')
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
16
|
-
response.
|
15
|
+
it 'uses the default layout used by ApplicationController' do
|
16
|
+
expect(response).to render_template('layouts/application')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'on GET to /pages/dir/nested' do
|
21
21
|
before { get :show, :id => 'dir/nested' }
|
22
22
|
|
23
|
-
it '
|
24
|
-
response.
|
25
|
-
response.
|
23
|
+
it 'responds with success and render template' do
|
24
|
+
expect(response).to be_success
|
25
|
+
expect(response).to render_template('pages/dir/nested')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
30
|
-
|
31
|
-
|
32
|
-
:id => 'invalid'
|
33
|
-
}.should raise_error(ActionController::RoutingError)
|
29
|
+
it 'raises a routing error for an invalid page' do
|
30
|
+
expect { get :show, id: 'invalid' }
|
31
|
+
.to raise_error(ActionController::RoutingError)
|
34
32
|
end
|
35
33
|
|
36
|
-
it '
|
37
|
-
|
38
|
-
|
39
|
-
:id => '../other/wrong'
|
40
|
-
}.should raise_error(ActionController::RoutingError)
|
34
|
+
it 'raises a routing error for a page in another directory' do
|
35
|
+
expect { get :show, id: '../other/wrong' }
|
36
|
+
.to raise_error(ActionController::RoutingError)
|
41
37
|
end
|
42
38
|
|
43
|
-
it '
|
44
|
-
|
45
|
-
|
46
|
-
:id => 'exists_but_references_nonexistent_partial'
|
47
|
-
}.should raise_error(ActionView::MissingTemplate)
|
39
|
+
it 'raises a missing template error for valid page with invalid partial' do
|
40
|
+
expect { get :show, id: 'exists_but_references_nonexistent_partial' }
|
41
|
+
.to raise_error(ActionView::MissingTemplate)
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
@@ -56,9 +50,9 @@ describe HighVoltage::PagesController do
|
|
56
50
|
describe 'on GET to /pages/exists' do
|
57
51
|
before { get :show, :id => 'exists' }
|
58
52
|
|
59
|
-
it '
|
60
|
-
response.
|
61
|
-
response.
|
53
|
+
it 'uses the custom configured layout' do
|
54
|
+
expect(response).not_to render_template('layouts/application')
|
55
|
+
expect(response).to render_template('layouts/alternate')
|
62
56
|
end
|
63
57
|
end
|
64
58
|
end
|
@@ -72,47 +66,43 @@ describe HighVoltage::PagesController do
|
|
72
66
|
describe 'on GET to /other_pages/also_exists' do
|
73
67
|
before { get :show, :id => 'also_exists' }
|
74
68
|
|
75
|
-
it '
|
76
|
-
response.
|
77
|
-
response.
|
69
|
+
it 'responds with success and render template' do
|
70
|
+
expect(response).to be_success
|
71
|
+
expect(response).to render_template('other_pages/also_exists')
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
81
75
|
describe 'on GET to /other_pages/also_dir/nested' do
|
82
76
|
before { get :show, :id => 'also_dir/also_nested' }
|
83
77
|
|
84
|
-
it '
|
85
|
-
response.
|
86
|
-
response.
|
78
|
+
it 'responds with success and render template' do
|
79
|
+
expect(response).to be_success
|
80
|
+
expect(response).to render_template('other_pages/also_dir/also_nested')
|
87
81
|
end
|
88
82
|
end
|
89
83
|
|
90
|
-
it '
|
91
|
-
|
92
|
-
|
93
|
-
:id => 'also_invalid'
|
94
|
-
}.should raise_error(ActionController::RoutingError)
|
84
|
+
it 'raises a routing error for an invalid page' do
|
85
|
+
expect { get :show, id: 'also_invalid' }
|
86
|
+
.to raise_error(ActionController::RoutingError)
|
95
87
|
end
|
96
88
|
|
97
|
-
|
98
|
-
|
99
|
-
get :show,
|
100
|
-
|
101
|
-
|
102
|
-
end
|
89
|
+
context 'page in another directory' do
|
90
|
+
it 'raises a routing error' do
|
91
|
+
expect { get :show, id: '../other_wrong' }
|
92
|
+
.to raise_error(ActionController::RoutingError)
|
93
|
+
end
|
103
94
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
}.should raise_error(ActionController::RoutingError)
|
95
|
+
it 'raises a routing error when using a Unicode exploit' do
|
96
|
+
expect { get :show, id: '/\\../other/wrong' }
|
97
|
+
.to raise_error(ActionController::RoutingError)
|
98
|
+
end
|
109
99
|
end
|
110
100
|
|
111
|
-
it '
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
101
|
+
it 'raises a missing template error for valid page with invalid partial' do
|
102
|
+
id = 'also_exists_but_references_nonexistent_partial'
|
103
|
+
|
104
|
+
expect { get :show, id: id }
|
105
|
+
.to raise_error(ActionView::MissingTemplate)
|
116
106
|
end
|
117
107
|
end
|
118
108
|
end
|
@@ -6,35 +6,29 @@ describe SubclassedPagesController do
|
|
6
6
|
describe 'on GET to /subclassed_pages/also_exists' do
|
7
7
|
before { get :show, :id => 'also_exists' }
|
8
8
|
|
9
|
-
it '
|
10
|
-
response.
|
11
|
-
response.
|
9
|
+
it 'responds with success and render template' do
|
10
|
+
expect(response).to be_succes
|
11
|
+
expect(response).to render_template('also_exists')
|
12
12
|
end
|
13
13
|
|
14
|
-
it '
|
15
|
-
response.
|
16
|
-
response.
|
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
|
-
it '
|
21
|
-
|
22
|
-
|
23
|
-
:id => 'invalid'
|
24
|
-
}.should raise_error(ActionController::RoutingError)
|
20
|
+
it 'raises a routing error for an invalid page' do
|
21
|
+
expect { get :show, id: 'invalid' }
|
22
|
+
.to raise_error(ActionController::RoutingError)
|
25
23
|
end
|
26
24
|
|
27
|
-
it '
|
28
|
-
|
29
|
-
|
30
|
-
:id => '../other/wrong'
|
31
|
-
}.should raise_error(ActionController::RoutingError)
|
25
|
+
it 'raises a routing error for a page in another directory' do
|
26
|
+
expect { get :show, id: '../other/wrong' }
|
27
|
+
.to raise_error(ActionController::RoutingError)
|
32
28
|
end
|
33
29
|
|
34
|
-
it '
|
35
|
-
|
36
|
-
|
37
|
-
:id => 'also_exists_but_references_nonexistent_partial'
|
38
|
-
}.should raise_error(ActionView::MissingTemplate)
|
30
|
+
it 'raises a missing template error for valid page with invalid partial' do
|
31
|
+
expect { get :show, id: 'also_exists_but_references_nonexistent_partial' }
|
32
|
+
.to raise_error(ActionView::MissingTemplate)
|
39
33
|
end
|
40
34
|
end
|
@@ -11,7 +11,8 @@ Dummy::Application.configure do
|
|
11
11
|
|
12
12
|
# Show full error reports and disable caching
|
13
13
|
config.consider_all_requests_local = true
|
14
|
-
config.action_controller.perform_caching =
|
14
|
+
config.action_controller.perform_caching = true
|
15
|
+
config.action_controller.cache_store = :memory_store
|
15
16
|
|
16
17
|
# Raise exceptions instead of rendering exception templates
|
17
18
|
config.action_dispatch.show_exceptions = false
|
@@ -1,25 +1,88 @@
|
|
1
|
-
require '
|
1
|
+
require 'minimal_spec_helper'
|
2
2
|
|
3
3
|
describe HighVoltage::Configuration do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
describe 'basic config assignment' do
|
5
|
+
let(:config_value) { 'fake_config_value' }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
HighVoltage.configure do |config|
|
9
|
+
ActiveSupport::Deprecation.silence do
|
10
|
+
config.action_caching = config_value
|
11
|
+
config.action_caching_layout = config_value
|
12
|
+
config.content_path = config_value
|
13
|
+
config.layout = config_value
|
14
|
+
config.page_caching = config_value
|
15
|
+
config.parent_engine = config_value
|
16
|
+
config.route_drawer = config_value
|
17
|
+
config.routes = config_value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
HighVoltage.configure do |config|
|
24
|
+
config.parent_engine = Rails.application
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it { expect(HighVoltage.action_caching).to eq config_value }
|
29
|
+
it { expect(HighVoltage.action_caching_layout).to eq config_value }
|
30
|
+
it { expect(HighVoltage.content_path).to eq config_value }
|
31
|
+
it { expect(HighVoltage.layout).to eq config_value }
|
32
|
+
it { expect(HighVoltage.page_caching).to eq config_value }
|
33
|
+
it { expect(HighVoltage.parent_engine).to eq config_value }
|
34
|
+
it { expect(HighVoltage.route_drawer).to eq config_value }
|
35
|
+
it { expect(HighVoltage.routes).to eq config_value }
|
36
|
+
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)
|
15
48
|
end
|
16
49
|
end
|
17
50
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
88
|
end
|
@@ -2,22 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe HighVoltage::PageFinder do
|
4
4
|
it 'produces the name of an existing template' do
|
5
|
-
find('existing').
|
5
|
+
expect(find('existing')).to eq 'pages/existing'
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'produces the name of a nested template' do
|
9
|
-
find('dir/nested').
|
9
|
+
expect(find('dir/nested')).to eq 'pages/dir/nested'
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'uses a custom content path' do
|
13
13
|
with_content_path('other_pages/') do
|
14
|
-
find('also_exists').
|
14
|
+
expect(find('also_exists')).to eq 'other_pages/also_exists'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'exposes the content path' do
|
19
19
|
with_content_path('another_thing/') do
|
20
|
-
page_finder.content_path.
|
20
|
+
expect(page_finder.content_path).to eq 'another_thing/'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,7 +28,7 @@ describe HighVoltage::PageFinder do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
subclass.new('sweet page').page_name.
|
31
|
+
expect(subclass.new('sweet page').page_name).to eq 'the page is sweet page'
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
data/spec/high_voltage_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'minimal_spec_helper'
|
2
2
|
|
3
3
|
describe HighVoltage do
|
4
|
-
it '
|
5
|
-
HighVoltage.
|
4
|
+
it 'is valid' do
|
5
|
+
expect(HighVoltage).to be_a(Module)
|
6
6
|
end
|
7
7
|
|
8
|
-
it '
|
8
|
+
it 'is loadable without preloading rails' do
|
9
9
|
expect { require 'high_voltage' }.not_to raise_error
|
10
10
|
end
|
11
11
|
end
|
data/spec/routing/routes_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe 'routes' do
|
4
4
|
context 'default configuration' do
|
5
5
|
it 'generates a route' do
|
6
|
-
page_path('one').
|
6
|
+
expect(page_path('one')).to eq '/pages/one'
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'generates a nested route' do
|
10
|
-
page_path('one/two').
|
10
|
+
expect(page_path('one/two')).to eq '/pages/one/two'
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'recognizes a route' do
|
@@ -51,11 +51,11 @@ describe 'routes' do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'generates a route' do
|
54
|
-
page_path('one').
|
54
|
+
expect(page_path('one')).to eq '/one'
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'generates a nested route' do
|
58
|
-
page_path('one/two').
|
58
|
+
expect(page_path('one/two')).to eq '/one/two'
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -66,11 +66,11 @@ describe 'routes' do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'generates a route' do
|
69
|
-
page_path('one').
|
69
|
+
expect(page_path('one')).to eq '/other_pages/one'
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'generates a nested route' do
|
73
|
-
page_path('one/two').
|
73
|
+
expect(page_path('one/two')).to eq '/other_pages/one/two'
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'recognizes a route' do
|
@@ -125,7 +125,7 @@ describe 'routes' do
|
|
125
125
|
|
126
126
|
context 'no home page route' do
|
127
127
|
it 'does generate a home page route' do
|
128
|
-
|
128
|
+
expect(get: '/').not_to be_routable
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -134,7 +134,7 @@ describe 'routes' do
|
|
134
134
|
HighVoltage.routes = false
|
135
135
|
Rails.application.reload_routes!
|
136
136
|
|
137
|
-
|
137
|
+
expect(get: '/pages/one/two').not_to be_routable
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,15 +2,12 @@ ENV['RAILS_ENV'] = 'test'
|
|
2
2
|
|
3
3
|
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
4
4
|
|
5
|
-
require 'capybara/rails'
|
6
5
|
require 'pry'
|
7
6
|
require 'rails/test_help'
|
8
7
|
require 'rspec/expectations'
|
9
8
|
require 'rspec/rails'
|
10
9
|
|
11
10
|
Rails.backtrace_cleaner.remove_silencers!
|
12
|
-
Capybara.default_driver = :rack_test
|
13
|
-
Capybara.default_selector = :css
|
14
11
|
|
15
12
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |file| require file }
|
16
13
|
|
@@ -20,6 +17,10 @@ RSpec.configure do |config|
|
|
20
17
|
Rails.application.reload_routes!
|
21
18
|
end
|
22
19
|
|
20
|
+
config.expect_with :rspec do |c|
|
21
|
+
c.syntax = :expect
|
22
|
+
end
|
23
|
+
|
23
24
|
config.include RSpec::Matchers
|
24
25
|
config.mock_with :rspec
|
25
26
|
config.order = 'random'
|
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: 2.
|
4
|
+
version: 2.2.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: 2014-06-24 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activesupport
|
@@ -46,20 +46,6 @@ dependencies:
|
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
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: 2.0.3
|
56
|
-
type: :development
|
57
|
-
prerelease: false
|
58
|
-
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - '='
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 2.0.3
|
63
49
|
- !ruby/object:Gem::Dependency
|
64
50
|
name: pry
|
65
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,8 +163,6 @@ files:
|
|
177
163
|
- spec/requests/home_page_spec.rb
|
178
164
|
- spec/routing/routes_spec.rb
|
179
165
|
- spec/spec_helper.rb
|
180
|
-
- spec/support/caching.rb
|
181
|
-
- spec/support/concern_reload.rb
|
182
166
|
homepage: http://github.com/thoughtbot/high_voltage
|
183
167
|
licenses:
|
184
168
|
- MIT
|
@@ -199,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
183
|
version: '0'
|
200
184
|
requirements: []
|
201
185
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.2.
|
186
|
+
rubygems_version: 2.2.2
|
203
187
|
signing_key:
|
204
188
|
specification_version: 4
|
205
189
|
summary: Simple static page rendering controller
|
@@ -264,5 +248,3 @@ test_files:
|
|
264
248
|
- spec/requests/home_page_spec.rb
|
265
249
|
- spec/routing/routes_spec.rb
|
266
250
|
- spec/spec_helper.rb
|
267
|
-
- spec/support/caching.rb
|
268
|
-
- spec/support/concern_reload.rb
|
data/spec/support/caching.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.around(:each, enable_caching: true) do |example|
|
3
|
-
previous_cache_store = ActionController::Base.cache_store
|
4
|
-
|
5
|
-
ActionController::Base.perform_caching = true
|
6
|
-
ActionController::Base.cache_store = :memory_store
|
7
|
-
ActionController::Base.cache_store.clear
|
8
|
-
|
9
|
-
example.run
|
10
|
-
|
11
|
-
ActionController::Base.cache_store.clear
|
12
|
-
ActionController::Base.cache_store = previous_cache_store
|
13
|
-
ActionController::Base.perform_caching = false
|
14
|
-
end
|
15
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
def concern_reload
|
2
|
-
HighVoltage::PagesController.class_eval do
|
3
|
-
if respond_to?(:caches_action)
|
4
|
-
caches_action :show, if: -> { HighVoltage.action_caching }
|
5
|
-
end
|
6
|
-
|
7
|
-
if respond_to?(:caches_page)
|
8
|
-
caches_page :show, if: -> { HighVoltage.page_caching }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|