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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -5
  3. data/Appraisals +1 -8
  4. data/Gemfile +0 -3
  5. data/Gemfile.lock +78 -58
  6. data/MIT-LICENSE +1 -1
  7. data/NEWS.md +9 -0
  8. data/README.md +11 -7
  9. data/app/controllers/concerns/high_voltage/static_page.rb +4 -1
  10. data/gemfiles/rails4.2.gemfile +0 -2
  11. data/gemfiles/{rails4.0.gemfile → rails5.0.gemfile} +1 -3
  12. data/gemfiles/{rails4.1.gemfile → rails5.1.gemfile} +1 -3
  13. data/gemfiles/rails5.2.gemfile +7 -0
  14. data/high_voltage.gemspec +6 -2
  15. data/lib/high_voltage/constraints/root_route.rb +17 -16
  16. data/lib/high_voltage/page.rb +11 -7
  17. data/lib/high_voltage/page_finder.rb +7 -24
  18. data/lib/high_voltage/route_drawers/root.rb +1 -1
  19. data/lib/high_voltage/version.rb +1 -1
  20. data/spec/constraints/root_route_spec.rb +17 -24
  21. data/spec/controllers/alternative_finder_controller_spec.rb +1 -1
  22. data/spec/controllers/pages_controller_spec.rb +4 -4
  23. data/spec/controllers/subclassed_pages_controller_spec.rb +15 -15
  24. data/spec/fake_app.rb +1 -0
  25. data/spec/features/current_page_helper_spec.rb +9 -0
  26. data/spec/features/view_page_spec.rb +9 -0
  27. data/spec/fixtures/app/views/pages/about.html.erb +1 -0
  28. data/spec/fixtures/app/views/pages/current_page_helper.html.erb +1 -0
  29. data/spec/fixtures/app/views/pages/exists_without_html_extension.erb +1 -0
  30. data/spec/high_voltage/page_collector_spec.rb +6 -2
  31. data/spec/high_voltage/page_finder_spec.rb +34 -13
  32. data/spec/high_voltage/page_spec.rb +3 -3
  33. data/spec/spec_helper.rb +1 -2
  34. data/spec/support/http_method_shim.rb +6 -2
  35. metadata +72 -6
  36. data/gemfiles/rails50.gemfile +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6fe8331cf7311ae941daea7a313a66e350a5565
4
- data.tar.gz: d1f5bb5ec3984ce97f167a7e4b56c9936ff1a788
3
+ metadata.gz: 223b265a8f841aac5236e6a7f2e635785d1799c9
4
+ data.tar.gz: f38250b134ab9303a6c0b4b0b577b1a87a1fa629
5
5
  SHA512:
6
- metadata.gz: 7b5f88d3c1b88243befa89c0e1c8e1640b9b1556ea070dcbb7eff8bfeab51c88d6907e6746730d9318c4a276f026f45695eefc800e9aba078bc4ee48714860a8
7
- data.tar.gz: 949ae450736d58557bc15ecdcd6f33098ae2ada670563b9440e8b65e7883d12154ddc170d3f42d1147133d4452ccabe7d771707eef320779113e32bdccc636a7
6
+ metadata.gz: 0543bae3871a0087e610c70417c4c98158c265d9a9972336f990c7d30c2f1375ccf0cede3c068e57feee604985ce3c837e4948dedf35543f5cb4c454b3af0c2f
7
+ data.tar.gz: 44ee90083858b224de20a07b8e971a02a40aaa1018896679700eb90ed16c19eb10fbf0503d576c8de524b36e08c95054676e6ce32a870892baceda703625c62b
@@ -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.8
12
- - 2.2.4
13
- - 2.3.0
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', '~> 4.1.0', '~> 4.2.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
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem "appraisal"
6
- gem "rspec-rails", "~> 3.2"
@@ -1,90 +1,108 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- high_voltage (3.0.0)
4
+ high_voltage (3.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (4.2.5.2)
10
- actionview (= 4.2.5.2)
11
- activesupport (= 4.2.5.2)
12
- rack (~> 1.6)
13
- rack-test (~> 0.6.2)
14
- rails-dom-testing (~> 1.0, >= 1.0.5)
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 (4.2.5.2)
17
- activesupport (= 4.2.5.2)
16
+ actionview (5.1.1)
17
+ activesupport (= 5.1.1)
18
18
  builder (~> 3.1)
19
- erubis (~> 2.7.0)
20
- rails-dom-testing (~> 1.0, >= 1.0.5)
21
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
22
- activesupport (4.2.5.2)
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.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
- diff-lcs (1.2.5)
35
- erubis (2.7.0)
36
- i18n (0.7.0)
37
- json (1.8.3)
38
- loofah (2.0.3)
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
- mini_portile2 (2.0.0)
42
- minitest (5.8.4)
43
- nokogiri (1.6.7.2)
44
- mini_portile2 (~> 2.0.0.rc2)
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
- rack (1.6.4)
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-deprecated_sanitizer (1.0.3)
53
- activesupport (>= 4.2.0.alpha)
54
- rails-dom-testing (1.0.7)
55
- activesupport (>= 4.2.0.beta, < 5.0)
56
- nokogiri (~> 1.6.0)
57
- rails-deprecated_sanitizer (>= 1.0.1)
58
- rails-html-sanitizer (1.0.3)
59
- loofah (~> 2.0)
60
- railties (4.2.5.2)
61
- actionpack (= 4.2.5.2)
62
- activesupport (= 4.2.5.2)
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 (10.5.0)
66
- rspec-core (3.4.3)
67
- rspec-support (~> 3.4.0)
68
- rspec-expectations (3.4.0)
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.4.0)
71
- rspec-mocks (3.4.1)
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.4.0)
74
- rspec-rails (3.4.2)
75
- actionpack (>= 3.0, < 4.3)
76
- activesupport (>= 3.0, < 4.3)
77
- railties (>= 3.0, < 4.3)
78
- rspec-core (~> 3.4.0)
79
- rspec-expectations (~> 3.4.0)
80
- rspec-mocks (~> 3.4.0)
81
- rspec-support (~> 3.4.0)
82
- rspec-support (3.4.1)
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.1)
85
- thread_safe (0.3.5)
86
- tzinfo (1.2.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
- rspec-rails (~> 3.2)
116
+ rails-controller-testing
117
+ rspec-rails (~> 3.5)
98
118
 
99
119
  BUNDLED WITH
100
- 1.11.2
120
+ 1.16.1
@@ -1,4 +1,4 @@
1
- Copyright 2010-2015 thoughtbot, inc.
1
+ Copyright 2010-2018 thoughtbot, inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.png)](http://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
- Include in your Gemfile:
19
+ Or you can include in your Gemfile:
16
20
 
17
21
  ```ruby
18
- gem 'high_voltage', '~> 3.0.0'
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
- <%= content_for :page_title, 'About Us - Custom page title' %>
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 [know
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-2016 thoughtbot. It is free software, and may
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](https://thoughtbot.com/logo.png)
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.
@@ -16,7 +16,10 @@ module HighVoltage::StaticPage
16
16
  end
17
17
 
18
18
  def show
19
- render template: current_page
19
+ render(
20
+ template: current_page,
21
+ locals: { current_page: current_page },
22
+ )
20
23
  end
21
24
 
22
25
  def invalid_page
@@ -2,8 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rspec-rails", "~> 3.2"
7
5
  gem "rails", "~> 4.2.0"
8
6
 
9
7
  gemspec :path => "../"
@@ -2,8 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rspec-rails", "~> 3.2"
7
- gem "rails", "~> 4.0.0"
5
+ gem "rails", "~> 5.0.0"
8
6
 
9
7
  gemspec :path => "../"
@@ -2,8 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "appraisal"
6
- gem "rspec-rails", "~> 3.2"
7
- gem "rails", "~> 4.1.0"
5
+ gem "rails", "~> 5.1.0"
8
6
 
9
7
  gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+
7
+ gemspec :path => "../"
@@ -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("activesupport", ">= 3.1.0")
20
- s.add_development_dependency("pry")
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
- class << self
6
- def matches?(request)
7
- page_id = clean_page_path(request.path)
8
- pattern = file_pattern(page_id)
5
+ def initialize
6
+ @lookup_context = ActionView::LookupContext.new(
7
+ Rails.configuration.paths["app/views"],
8
+ )
9
+ end
9
10
 
10
- Dir.glob(pattern).any?
11
- end
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
- private
17
+ private
14
18
 
15
- def clean_page_path(request_path)
16
- request_path.sub(/\.html$/, "")
17
- end
19
+ attr_reader :lookup_context
18
20
 
19
- def file_pattern(page_id)
20
- "#{content_path}#{page_id}.html*"
21
- end
21
+ def clean_page_path(request_path)
22
+ request_path.sub(/\.html$/, "")
23
+ end
22
24
 
23
- def content_path
24
- Rails.root.join("app", "views", HighVoltage.content_path).to_s
25
- end
25
+ def content_path
26
+ HighVoltage.content_path
26
27
  end
27
28
  end
28
29
  end
@@ -8,17 +8,21 @@ module HighVoltage
8
8
  end
9
9
 
10
10
  def id
11
- file_path.gsub(content_path, "").gsub(html_file_pattern, "")
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? && html?
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.exists?(file_path)
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 html?
37
- !file_path.match(html_file_pattern).nil?
40
+ def handled?
41
+ available_handlers.include? handler_extension
38
42
  end
39
43
 
40
- def html_file_pattern
41
- /\.(html)(\.[a-z]+)?$/
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
- "#{content_path}#{clean_path}"
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
- private
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
 
@@ -8,7 +8,7 @@ module HighVoltage
8
8
  "/*id" => 'high_voltage/pages#show',
9
9
  :as => :page,
10
10
  :format => false,
11
- :constraints => HighVoltage::Constraints::RootRoute
11
+ :constraints => HighVoltage::Constraints::RootRoute.new,
12
12
  }
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module HighVoltage
2
- VERSION = "3.0.0".freeze
2
+ VERSION = "3.1.0".freeze
3
3
  end
@@ -1,36 +1,29 @@
1
1
  require "spec_helper"
2
2
 
3
- describe HighVoltage::Constraints::RootRoute, ".matches?" do
4
- it "returns true when the view file exists" do
5
- request = double(path: 'index')
6
- file_path = Rails.root.join("app", "views", "pages", "index.html*").to_s
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
- allow(Dir).to receive(:glob).with(file_path).and_return(["about.html.erb"])
8
+ result = described_class.new.matches?(request)
9
9
 
10
- result = HighVoltage::Constraints::RootRoute.matches?(request)
10
+ expect(result).to be true
11
+ end
11
12
 
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"])
13
+ it "returns true when the view file exists and url ends with .html" do
14
+ request = double(path: "exists.html")
20
15
 
21
- result = HighVoltage::Constraints::RootRoute.matches?(request)
22
-
23
- expect(result).to be true
24
- end
16
+ result = described_class.new.matches?(request)
25
17
 
26
- it "returns false when the view files does not exist" do
27
- request = double(path: 'index')
28
- file_path = Rails.root.join("app", "views", "pages", "index", ".html*").to_s
18
+ expect(result).to be true
19
+ end
29
20
 
30
- allow(File).to receive(:glob).with(file_path).and_return([])
21
+ it "returns false when the view files does not exist" do
22
+ request = double(path: "index")
31
23
 
32
- result = HighVoltage::Constraints::RootRoute.matches?(request)
24
+ result = described_class.new.matches?(request)
33
25
 
34
- expect(result).to be false
26
+ expect(result).to be false
27
+ end
35
28
  end
36
29
  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
- expect(response).to be_success
9
+ expect(response).to be_successful
10
10
  expect(response).to render_template('rot13')
11
11
  end
12
12
  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 be_success
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 be_success
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 be_success
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 be_success
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe SubclassedPagesController do
4
4
  render_views
5
5
 
6
- describe 'on GET to /subclassed_pages/also_exists' do
7
- before { get :show, :id => 'also_exists' }
6
+ describe "on GET to /subclassed_pages/also_exists" do
7
+ before { get :show, id: "also_exists" }
8
8
 
9
- it 'responds with success and render template' do
10
- expect(response).to be_succes
11
- expect(response).to render_template('also_exists')
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 'uses the custom configured layout' do
15
- expect(response).not_to render_template('layouts/application')
16
- expect(response).to render_template('layouts/alternate')
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: 'invalid' }
22
- .to raise_error(ActionController::RoutingError)
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: '../other/wrong' }
27
- .to raise_error(ActionController::RoutingError)
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: 'also_exists_but_references_nonexistent_partial' }
32
- .to raise_error(ActionView::MissingTemplate)
31
+ expect { get :show, id: "also_exists_but_references_nonexistent_partial" }.
32
+ to raise_error(ActionView::MissingTemplate)
33
33
  end
34
34
  end
@@ -10,6 +10,7 @@ module Dummy
10
10
  config.action_controller.perform_caching = true
11
11
  config.action_controller.cache_store = :memory_store
12
12
  config.root = "spec/fixtures"
13
+ config.paths["app/views"] << "spec/fixtures/app/views"
13
14
  end
14
15
  end
15
16
  Dummy::Application.initialize!
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ feature "current page helper" do
4
+ scenario "is available in view" do
5
+ visit page_path(id: "current_page_helper")
6
+
7
+ expect(page).to have_content "Current Page: pages/current_page_helper"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ feature "view page" do
4
+ scenario "successfully" do
5
+ visit page_path(id: "about")
6
+
7
+ expect(page).to have_content "About Us"
8
+ end
9
+ end
@@ -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 eq [
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
- 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
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 the page_id is just a file extension" do
46
- expect { find("\\√.zip") }.to raise_error HighVoltage::InvalidPageIdError
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 invalid for a text page" do
47
- page = page(full_file_path("text.txt.erb"))
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).to_not be_valid
49
+ expect(page).to be_valid
50
50
  end
51
51
 
52
52
  private
@@ -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, headers = nil)
7
- super(path, params: params, headers: headers)
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.0.0
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: 2016-04-15 00:00:00.000000000 Z
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/rails50.gemfile
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.5.1
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
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rspec-rails", "3.5.0.beta1"
7
- gem "rails", "~> 5.0.0.beta3"
8
- gem "rails-controller-testing"
9
-
10
- gemspec :path => "../"