From ea27bcd960bf824d042fab7b2919f54bfe8dc875 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:17:46 -0700 Subject: [PATCH 1/7] Remove duplicate pry entry in Gemfile It's already in gemspec --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index 70ab496..59ad495 100644 --- a/Gemfile +++ b/Gemfile @@ -27,5 +27,4 @@ end group :test do gem 'rack_session_access' gem 'ammeter' - gem 'pry' end From bf37c45ccb299ae2b3521114d8f3b2540279347b Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:20:28 -0700 Subject: [PATCH 2/7] Enhance travis build matrix for supported Ruby and Rails versions Also enables fast_finish --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index cafa223..4db311b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,21 @@ language: ruby env: - - "RAILS_VERSION=4.0" - - "RAILS_VERSION=4.1" - "RAILS_VERSION=4.2" + - "RAILS_VERSION=5.1" - "RAILS_VERSION=master" rvm: - - 2.1 - 2.2 - - 2.3.1 + - 2.3.6 + - 2.4.3 + - 2.5.0 matrix: + fast_finish: true allow_failures: - env: "RAILS_VERSION=master" exclude: - - rvm: 2.1 - env: RAILS_VERSION=master - rvm: 2.2 env: RAILS_VERSION=master From ce054cd001133b80feba933df565f9d889b22170 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:21:07 -0700 Subject: [PATCH 3/7] Upgrade capybara for Rails 5 support --- two_factor_authentication.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two_factor_authentication.gemspec b/two_factor_authentication.gemspec index d606d6e..a5b886d 100644 --- a/two_factor_authentication.gemspec +++ b/two_factor_authentication.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler' s.add_development_dependency 'rake' s.add_development_dependency 'rspec-rails', '>= 3.0.1' - s.add_development_dependency 'capybara', '2.4.1' + s.add_development_dependency 'capybara', '~> 2.5' s.add_development_dependency 'pry' s.add_development_dependency 'timecop' end From f6b011d33d9d7a526db821b0f1c1467261b7c1f2 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:21:43 -0700 Subject: [PATCH 4/7] Add Rails 5 support to specs - Replace silence_stream with ActiveRecord::Migration.suppress_messages - Resolve rspec-rails changes --- .../two_factor_authentication_controller_spec.rb | 12 ++++++++++-- spec/support/authenticated_model_helper.rb | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/controllers/two_factor_authentication_controller_spec.rb b/spec/controllers/two_factor_authentication_controller_spec.rb index 100876a..d578d0b 100644 --- a/spec/controllers/two_factor_authentication_controller_spec.rb +++ b/spec/controllers/two_factor_authentication_controller_spec.rb @@ -2,6 +2,14 @@ require 'spec_helper' describe Devise::TwoFactorAuthenticationController, type: :controller do describe 'is_fully_authenticated? helper' do + def post_code(code) + if Rails::VERSION::MAJOR >= 5 + post :update, params: { code: code } + else + post :update, code: code + end + end + before do sign_in end @@ -9,7 +17,7 @@ describe Devise::TwoFactorAuthenticationController, type: :controller do context 'after user enters valid OTP code' do it 'returns true' do controller.current_user.send_new_otp - post :update, code: controller.current_user.direct_otp + post_code controller.current_user.direct_otp expect(subject.is_fully_authenticated?).to eq true end end @@ -24,7 +32,7 @@ describe Devise::TwoFactorAuthenticationController, type: :controller do context 'when user enters an invalid OTP' do it 'returns false' do - post :update, code: '12345' + post_code '12345' expect(subject.is_fully_authenticated?).to eq false end diff --git a/spec/support/authenticated_model_helper.rb b/spec/support/authenticated_model_helper.rb index 42696e6..8138dc5 100644 --- a/spec/support/authenticated_model_helper.rb +++ b/spec/support/authenticated_model_helper.rb @@ -29,7 +29,7 @@ module AuthenticatedModelHelper end def create_table_for_nonencrypted_user - silence_stream(STDOUT) do + ActiveRecord::Migration.suppress_messages do ActiveRecord::Schema.define(version: 1) do create_table 'users', force: :cascade do |t| t.string 'email', default: '', null: false From 5bf0aaf114ac1aa4832f35f6e3ef947b002b41d5 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:32:55 -0700 Subject: [PATCH 5/7] Only run Ruby 2.2 against Rails 4 --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4db311b..2a8f296 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ env: - "RAILS_VERSION=master" rvm: - - 2.2 - 2.3.6 - 2.4.3 - 2.5.0 @@ -15,9 +14,9 @@ matrix: fast_finish: true allow_failures: - env: "RAILS_VERSION=master" - exclude: + include: - rvm: 2.2 - env: RAILS_VERSION=master + env: RAILS_VERSION=4.2 before_install: - gem update bundler From 6050115a2c0a9f339f9df216c6518ea6c13ca8d2 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:53:33 -0700 Subject: [PATCH 6/7] Made Rails 5.1 the "default" version of rails in Gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 59ad495..72a62fd 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ rails = case rails_version when "master" {github: "rails/rails"} when "default" - "~> 4.1" + "~> 5.1" else "~> #{rails_version}" end From f677f1fe303f4fc6a57ab074dc38c519eead9268 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Mon, 29 Jan 2018 15:54:02 -0700 Subject: [PATCH 7/7] Normalize migrations between Rails 4 and Rails 5 --- .travis.yml | 2 +- .../20140403184646_devise_create_users.rb | 2 +- ..._two_factor_authentication_add_to_users.rb | 2 +- .../20140407215513_add_nickanme_to_users.rb | 2 +- ...224171231_add_encrypted_columns_to_user.rb | 2 +- .../20151224180310_populate_otp_column.rb | 2 +- ...8230340_remove_otp_secret_key_from_user.rb | 2 +- .../20160209032439_devise_create_admins.rb | 2 +- spec/rails_app/db/schema.rb | 55 +++++++++---------- 9 files changed, 34 insertions(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a8f296..94be5d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,6 @@ before_install: - gem update bundler before_script: - - bundle exec rake app:db:migrate + - bundle exec rake app:db:setup script: bundle exec rake spec diff --git a/spec/rails_app/db/migrate/20140403184646_devise_create_users.rb b/spec/rails_app/db/migrate/20140403184646_devise_create_users.rb index 74adf30..83d51c9 100644 --- a/spec/rails_app/db/migrate/20140403184646_devise_create_users.rb +++ b/spec/rails_app/db/migrate/20140403184646_devise_create_users.rb @@ -1,4 +1,4 @@ -class DeviseCreateUsers < ActiveRecord::Migration +class DeviseCreateUsers < ActiveRecord::Migration[4.2] def change create_table(:users) do |t| ## Database authenticatable diff --git a/spec/rails_app/db/migrate/20140407172619_two_factor_authentication_add_to_users.rb b/spec/rails_app/db/migrate/20140407172619_two_factor_authentication_add_to_users.rb index 5720bb8..e3c2bf6 100644 --- a/spec/rails_app/db/migrate/20140407172619_two_factor_authentication_add_to_users.rb +++ b/spec/rails_app/db/migrate/20140407172619_two_factor_authentication_add_to_users.rb @@ -1,4 +1,4 @@ -class TwoFactorAuthenticationAddToUsers < ActiveRecord::Migration +class TwoFactorAuthenticationAddToUsers < ActiveRecord::Migration[4.2] def up change_table :users do |t| t.string :otp_secret_key diff --git a/spec/rails_app/db/migrate/20140407215513_add_nickanme_to_users.rb b/spec/rails_app/db/migrate/20140407215513_add_nickanme_to_users.rb index ee3fa8f..87f8217 100644 --- a/spec/rails_app/db/migrate/20140407215513_add_nickanme_to_users.rb +++ b/spec/rails_app/db/migrate/20140407215513_add_nickanme_to_users.rb @@ -1,4 +1,4 @@ -class AddNickanmeToUsers < ActiveRecord::Migration +class AddNickanmeToUsers < ActiveRecord::Migration[4.2] def change change_table :users do |t| t.column :nickname, :string, limit: 64 diff --git a/spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb b/spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb index 67f80a6..ba6b528 100644 --- a/spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb +++ b/spec/rails_app/db/migrate/20151224171231_add_encrypted_columns_to_user.rb @@ -1,4 +1,4 @@ -class AddEncryptedColumnsToUser < ActiveRecord::Migration +class AddEncryptedColumnsToUser < ActiveRecord::Migration[4.2] def change add_column :users, :encrypted_otp_secret_key, :string add_column :users, :encrypted_otp_secret_key_iv, :string diff --git a/spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb b/spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb index a51222f..ab34526 100644 --- a/spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb +++ b/spec/rails_app/db/migrate/20151224180310_populate_otp_column.rb @@ -1,4 +1,4 @@ -class PopulateOtpColumn < ActiveRecord::Migration +class PopulateOtpColumn < ActiveRecord::Migration[4.2] def up User.reset_column_information diff --git a/spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb b/spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb index 9ddd608..40ebc07 100644 --- a/spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb +++ b/spec/rails_app/db/migrate/20151228230340_remove_otp_secret_key_from_user.rb @@ -1,4 +1,4 @@ -class RemoveOtpSecretKeyFromUser < ActiveRecord::Migration +class RemoveOtpSecretKeyFromUser < ActiveRecord::Migration[4.2] def change remove_column :users, :otp_secret_key, :string end diff --git a/spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb b/spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb index e598f42..8ec40e4 100644 --- a/spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb +++ b/spec/rails_app/db/migrate/20160209032439_devise_create_admins.rb @@ -1,4 +1,4 @@ -class DeviseCreateAdmins < ActiveRecord::Migration +class DeviseCreateAdmins < ActiveRecord::Migration[4.2] def change create_table(:admins) do |t| ## Database authenticatable diff --git a/spec/rails_app/db/schema.rb b/spec/rails_app/db/schema.rb index 5f01161..02725d0 100644 --- a/spec/rails_app/db/schema.rb +++ b/spec/rails_app/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -14,45 +13,43 @@ ActiveRecord::Schema.define(version: 20160209032439) do create_table "admins", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_admins_on_email", unique: true + t.index ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true end - add_index "admins", ["email"], name: "index_admins_on_email", unique: true - add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "second_factor_attempts_count", default: 0 - t.string "nickname", limit: 64 - t.string "encrypted_otp_secret_key" - t.string "encrypted_otp_secret_key_iv" - t.string "encrypted_otp_secret_key_salt" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "second_factor_attempts_count", default: 0 + t.string "nickname", limit: 64 + t.string "encrypted_otp_secret_key" + t.string "encrypted_otp_secret_key_iv" + t.string "encrypted_otp_secret_key_salt" + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - add_index "users", ["email"], name: "index_users_on_email", unique: true - add_index "users", ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end