Skip to content

Commit 2d96f60

Browse files
authored
Add Rails 6 testing (#161)
- Continue to support Rails 4
1 parent 7384359 commit 2d96f60

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

.travis.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ rvm:
44
- "2.1.10"
55
- "2.2.10"
66
- "2.3.8"
7-
- "2.4.6"
8-
- "2.5.5"
9-
- "2.6.3"
7+
- "2.4.9"
8+
- "2.5.7"
9+
- "2.6.5"
10+
- "2.7.0"
1011
gemfile:
1112
- Gemfile
13+
- spec/support/Gemfile.rails5.2
1214
- spec/support/Gemfile.rails5.1
1315
- spec/support/Gemfile.rails5
1416
- spec/support/Gemfile.rails4
@@ -20,16 +22,28 @@ matrix:
2022
gemfile: spec/support/Gemfile.rails5
2123
- rvm: "2.0.0"
2224
gemfile: spec/support/Gemfile.rails5.1
25+
- rvm: "2.0.0"
26+
gemfile: spec/support/Gemfile.rails5.2
2327
- rvm: "2.1.10"
2428
gemfile: Gemfile
2529
- rvm: "2.1.10"
2630
gemfile: spec/support/Gemfile.rails5
2731
- rvm: "2.1.10"
2832
gemfile: spec/support/Gemfile.rails5.1
33+
- rvm: "2.1.10"
34+
gemfile: spec/support/Gemfile.rails5.2
35+
- rvm: "2.2.10"
36+
gemfile: Gemfile
2937
- rvm: "2.2.10"
38+
gemfile: spec/support/Gemfile.rails5.2
39+
- rvm: "2.3.8"
40+
gemfile: Gemfile
41+
- rvm: "2.4.9"
3042
gemfile: Gemfile
3143
- rvm: "2.6.3"
3244
gemfile: spec/support/Gemfile.rails4
45+
- rvm: "2.7.0"
46+
gemfile: spec/support/Gemfile.rails4
3347

3448
before_install:
3549
- command -v bundle || gem install bundler -v '~> 1.17.3'

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ gemspec
66
group :test do
77
gem 'rake'
88
gem 'rspec', '~> 3.0'
9-
gem 'rails', '~> 5.2'
9+
gem 'rails', '~> 6.0'
1010
gem 'rspec-rails'
11-
gem 'sqlite3', '~> 1.3.6'
11+
gem 'sqlite3', '~> 1.4.0'
1212
gem 'capybara'
1313
gem 'poltergeist'
1414

spec/controllers/devise/saml_sessions_controller_spec.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
require 'rails_helper'
22

3-
class Devise::SessionsController < ActionController::Base
3+
# The important parts from devise
4+
class DeviseController < ApplicationController
45
attr_accessor :current_user
56

6-
# The important parts from devise
77
def resource_class
88
User
99
end
1010

11+
def require_no_authentication
12+
end
13+
end
14+
class Devise::SessionsController < DeviseController
1115
def destroy
1216
sign_out
1317
redirect_to after_sign_out_path_for(:user)
1418
end
1519

16-
def require_no_authentication
20+
def verify_signed_out_user
21+
# no-op for these tests
1722
end
1823
end
1924

@@ -23,6 +28,7 @@ def require_no_authentication
2328
let(:idp_providers_adapter) { spy("Stub IDPSettings Adaptor") }
2429

2530
before do
31+
@request.env["devise.mapping"] = Devise.mappings[:user]
2632
allow(idp_providers_adapter).to receive(:settings).and_return({
2733
assertion_consumer_service_url: "acs_url",
2834
assertion_consumer_service_binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
@@ -36,6 +42,20 @@ def require_no_authentication
3642
})
3743
end
3844

45+
before do
46+
if Rails::VERSION::MAJOR < 5 && Gem::Version.new(RUBY_VERSION) > Gem::Version.new("2.6")
47+
# we still want to support Rails 4
48+
# patch tests using snippet from https://github.com/rails/rails/issues/34790#issuecomment-483607370
49+
class ActionController::TestResponse < ActionDispatch::TestResponse
50+
def recycle!
51+
@mon_mutex_owner_object_id = nil
52+
@mon_mutex = nil
53+
initialize
54+
end
55+
end
56+
end
57+
end
58+
3959
describe '#new' do
4060
let(:saml_response) { File.read(File.join(File.dirname(__FILE__), '../../support', 'response_encrypted_nameid.xml.base64')) }
4161

spec/support/Gemfile.rails5.2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in devise_saml_authenticatable.gemspec
4+
gemspec path: '../..'
5+
6+
group :test do
7+
gem 'rake'
8+
gem 'rspec', '~> 3.0'
9+
gem 'rails', '~> 5.2'
10+
gem 'rspec-rails'
11+
gem 'sqlite3', '~> 1.3.6'
12+
gem 'capybara'
13+
gem 'poltergeist'
14+
15+
# Lock down versions of gems for older versions of Ruby
16+
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("2.4")
17+
gem 'responders', '~> 2.4'
18+
end
19+
end

spec/support/sp_template.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
end
2828
GEMFILE
2929
}
30-
# sqlite3 is hard-coded in Rails to v1.3.x
31-
gsub_file 'Gemfile', /^gem 'sqlite3'.*$/, "gem 'sqlite3', '~> 1.3.6'"
30+
if Rails::VERSION::MAJOR < 6
31+
# sqlite3 is hard-coded in Rails < 6 to v1.3.x
32+
gsub_file 'Gemfile', /^gem 'sqlite3'.*$/, "gem 'sqlite3', '~> 1.3.6'"
33+
end
3234

3335
template File.expand_path('../idp_settings_adapter.rb.erb', __FILE__), 'app/lib/idp_settings_adapter.rb'
3436

@@ -107,7 +109,12 @@ def self.entity_id(params)
107109
end
108110
CONFIG
109111

110-
generate :devise, "user", "email:string", "name:string", "session_index:string"
112+
if Rails::VERSION::MAJOR < 6
113+
generate :devise, "user", "email:string", "name:string", "session_index:string"
114+
else
115+
# devise seems to add `email` by default in Rails 6
116+
generate :devise, "user", "name:string", "session_index:string"
117+
end
111118
gsub_file 'app/models/user.rb', /database_authenticatable.*\n.*/, 'saml_authenticatable'
112119
route "resources :users, only: [:create]"
113120
create_file('app/controllers/users_controller.rb', <<-USERS)

0 commit comments

Comments
 (0)