Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #188 from natebird/rails5_deprecation_fixes
Browse files Browse the repository at this point in the history
Rails5 deprecation fixes
  • Loading branch information
Mario Manno authored Aug 30, 2016
2 parents 012b55a + fdedcd1 commit b2ee978
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 74 deletions.
90 changes: 46 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,51 @@ PATH
specs:
devise_security_extension (0.10.0)
devise (>= 3.0.0, < 5.0)
railties (>= 3.2.6, < 5.0)
railties (>= 3.2.6, < 6.0)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.5.1)
actionpack (= 4.2.5.1)
actionview (= 4.2.5.1)
activejob (= 4.2.5.1)
actionmailer (4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.5.1)
actionview (= 4.2.5.1)
activesupport (= 4.2.5.1)
actionpack (4.2.6)
actionview (= 4.2.6)
activesupport (= 4.2.6)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.5.1)
activesupport (= 4.2.5.1)
actionview (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.5.1)
activesupport (= 4.2.5.1)
activejob (4.2.6)
activesupport (= 4.2.6)
globalid (>= 0.3.0)
activemodel (4.2.5.1)
activesupport (= 4.2.5.1)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activerecord (4.2.5.1)
activemodel (= 4.2.5.1)
activesupport (= 4.2.5.1)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
arel (~> 6.0)
activesupport (4.2.5.1)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
ast (2.2.0)
ast (2.3.0)
bcrypt (3.1.11)
builder (3.2.2)
concurrent-ruby (1.0.0)
concurrent-ruby (1.0.2)
coveralls (0.8.13)
json (~> 1.8)
simplecov (~> 0.11.0)
Expand Down Expand Up @@ -76,32 +76,34 @@ GEM
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.99.1)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
orm_adapter (0.5.0)
parser (2.3.0.6)
parser (2.3.1.2)
ast (~> 2.2)
pkg-config (1.1.7)
powerpack (0.1.1)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.5.1)
actionmailer (= 4.2.5.1)
actionpack (= 4.2.5.1)
actionview (= 4.2.5.1)
activejob (= 4.2.5.1)
activemodel (= 4.2.5.1)
activerecord (= 4.2.5.1)
activesupport (= 4.2.5.1)
rails (4.2.6)
actionmailer (= 4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
activemodel (= 4.2.6)
activerecord (= 4.2.6)
activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.5.1)
railties (= 4.2.6)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
Expand All @@ -113,17 +115,17 @@ GEM
loofah (~> 2.0)
rails_email_validator (0.1.4)
activemodel (>= 3.0.0)
railties (4.2.5.1)
actionpack (= 4.2.5.1)
activesupport (= 4.2.5.1)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.2.2)
responders (2.2.0)
railties (>= 4.2.0, < 5.1)
rmagick (2.15.4)
rspec-core (3.4.3)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -140,22 +142,22 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.37.2)
parser (>= 2.3.0.4, < 3.0)
rubocop (0.40.0)
parser (>= 2.3.1.0, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 0.3)
ruby-progressbar (1.7.5)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
simplecov (0.11.2)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
sprockets (3.5.2)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.3)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand All @@ -167,7 +169,7 @@ GEM
tins (1.6.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicode-display_width (0.3.1)
unicode-display_width (1.0.5)
warden (1.2.6)
rack (>= 1.0)
yard (0.8.7.6)
Expand Down
2 changes: 1 addition & 1 deletion devise_security_extension.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.1.0'

s.add_runtime_dependency 'railties', '>= 3.2.6', '< 5.0'
s.add_runtime_dependency 'railties', '>= 3.2.6', '< 6.0'
s.add_runtime_dependency 'devise', '>= 3.0.0', '< 5.0'
s.add_development_dependency 'bundler', '>= 1.3.0', '< 2.0'
s.add_development_dependency 'sqlite3', '~> 1.3.10'
Expand Down
6 changes: 3 additions & 3 deletions lib/devise_security_extension/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class Engine < ::Rails::Engine
ActiveSupport.on_load(:action_controller) do
include DeviseSecurityExtension::Controllers::Helpers
end

if defined?(ActiveSupport::Reloader)
ActiveSupport::Callbacks.to_prepare do
if Rails.version > "5"
ActiveSupport::Reloader.to_prepare do
DeviseSecurityExtension::Patches.apply
end
else
Expand Down
9 changes: 7 additions & 2 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
config.cache_classes = true
config.eager_load = false

config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
if Rails.version > "5"
config.public_file_server.enabled = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
else
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
end

config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand Down
6 changes: 6 additions & 0 deletions test/dummy/config/initializers/migration_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MIGRATION_CLASS =
if ActiveRecord::VERSION::MAJOR >= 5
ActiveRecord::Migration[4.2]
else
ActiveRecord::Migration
end
4 changes: 2 additions & 2 deletions test/dummy/db/migrate/20120508165529_create_tables.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateTables < ActiveRecord::Migration
class CreateTables < MIGRATION_CLASS
def self.up
create_table :users do |t|
t.string :username
Expand All @@ -15,7 +15,7 @@ def self.up
create_table :secure_users do |t|
t.string :email
t.string :encrypted_password, null: false, default: ''
t.timestamps
t.timestamps null: false
end

create_table :old_passwords do |t|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddVerificationColumns < ActiveRecord::Migration
class AddVerificationColumns < MIGRATION_CLASS
def self.up
add_column :users, :paranoid_verification_code, :string
add_column :users, :paranoid_verified_at, :datetime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddVerificationAttemptColumn < ActiveRecord::Migration
class AddVerificationAttemptColumn < MIGRATION_CLASS
def self.up
add_column :users, :paranoid_verification_attempt, :integer, default: 0
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddSecurityQuestionsFields < ActiveRecord::Migration
class AddSecurityQuestionsFields < MIGRATION_CLASS
def change
add_column :users, :locked_at, :datetime
add_column :users, :unlock_token, :string
Expand Down
25 changes: 16 additions & 9 deletions test/test_captcha_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class TestWithCaptcha < ActionController::TestCase
end

test 'When captcha is enabled, it is inserted correctly' do
post :create, captcha_user: {
email: "wrong@email.com",
password: "wrongpassword"
post :create, {
captcha_user: {
email: "wrong@email.com",
password: "wrongpassword"
}
}

assert_equal "The captcha input was invalid.", flash[:alert]
Expand All @@ -23,9 +25,12 @@ class TestWithCaptcha < ActionController::TestCase
true
end

post :create, captcha: "ABCDE", captcha_user: {
email: "wrong@email.com",
password: "wrongpassword"
post :create, {
captcha: "ABCDE",
captcha_user: {
email: "wrong@email.com",
password: "wrongpassword"
}
}

assert_equal "Invalid Email or password.", flash[:alert]
Expand All @@ -41,9 +46,11 @@ class TestWithoutCaptcha < ActionController::TestCase
end

test 'When captcha is not enabled, it is not inserted' do
post :create, user: {
email: "wrong@email.com",
password: "wrongpassword"
post :create, {
user: {
email: "wrong@email.com",
password: "wrongpassword"
}
}

assert_equal "Invalid Email or password.", flash[:alert]
Expand Down
9 changes: 7 additions & 2 deletions test/test_password_expired_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class Devise::PasswordExpiredControllerTest < ActionController::TestCase
end

test 'shold update password' do
put :update, user: { current_password: '1234', password: '12345',
password_confirmation: '12345' }
put :update, {
user: {
current_password: '1234',
password: '12345',
password_confirmation: '12345'
}
}
assert_redirected_to root_path
end
end
22 changes: 14 additions & 8 deletions test/test_security_question_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ class TestWithSecurityQuestion < ActionController::TestCase
end

test 'When security question is enabled, it is inserted correctly' do
post :create, security_question_user: {
email: @user.email
}, security_question_answer: "wrong answer"
post :create, {
security_question_user: {
email: @user.email
}, security_question_answer: "wrong answer"
}

assert_equal "The security question answer was invalid.", flash[:alert]
assert_redirected_to new_security_question_user_unlock_path
end

test 'When security_question is valid, it runs as normal' do
post :create, security_question_user: {
email: @user.email
}, security_question_answer: @user.security_question_answer
post :create, {
security_question_user: {
email: @user.email
}, security_question_answer: @user.security_question_answer
}

assert_equal "You will receive an email with instructions for how to unlock your account in a few minutes.", flash[:notice]
assert_redirected_to new_security_question_user_session_path
Expand All @@ -44,8 +48,10 @@ class TestWithoutSecurityQuestion < ActionController::TestCase
end

test 'When security question is not enabled it is not inserted' do
post :create, user: {
email: @user.email
post :create, {
user: {
email: @user.email
}
}

assert_equal "You will receive an email with instructions for how to unlock your account in a few minutes.", flash[:notice]
Expand Down

0 comments on commit b2ee978

Please sign in to comment.