Skip to content

Commit ff8b3d7

Browse files
authored
Rails 7 support (#91)
1 parent ea48ce2 commit ff8b3d7

File tree

7 files changed

+86
-7
lines changed

7 files changed

+86
-7
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
jobs:
44
bundle:
55
docker:
6-
- image: circleci/ruby:2.7.1
6+
- image: circleci/ruby:2.7.5
77
working_directory: /mnt/ramdisk
88
steps:
99
- checkout
@@ -13,7 +13,7 @@ jobs:
1313
- run:
1414
name: bundle install
1515
command: |
16-
gem install bundler -v '2.1.4'
16+
gem install bundler -v '2.3.4'
1717
bundle install --path=vendor/bundle --jobs=4 --retry=3
1818
- save_cache:
1919
key: bundler-{{ checksum "diffcrypt.gemspec" }}-{{ .Environment.CACHE_VERSION }}
@@ -22,7 +22,7 @@ jobs:
2222

2323
test:
2424
docker:
25-
- image: circleci/ruby:2.7.1
25+
- image: circleci/ruby:2.7.5
2626
working_directory: /mnt/ramdisk
2727
steps:
2828
- checkout
@@ -32,7 +32,7 @@ jobs:
3232
- run:
3333
name: bundle install
3434
command: |
35-
gem install bundler -v '2.1.4'
35+
gem install bundler -v '2.3.4'
3636
bundle install --path=vendor/bundle --jobs=4 --retry=3
3737
- run:
3838
name: Setup Code Climate test-reporter
@@ -48,7 +48,7 @@ jobs:
4848
./cc-test-reporter after-build --coverage-input-type lcov --exit-code $?
4949
rubocop:
5050
docker:
51-
- image: circleci/ruby:2.7.1
51+
- image: circleci/ruby:2.7.5
5252
working_directory: /mnt/ramdisk
5353
steps:
5454
- checkout
@@ -58,7 +58,7 @@ jobs:
5858
- run:
5959
name: bundle install
6060
command: |
61-
gem install bundler -v '2.1.4'
61+
gem install bundler -v '2.3.4'
6262
bundle install --path=vendor/bundle --jobs=4 --retry=3
6363
- run:
6464
name: rubocop

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Style/Documentation:
99
Enabled: false
1010
Metrics/MethodLength:
1111
Exclude:
12+
- test/*_test.rb
13+
- test/**/*_test.rb
14+
Naming/VariableNumber:
15+
Exclude:
16+
- test/*_test.rb
1217
- test/**/*_test.rb
1318
Style/TrailingCommaInArrayLiteral:
1419
EnforcedStyleForMultiline: consistent_comma
@@ -21,4 +26,5 @@ Style/AccessorGrouping:
2126

2227
Layout/LineLength:
2328
Exclude:
29+
- test/*_test.rb
2430
- test/**/*_test.rb

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source 'https://rubygems.org'
66
gemspec
77

88
gem 'minitest', '~> 5.0'
9+
gem 'minitest-reporters', '~> 1.4.3'
910
gem 'rake', '~> 13.0'
1011
gem 'rubocop', '~> 1.17.0'
1112
gem 'simplecov', '~> 0.21.2', require: false # CodeClimate not compatible with 0.18+ yet - https://github.com/codeclimate/test-reporter/issues/413

diffcrypt.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
2929
spec.executables = %w[diffcrypt]
3030
spec.require_paths = ['lib']
3131

32-
spec.add_runtime_dependency 'activesupport', '>= 6.0', '< 6.2'
32+
spec.add_runtime_dependency 'activesupport', '>= 6.0', '< 7.1'
3333
spec.add_runtime_dependency 'thor', '>= 0.20', '< 2'
3434
end

lib/diffcrypt/rails/encrypted_configuration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require 'pathname'
55
require 'tmpdir'
66

7+
require 'active_support/isolated_execution_state' if Gem.loaded_specs['activesupport'].version.to_s.index('7.')&.zero?
8+
79
require 'active_support/ordered_options'
810
require 'active_support/core_ext/hash'
911
require 'active_support/core_ext/module/delegation'

test/rails_test.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
4+
require 'bundler'
5+
6+
require 'open3'
7+
8+
RAILS_VERSIONS = %w[
9+
6.0.4.4
10+
6.1.4.4
11+
7.0.0
12+
].freeze
13+
14+
RAILS_FLAGS = %w[
15+
--api
16+
--skip-action-cable
17+
--skip-active-storage
18+
--skip-bundle
19+
--skip-git
20+
--skip-javascript
21+
--skip-keeps
22+
--skip-system-test
23+
--skip-test
24+
].freeze
25+
26+
TMP_RAILS_ROOT = File.join(__dir__, '../tmp/test')
27+
28+
# Helper to ensure we raise if command is not successful
29+
def run_command(*command)
30+
stdout, stderr, status = Open3.capture3(*command)
31+
if status.success? == false
32+
errors = [
33+
" Command Failed: #{command.join(' ')}",
34+
stdout.split("\n").map { |line| " #{line}" }.join("\n"),
35+
stderr.split("\n").map { |line| " #{line}" }.join("\n"),
36+
]
37+
raise errors.join("\n")
38+
end
39+
40+
[stdout, stderr, status]
41+
end
42+
43+
class RailsTest < Minitest::Test
44+
def setup
45+
FileUtils.mkdir_p(TMP_RAILS_ROOT) unless Dir.exist?(TMP_RAILS_ROOT)
46+
end
47+
48+
RAILS_VERSIONS.each do |rails_version|
49+
define_method "test_that_rails_#{rails_version.gsub('.', '_')}_works" do
50+
Bundler.with_unbundled_env do
51+
Dir.chdir(TMP_RAILS_ROOT) do
52+
tmp_version_root = "rails_#{rails_version.gsub('.', '_')}"
53+
FileUtils.remove_dir(tmp_version_root) if Dir.exist?(tmp_version_root)
54+
run_command('gem', 'install', 'rails', '--version', rails_version)
55+
run_command('rails', "_#{rails_version}_", 'new', *RAILS_FLAGS, tmp_version_root)
56+
Dir.chdir(tmp_version_root) do
57+
File.write('Gemfile', "gem 'diffcrypt', path: '../../..'", mode: 'a')
58+
run_command('bundle', 'install')
59+
stdout, _stderr, _status = run_command('bundle', 'exec', 'rails', 'r', 'puts Rails.version')
60+
assert_equal rails_version, stdout.strip
61+
end
62+
end
63+
end
64+
end
65+
end
66+
end

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
TEST_KEY_128 = ::File.read("#{__dir__}/fixtures/aes-128-gcm.key").strip
2525
TEST_KEY_256 = ::File.read("#{__dir__}/fixtures/aes-256-gcm.key").strip
2626

27+
# Custom test output
28+
require 'minitest/reporters'
29+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
30+
2731
require 'minitest/autorun'

0 commit comments

Comments
 (0)