Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup appraisal for rails 4 #1142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rvm:
- 2.5.0

gemfile:
- gemfiles/rails_4_2.gemfile
- gemfiles/rails_5_0.gemfile
- gemfiles/rails_5_1.gemfile

Expand Down
10 changes: 10 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[
{ name: '4-2', version: '4.2.10' }
].each do |rails|
appraise "rails-#{rails[:name]}" do
gem "mysql2", "~> 0.4.10"
gem "pg", "~> 0.21"
gem "rails", "~> #{rails[:version]}"
end
end

[
{ name: '5-0', version: '5.0.7' },
{ name: '5-1', version: '5.1.6' },
Expand Down
39 changes: 39 additions & 0 deletions gemfiles/rails_4_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mysql2", "~> 0.4.10"
gem "pg", "~> 0.21"
gem "rails", "~> 4.2.10"

group :development, :test do
gem "attr_encrypted"
gem "figaro", git: "https://github.com/laserlemon/figaro"
gem "omniauth-facebook", git: "https://github.com/mkdynamic/omniauth-facebook"
gem "omniauth-github", git: "https://github.com/intridea/omniauth-github"
gem "omniauth-google-oauth2", git: "https://github.com/zquestz/omniauth-google-oauth2"
gem "rack-cors", require: "rack/cors"
gem "thor"
gem "faker"
gem "fuzz_ball"
gem "guard"
gem "guard-minitest"
gem "minitest"
gem "minitest-focus"
gem "minitest-rails"
gem "minitest-reporters"
gem "mocha"
gem "pry"
gem "pry-remote"
end

group :test do
gem "codeclimate-test-reporter", require: nil
gem "rails-controller-testing"
end

group :development do
gem "github_changelog_generator"
end

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_parsed_data_json
expiry = controller.auth_params[:expiry]

# the expiry should have been set
assert_equal expiry, @resource.tokens[client_id]['expiry']
assert_equal expiry, @resource.tokens[client_id]['expiry'] || @resource.tokens[client_id][:expiry]

# the token sent down to the client should now be valid
assert @resource.valid_token?(token, client_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration
@resource = assigns(:resource)
@data = JSON.parse(response.body)
@mail = ActionMailer::Base.deliveries.last
@sent_redirect_url = URI.decode(@mail.body.match(/redirect_url=([^&]*)(&|\")/)[1])
@sent_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)(&|\")/)[1])
end

teardown do
Expand Down
12 changes: 12 additions & 0 deletions test/dummy/lib/migration_database_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# polyfill Rails >= 5 versioned migrations

unless ActiveRecord::Migration.respond_to?(:[])
module ActiveRecord
class Migration
def self.[](_version)
self
end
end
end
end

module MigrationDatabaseHelper
def json_supported_database?
(postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?)
Expand Down
4 changes: 2 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ def @resource.token_lifespan
assert @resource.token_is_current?(@token_global, @client_id_global)

time = Time.zone.now.to_i
expiry_global = @resource.tokens[@client_id_global]['expiry']
expiry_global = @resource.tokens[@client_id_global]['expiry'] || @resource.tokens[@client_id_global][:expiry]

assert expiry_global > time + DeviseTokenAuth.token_lifespan - 5.seconds
assert expiry_global < time + DeviseTokenAuth.token_lifespan + 5.seconds

expiry_specific = @resource.tokens[@client_id_specific]['expiry']
expiry_specific = @resource.tokens[@client_id_specific]['expiry'] || @resource.tokens[@client_id_specific][:expiry]
assert expiry_specific > time + 55.seconds
assert expiry_specific < time + 65.seconds
end
Expand Down
25 changes: 25 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,28 @@ class ActionController::TestCase
@request.env['devise.mapping'] = Devise.mappings[:user]
end
end

# TODO: remove it when support for Rails < 5 has been dropped
module Rails
module Controller
module Testing
module Integration
%w[get post patch put head delete get_via_redirect post_via_redirect].each do |method|
define_method(method) do |path_or_action, **args|
if Rails::VERSION::MAJOR >= 5
super path_or_action, args
else
super path_or_action, args[:params], args[:headers]
end
end
end
end
end
end
end

module ActionController
class TestCase
include Rails::Controller::Testing::Integration
end
end