Skip to content

Commit 7a75178

Browse files
committed
Bring back support for ruby 1.9
1 parent a43eecf commit 7a75178

File tree

15 files changed

+81
-44
lines changed

15 files changed

+81
-44
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ jobs:
88
matrix:
99
# lockfiles are not commited, so autodetection will not work, need to specify bundler version
1010
include:
11-
- ruby-version: 2.3.8
11+
- ruby-version: 1.9.3
1212
rails-version: 3
13-
bundler-version: 1.17.3
13+
bundler-version: "1.17.3"
14+
1415
- ruby-version: 2.3.8
1516
rails-version: 40
16-
bundler-version: 1.17.3
17+
bundler-version: "1.17.3"
1718
- ruby-version: 2.3.8
1819
rails-version: 42
19-
bundler-version: 1.17.3
20+
bundler-version: "1.17.3"
2021

2122
- ruby-version: 2.3.8
2223
rails-version: 50_rspec
@@ -36,8 +37,14 @@ jobs:
3637

3738
steps:
3839
- uses: actions/checkout@master
40+
- name: Disable broken ssl for legacy ruby
41+
run: |
42+
echo :ssl_verify_mode: 0 >> ~/.gemrc
43+
echo gem: --no-ri --no-rdoc >> ~/.gemrc
44+
echo "RUBYGEMS_HOST=http://rubygems.org" >> $GITHUB_ENV
45+
if: matrix.ruby-version == '1.9.3'
3946
- name: Install ruby
40-
uses: ruby/setup-ruby@v1
47+
uses: ruby/setup-ruby@master
4148
with:
4249
ruby-version: ${{ matrix.ruby-version }}
4350
bundler-cache: true

Appraisals

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
if RUBY_VERSION <= '2.4'
66
# to get a working ruby 2.3: `docker run --rm -it --volume $PWD:/app ruby:2.3-stretch bash`
7+
# to get a working ruby 1.9: `docker run --rm -it --volume $PWD:/app ruby:1.9.3-wheezy bash`
78
appraise 'rails-3' do
89
gem 'rails', '~>3.2.22'
910
gem 'test-unit'
11+
# helping old bundler with correct versions with support for ruby 1.9:
12+
if RUBY_VERSION < '2'
13+
gem 'rake', '~> 11.3'
14+
gem 'concurrent-ruby', '1.1.9'
15+
gem 'rack-cache', '1.7.0'
16+
gem 'thor', '0.20.3'
17+
gem 'appraisal', '2.2.0'
18+
gem 'minitest', '5.11.3'
19+
end
1020
end
1121

1222
appraise 'rails-40' do

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
-
5+
- Bring back support for ruby 1.9
66

77
## 0.7.0 - April 24, 2022
88
- Support for Rails 7 (added tests, main code was already working)

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Rake::TestTask.new(:dummytest_controller) { |t| t.pattern = 'spec/fixtures/dummy
2020

2121
task default: :spec
2222

23-
$LOAD_PATH.push File.expand_path('lib', __dir__)
23+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
2424
require 'routes_coverage/version'
2525

2626
namespace :assets do

gemfiles/rails_3.gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ source "https://rubygems.org"
44

55
gem "rails", "~>3.2.22"
66
gem "test-unit"
7+
gem 'rake', '~> 11.3'
8+
gem 'concurrent-ruby', '1.1.9'
9+
gem 'rack-cache', '1.7.0'
10+
gem 'thor', '0.20.3'
11+
gem 'appraisal', '2.2.0'
12+
gem 'minitest', '5.11.3'
713

814
gemspec path: "../"

lib/routes_coverage.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ def process(action, *args)
1919
end
2020

2121
module ActionControllerTestCaseKvargs
22-
def process(action, **kvargs)
23-
return super unless RoutesCoverage.settings.include_from_controller_tests
22+
if RUBY_VERSION >= '2'
23+
class_eval <<-RUBY, __FILE__, __LINE__+1
24+
def process(action, **kvargs)
25+
return super unless RoutesCoverage.settings.include_from_controller_tests
2426
25-
super.tap { RoutesCoverage._touch_request(@request) }
27+
super.tap { RoutesCoverage._touch_request(@request) }
28+
end
29+
RUBY
2630
end
2731
end
2832

@@ -154,7 +158,7 @@ def self._collect_all_routes
154158
end
155159

156160
def self._collect_route_groups(all_routes)
157-
settings.groups.map do |group_name, matcher|
161+
Hash[settings.groups.map do |group_name, matcher|
158162
group_routes = all_routes.select do |route|
159163
if matcher.respond_to?(:call)
160164
matcher.call(route)
@@ -164,9 +168,9 @@ def self._collect_route_groups(all_routes)
164168
when :path
165169
route.path.spec.to_s =~ value
166170
when :action
167-
route.requirements[:action]&.match(value)
171+
route.requirements[:action] && route.requirements[:action].match(value)
168172
when :controller
169-
route.requirements[:controller]&.match(value)
173+
route.requirements[:controller] && route.requirements[:controller].match(value)
170174
when :constraints
171175
value.all? do |constraint_name, constraint_value|
172176
if constraint_value.present?
@@ -183,7 +187,7 @@ def self._collect_route_groups(all_routes)
183187
end
184188

185189
[group_name, Result.new(group_routes, route_hit_count.slice(*group_routes), settings)]
186-
end.to_h
190+
end]
187191
end
188192

189193
# NB: router changes env/request during recognition

lib/routes_coverage/auditor.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def existing_actions_usage_hash
5555
controller_name = controller.name.sub(/Controller$/, "").underscore
5656
controller.action_methods.map { |action| "#{controller_name}##{action}" }
5757
end
58-
controller_actions.flatten.map { |action| [action, 0] }.to_h
58+
Hash[controller_actions.flatten.map { |action| [action, 0] }]
5959
end
6060
end
6161

@@ -78,8 +78,9 @@ def perform
7878
existing_actions_usage_hash[action] += 1
7979
else
8080
# there may be inheritance or implicit renders
81-
controller_instance = controller_class_by_name(route.requirements[:controller])&.new
82-
unless controller_instance&.available_action?(route.requirements[:action])
81+
controller_class = controller_class_by_name(route.requirements[:controller])
82+
controller_instance = controller_class && controller_class.new
83+
unless controller_instance && controller_instance.available_action?(route.requirements[:action])
8384
if controller_instance.respond_to?(route.requirements[:action])
8485
logger.warn "No action, but responds: #{action}"
8586
end
@@ -101,14 +102,15 @@ def unused_actions
101102
@unused_actions ||= begin
102103
# methods with special suffixes are obviously not actions, reduce noise:
103104
unused_actions_from_hash = existing_actions_usage_hash.reject do |action, count|
104-
count.positive? || action.end_with?('?') || action.end_with?('!') || action.end_with?('=')
105+
count > 0 || action.end_with?('?') || action.end_with?('!') || action.end_with?('=')
105106
end
106107

107108
unused_actions_from_hash.keys.map do |action|
108109
controller_name, action_name = action.split('#', 2)
109-
controller = controller_class_by_name(controller_name)&.new
110-
method = controller.method(action_name.to_sym)
111-
if method&.source_location && method.source_location.first.start_with?(root)
110+
controller_class = controller_class_by_name(controller_name)
111+
controller = controller_class && controller_class.new
112+
method = controller && controller.method(action_name.to_sym)
113+
if method && method.source_location && method.source_location.first.start_with?(root)
112114
"#{method.source_location.first.sub(root, '')}:#{method.source_location.second} - #{action}"
113115
else
114116
action

lib/routes_coverage/formatters/full_text.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ class FullText < SummaryText
66
class RouteFormatter
77
attr_reader :buffer
88

9-
def initialize(result = nil, _settings = nil, output_hits: false)
9+
def initialize(result = nil, _settings = nil)
1010
@buffer = []
1111
@result = result
12-
@output_hits = output_hits
12+
@output_hits = false
1313
@output_prefix = false
1414
end
1515

16+
def with_hits
17+
@output_hits = true
18+
self
19+
end
20+
1621
def result
1722
@buffer.join("\n")
1823
end
@@ -63,7 +68,7 @@ def draw_header(routes)
6368
end
6469

6570
def widths(routes)
66-
%i[name verb path reqs].map do |key|
71+
[:name, :verb, :path, :reqs].map do |key|
6772
routes.map { |r| r[key].length }.max.to_i
6873
end
6974
end
@@ -94,11 +99,9 @@ def hit_routes_details
9499
hit_routes = collect_routes(result.hit_routes)
95100
pending_routes = collect_routes(result.pending_routes)
96101

97-
<<~TXT
98-
#{routes_section(RouteFormatter.new(result, settings, output_hits: true), 'Covered routes:', hit_routes)}
99-
100-
#{routes_section(RouteFormatter.new(result, settings), 'Pending routes:', pending_routes)}
101-
TXT
102+
"#{routes_section(RouteFormatter.new(result, settings).with_hits, 'Covered routes:', hit_routes)}\n"\
103+
"\n"\
104+
"#{routes_section(RouteFormatter.new(result, settings), 'Pending routes:', pending_routes)}"
102105
end
103106

104107
def format

lib/routes_coverage/formatters/html.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def project_name
5555
end
5656

5757
def asset_content(name)
58-
File.read(File.expand_path("../../../compiled_assets/#{name}", __dir__))
58+
File.read(File.expand_path("../../../../compiled_assets/#{name}", __FILE__))
5959
end
6060

6161
def style_asset_link
@@ -87,7 +87,7 @@ def strength_css_class(covered_strength)
8787
end
8888

8989
def hits_css_class(hits)
90-
hits.positive? ? 'cov' : 'uncov'
90+
hits > 0 ? 'cov' : 'uncov'
9191
end
9292

9393
def timeago(time)

lib/routes_coverage/formatters/summary_text.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SummaryText < Base
66
def hits_count(result)
77
"#{result.hit_routes_count} of #{result.expected_routes_count}"\
88
"#{"(#{result.total_count} total)" if result.expected_routes_count != result.total_count}"\
9-
" routes hit#{" at #{result.avg_hits} hits average" if result.hit_routes_count.positive?}"
9+
" routes hit#{" at #{result.avg_hits} hits average" if result.hit_routes_count > 0}"
1010
end
1111

1212
def status

0 commit comments

Comments
 (0)