Skip to content

Commit

Permalink
Rails 5.2 support (#129)
Browse files Browse the repository at this point in the history
* Rails 5.2 support

* Fix specs for Rails 4
  • Loading branch information
akhiln authored and Ch4s3 committed Jun 20, 2018
1 parent ba45f18 commit 8f3cb2d
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'rails', '~> 5.1.0'
gem 'rails', '~> 5.2.0'
gem 'rails-controller-testing'
gem 'sqlite3'
gem 'pry'
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/sorcery/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def inject_sorcery_to_model
# Copy the migrations files to db/migrate folder
def copy_migration_files
# Copy core migration file in all cases except when you pass --only-submodules.
return unless defined?(Sorcery::Generators::InstallGenerator::ActiveRecord)
return unless defined?(ActiveRecord)
migration_template 'migration/core.rb', 'db/migrate/sorcery_core.rb', migration_class_name: migration_class_name unless only_submodules?

if submodules
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_activation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

describe User, 'with activation submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
end

it_behaves_like 'rails_3_activation_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_activity_logging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with activity logging submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activity_logging")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activity_logging")
end

it_behaves_like 'rails_3_activity_logging_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_brute_force_protection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with brute_force_protection submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/brute_force_protection")
MigrationHelper.migrate("#{Rails.root}/db/migrate/brute_force_protection")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/brute_force_protection")
MigrationHelper.rollback("#{Rails.root}/db/migrate/brute_force_protection")
end

it_behaves_like 'rails_3_brute_force_protection_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_magic_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with magic_login submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/magic_login")
MigrationHelper.migrate("#{Rails.root}/db/migrate/magic_login")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/magic_login")
MigrationHelper.rollback("#{Rails.root}/db/migrate/magic_login")
end

it_behaves_like 'magic_login_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with oauth submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
end

it_behaves_like 'rails_3_oauth_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_remember_me_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with remember_me submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/remember_me")
MigrationHelper.migrate("#{Rails.root}/db/migrate/remember_me")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/remember_me")
MigrationHelper.rollback("#{Rails.root}/db/migrate/remember_me")
end

it_behaves_like 'rails_3_remember_me_model'
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/user_reset_password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

describe User, 'with reset_password submodule', active_record: true do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/reset_password")
MigrationHelper.migrate("#{Rails.root}/db/migrate/reset_password")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/reset_password")
MigrationHelper.rollback("#{Rails.root}/db/migrate/reset_password")
end

it_behaves_like 'rails_3_reset_password_model'
Expand Down
10 changes: 0 additions & 10 deletions spec/active_record/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
it_should_behave_like 'rails_3_core_model'

describe 'external users' do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
User.reset_column_information
sorcery_reload!
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
end

it_should_behave_like 'external_user'
end
end
2 changes: 1 addition & 1 deletion spec/controllers/controller_http_basic_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }

expect(response).to be_a_success
expect(response).to be_successful
end

it 'fails authentication if credentials are wrong' do
Expand Down
26 changes: 6 additions & 20 deletions spec/controllers/controller_oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
describe SorceryController, active_record: true, type: :controller do
before(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activity_logging")
User.reset_column_information
end

Expand All @@ -15,7 +17,9 @@

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activity_logging")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
end
end

Expand Down Expand Up @@ -196,10 +200,6 @@

describe 'OAuth with User Activation features' do
before(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
end

sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft])

Expand Down Expand Up @@ -236,13 +236,6 @@
sorcery_controller_external_property_set(:microsoft, :callback_url, "http://blabla.com")
end

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
end
end

after(:each) do
User.sorcery_adapter.delete_all
end
Expand Down Expand Up @@ -286,13 +279,6 @@
sorcery_reload!([:activity_logging, :external])
end

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
end
end

%w(facebook github google liveid vk salesforce slack).each do |provider|
context "when #{provider}" do
before(:each) do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/controller_oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def stub_all_oauth_requests!
describe SorceryController, 'OAuth with session timeout features' do
before(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
User.reset_column_information
end

Expand All @@ -224,7 +224,7 @@ def stub_all_oauth_requests!

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/controller_session_timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
get :test_should_be_logged_in

expect(session[:user_id]).not_to be_nil
expect(response).to be_a_success
expect(response).to be_successful
end

it 'resets session after session timeout' do
Expand All @@ -44,7 +44,7 @@
get :test_login, params: { email: 'bla@bla.com', password: 'secret' }

expect(session[:user_id]).not_to be_nil
expect(response).to be_a_success
expect(response).to be_successful
end

context "with 'session_timeout_from_last_action'" do
Expand All @@ -62,7 +62,7 @@
get :test_should_be_logged_in

expect(session[:user_id]).not_to be_nil
expect(response).to be_a_success
expect(response).to be_successful
end

it "with 'session_timeout_from_last_action' logs out if there was no activity" do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
sorcery_controller_property_set(:not_authenticated_action, :test_not_authenticated_action)
get :test_logout

expect(response).to be_a_success
expect(response).to be_successful
end

it 'require_login before_action saves the url that the user originally wanted' do
Expand Down
4 changes: 2 additions & 2 deletions spec/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TestUser < ActiveRecord::Base
end

def setup_orm
ActiveRecord::Migrator.migrate(migrations_path)
MigrationHelper.migrate(migrations_path)
end

def teardown_orm
ActiveRecord::Migrator.rollback(migrations_path)
MigrationHelper.rollback(migrations_path)
end

def migrations_path
Expand Down
4 changes: 3 additions & 1 deletion spec/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class Application < Rails::Application
config.filter_parameters += [:password]

config.action_mailer.delivery_method = :test

config.active_support.deprecation = :stderr
if Rails.version >= '5.1.0' && config.active_record.sqlite3.present?
config.active_record.sqlite3.represent_boolean_as_integer = true
end
end
end
7 changes: 0 additions & 7 deletions spec/rails_app/config/initializers/secret_token.rb

This file was deleted.

4 changes: 4 additions & 0 deletions spec/rails_app/config/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# secrets.yml

test:
secret_key_base: 'a9789f869a0d0ac2f2b683d6e9410c530696b178bca28a7971f4a652b14ff2da89f2cf4dcbf0355f6bc41f81731aa8e46085674d1acc1980436f61cdba76ff5d'
49 changes: 20 additions & 29 deletions spec/shared_examples/user_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,12 @@ class Admin2 < User; end

describe 'generic send email' do
before(:all) do
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
User.reset_column_information
end

after(:all) do
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
end

before do
Expand Down Expand Up @@ -518,6 +518,21 @@ def self.matches?(crypted, *tokens)
let(:user) { create_new_user }
let(:external_user) { create_new_external_user :twitter }

before(:all) do
if SORCERY_ORM == :active_record
MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
end
sorcery_reload!
end

after(:all) do
if SORCERY_ORM == :active_record
MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
end
end

before(:each) do
User.sorcery_adapter.delete_all
end
Expand All @@ -535,24 +550,12 @@ def self.matches?(crypted, *tokens)
end

describe '.create_from_provider' do
before(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
User.reset_column_information
end

before(:each) do
sorcery_reload!([:external])
end

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
end
sorcery_model_property_set(:authentications_class, Authentication)
end

it 'supports nested attributes' do
sorcery_model_property_set(:authentications_class, Authentication)

expect do
User.create_from_provider('facebook', '123', username: 'Noam Ben Ari')
end.to change { User.count }.by(1)
Expand All @@ -576,22 +579,10 @@ def self.matches?(crypted, *tokens)
end

describe 'activation' do
before(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
end

before(:each) do
sorcery_reload!([:user_activation, :external], user_activation_mailer: ::SorceryMailer)
end

after(:all) do
if SORCERY_ORM == :active_record
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
end
end

after(:each) do
User.sorcery_adapter.delete_all
end
Expand Down
Loading

0 comments on commit 8f3cb2d

Please sign in to comment.