Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed Test Errors on Rails 4 #351

Closed
wants to merge 7 commits into from

3 participants

@AxisOfEval

Hi Ben,

I am using Rails 4 beta for ActiveRecord and ActiveSupport. Doing rake test got me some (nine I think) errors. They were because:

  1. Bad tests, for Password Confirmation Stuff
  2. No fixed timezone, killed perishable functionality

I am sure you're aware of the deprecation warnings related to scope. They remain because I am not entirely sure about what's really happening there. But will try to fix things when I find more time. Meanwhile, getting this PR in will be great. Thanks :o)

@nathany nathany commented on the diff
authlogic.gemspec
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
s.summary = %q{A clean, simple, and unobtrusive ruby authentication solution.}
s.description = %q{A clean, simple, and unobtrusive ruby authentication solution.}
- s.add_dependency 'activerecord', '>= 3.0.0'
- s.add_dependency 'activesupport', '>= 3.0.0'
+ s.add_dependency 'activerecord', '>= 4.0.0.beta1'
@nathany
nathany added a note

I'm guessing we'd still want to support and test against Rails 3. I hope #368 will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@binarylogic
Owner

I believe we're using appraisal now to test both versions of rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2013
  1. - Using Ruby 2.0 p0

    Amol Hatwar authored
  2. - Rebundled with Rails 4 deps

    Amol Hatwar authored
  3. - Fixed for Ruby 2.0.0 require behaviour

    Amol Hatwar authored
  4. - Got tests working

    Amol Hatwar authored
  5. - Fixed faulty password tests

    Amol Hatwar authored
  6. - Enforce a timezone

    Amol Hatwar authored
This page is out of date. Refresh to see the latest.
View
1  .rbenv-gemsets
@@ -0,0 +1 @@
+authlogic-rails4
View
1  .ruby-version
@@ -0,0 +1 @@
+2.0.0-p0
View
4 Gemfile
@@ -1,2 +1,2 @@
-source :rubygems
-gemspec
+source 'https://rubygems.org'
+gemspec
View
46 Gemfile.lock
@@ -2,33 +2,41 @@ PATH
remote: .
specs:
authlogic (3.2.1)
- activerecord (>= 3.0.0)
- activesupport (>= 3.0.0)
+ activerecord (>= 4.0.0.beta1)
+ activesupport (>= 4.0.0.beta1)
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
- activemodel (3.2.9)
- activesupport (= 3.2.9)
- builder (~> 3.0.0)
- activerecord (3.2.9)
- activemodel (= 3.2.9)
- activesupport (= 3.2.9)
- arel (~> 3.0.2)
- tzinfo (~> 0.3.29)
- activesupport (3.2.9)
- i18n (~> 0.6)
- multi_json (~> 1.0)
- arel (3.0.2)
+ activemodel (4.0.0.beta1)
+ activesupport (= 4.0.0.beta1)
+ builder (~> 3.1.0)
+ activerecord (4.0.0.beta1)
+ activemodel (= 4.0.0.beta1)
+ activerecord-deprecated_finders (~> 0.0.3)
+ activesupport (= 4.0.0.beta1)
+ arel (~> 4.0.0.beta1)
+ activerecord-deprecated_finders (0.0.3)
+ activesupport (4.0.0.beta1)
+ i18n (~> 0.6.2)
+ minitest (~> 4.2)
+ multi_json (~> 1.3)
+ thread_safe (~> 0.1)
+ tzinfo (~> 0.3.33)
+ arel (4.0.0.beta1)
+ atomic (1.0.1)
bcrypt-ruby (3.0.1)
- builder (3.0.4)
- i18n (0.6.1)
- multi_json (1.4.0)
+ builder (3.1.4)
+ i18n (0.6.4)
+ minitest (4.6.2)
+ multi_json (1.6.1)
rake (10.0.2)
scrypt (1.1.0)
sqlite3 (1.3.6)
+ thread_safe (0.1.0)
+ atomic
timecop (0.5.4)
- tzinfo (0.3.35)
+ tzinfo (0.3.36)
PLATFORMS
ruby
View
4 authlogic.gemspec
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
s.summary = %q{A clean, simple, and unobtrusive ruby authentication solution.}
s.description = %q{A clean, simple, and unobtrusive ruby authentication solution.}
- s.add_dependency 'activerecord', '>= 3.0.0'
- s.add_dependency 'activesupport', '>= 3.0.0'
+ s.add_dependency 'activerecord', '>= 4.0.0.beta1'
@nathany
nathany added a note

I'm guessing we'd still want to support and test against Rails 3. I hope #368 will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ s.add_dependency 'activesupport', '>= 4.0.0.beta1'
s.add_development_dependency 'rake'
s.add_development_dependency 'bcrypt-ruby'
s.add_development_dependency 'scrypt'
View
14 lib/authlogic/i18n.rb
@@ -1,4 +1,4 @@
-require "authlogic/i18n/translator"
+require File.dirname(__FILE__) + '/i18n/translator'
module Authlogic
# This class allows any message in Authlogic to use internationalization. In earlier versions of Authlogic each message was translated via configuration.
@@ -22,7 +22,7 @@ module Authlogic
# # do whatever you want here with the arguments passed to you.
# end
# end
- #
+ #
# Authlogic::I18n.translator = MyAuthlogicI18nTranslator.new
#
# That it's! Here is a complete list of the keys that are passed. Just define these however you wish:
@@ -52,28 +52,28 @@ module Authlogic
module I18n
@@scope = :authlogic
@@translator = nil
-
+
class << self
# Returns the current scope. Defaults to :authlogic
def scope
@@scope
end
-
+
# Sets the current scope. Used to set a custom scope.
def scope=(scope)
@@scope = scope
end
-
+
# Returns the current translator. Defaults to +Translator+.
def translator
@@translator ||= Translator.new
end
-
+
# Sets the current translator. Used to set a custom translator.
def translator=(translator)
@@translator = translator
end
-
+
# All message translation is passed to this method. The first argument is the key for the message. The second is options, see the rails I18n library for a list of options used.
def translate(key, options = {})
translator.translate key, { :scope => I18n.scope }.merge(options)
View
8 lib/authlogic/test_case.rb
@@ -81,7 +81,7 @@ module Authlogic
# that looks like a controller, acts like a controller, but isn't a "real" controller. You are essentially connecting
# Authlogic to your "mock" controller, then you can test off of the mock controller to make sure everything is functioning
# properly.
- #
+ #
# I use a mock controller to test Authlogic myself. It's part of the Authlogic library that you can easily use. It's as simple
# as functional and integration tests. Just do the following:
#
@@ -108,13 +108,13 @@ class <<@request
Authlogic::Session::Base.controller = (@request && Authlogic::TestCase::RailsRequestAdapter.new(@request)) || controller
end
-
+
# The Authlogic::TestCase::MockController object passed to Authlogic to activate it. You can access this in your test.
# See the module description for an example.
def controller
@controller ||= Authlogic::TestCase::MockController.new
end
end
-
- ::Test::Unit::TestCase.send(:include, TestCase) if defined?(::Test::Unit::TestCase)
+
+ ::MiniTest::Unit::TestCase.send(:include, ::Authlogic::TestCase) if defined?(::MiniTest::Unit::TestCase)
end
View
88 test/acts_as_authentic_test/password_test.rb
@@ -5,33 +5,33 @@ class PasswordTest < ActiveSupport::TestCase
def test_crypted_password_field_config
assert_equal :crypted_password, User.crypted_password_field
assert_equal :crypted_password, Employee.crypted_password_field
-
+
User.crypted_password_field = :nope
assert_equal :nope, User.crypted_password_field
User.crypted_password_field :crypted_password
assert_equal :crypted_password, User.crypted_password_field
end
-
+
def test_password_salt_field_config
assert_equal :password_salt, User.password_salt_field
assert_equal :password_salt, Employee.password_salt_field
-
+
User.password_salt_field = :nope
assert_equal :nope, User.password_salt_field
User.password_salt_field :password_salt
assert_equal :password_salt, User.password_salt_field
end
-
+
def test_ignore_blank_passwords_config
assert User.ignore_blank_passwords
assert Employee.ignore_blank_passwords
-
+
User.ignore_blank_passwords = false
assert !User.ignore_blank_passwords
User.ignore_blank_passwords true
assert User.ignore_blank_passwords
end
-
+
def test_check_passwords_against_database
assert User.check_passwords_against_database
User.check_passwords_against_database = false
@@ -39,116 +39,116 @@ def test_check_passwords_against_database
User.check_passwords_against_database true
assert User.check_passwords_against_database
end
-
+
def test_validate_password_field_config
assert User.validate_password_field
assert Employee.validate_password_field
-
+
User.validate_password_field = false
assert !User.validate_password_field
User.validate_password_field true
assert User.validate_password_field
end
-
+
def test_validates_length_of_password_field_options_config
default = {:minimum => 4, :if => :require_password?}
assert_equal default, User.validates_length_of_password_field_options
assert_equal default, Employee.validates_length_of_password_field_options
-
+
User.validates_length_of_password_field_options = {:yes => "no"}
assert_equal({:yes => "no"}, User.validates_length_of_password_field_options)
User.validates_length_of_password_field_options default
assert_equal default, User.validates_length_of_password_field_options
end
-
+
def test_validates_confirmation_of_password_field_options_config
default = {:if => :require_password?}
assert_equal default, User.validates_confirmation_of_password_field_options
assert_equal default, Employee.validates_confirmation_of_password_field_options
-
+
User.validates_confirmation_of_password_field_options = {:yes => "no"}
assert_equal({:yes => "no"}, User.validates_confirmation_of_password_field_options)
User.validates_confirmation_of_password_field_options default
assert_equal default, User.validates_confirmation_of_password_field_options
end
-
+
def test_validates_length_of_password_confirmation_field_options_config
default = {:minimum => 4, :if => :require_password?}
assert_equal default, User.validates_length_of_password_confirmation_field_options
assert_equal default, Employee.validates_length_of_password_confirmation_field_options
-
+
User.validates_length_of_password_confirmation_field_options = {:yes => "no"}
assert_equal({:yes => "no"}, User.validates_length_of_password_confirmation_field_options)
User.validates_length_of_password_confirmation_field_options default
assert_equal default, User.validates_length_of_password_confirmation_field_options
end
-
+
def test_crypto_provider_config
assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
assert_equal Authlogic::CryptoProviders::AES256, Employee.crypto_provider
-
+
User.crypto_provider = Authlogic::CryptoProviders::BCrypt
assert_equal Authlogic::CryptoProviders::BCrypt, User.crypto_provider
User.crypto_provider Authlogic::CryptoProviders::Sha512
assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
end
-
+
def test_transition_from_crypto_providers_config
assert_equal [], User.transition_from_crypto_providers
assert_equal [], Employee.transition_from_crypto_providers
-
+
User.transition_from_crypto_providers = [Authlogic::CryptoProviders::BCrypt]
assert_equal [Authlogic::CryptoProviders::BCrypt], User.transition_from_crypto_providers
User.transition_from_crypto_providers []
assert_equal [], User.transition_from_crypto_providers
end
-
+
def test_validates_length_of_password
u = User.new
- u.password_confirmation = "test2"
+ u.password_confirmation = "test"
assert !u.valid?
assert u.errors[:password].size > 0
-
+
u.password = "test"
assert !u.valid?
- assert u.errors[:password_confirmation].size == 0
+ assert u.errors[:password].size == 0
end
-
+
def test_validates_confirmation_of_password
u = User.new
u.password = "test"
u.password_confirmation = "test2"
assert !u.valid?
- assert u.errors[:password].size > 0
-
+ assert u.errors[:password_confirmation].size > 0
+
u.password_confirmation = "test"
assert !u.valid?
- assert u.errors[:password].size == 0
+ assert u.errors[:password_confirmation].size == 0
end
-
+
def test_validates_length_of_password_confirmation
u = User.new
-
+
u.password = "test"
u.password_confirmation = ""
assert !u.valid?
assert u.errors[:password_confirmation].size > 0
-
+
u.password_confirmation = "test"
assert !u.valid?
assert u.errors[:password_confirmation].size == 0
-
+
ben = users(:ben)
assert ben.valid?
-
+
ben.password = "newpass"
assert !ben.valid?
assert ben.errors[:password_confirmation].size > 0
-
+
ben.password_confirmation = "newpass"
assert ben.valid?
end
-
+
def test_password
u = User.new
old_password_salt = u.password_salt
@@ -157,60 +157,60 @@ def test_password
assert_not_equal old_password_salt, u.password_salt
assert_not_equal old_crypted_password, u.crypted_password
end
-
+
def test_transitioning_password
ben = users(:ben)
transition_password_to(Authlogic::CryptoProviders::BCrypt, ben)
transition_password_to(Authlogic::CryptoProviders::Sha1, ben, [Authlogic::CryptoProviders::Sha512, Authlogic::CryptoProviders::BCrypt])
transition_password_to(Authlogic::CryptoProviders::Sha512, ben, [Authlogic::CryptoProviders::Sha1, Authlogic::CryptoProviders::BCrypt])
end
-
+
def test_checks_password_against_database
ben = users(:ben)
ben.password = "new pass"
assert !ben.valid_password?("new pass")
assert ben.valid_password?("benrocks")
end
-
+
def test_checks_password_against_database_and_always_fails_on_new_records
user = User.new
user.password = "new pass"
assert !user.valid_password?("new pass")
end
-
+
def test_checks_password_against_object
ben = users(:ben)
ben.password = "new pass"
assert ben.valid_password?("new pass", false)
assert !ben.valid_password?("benrocks", false)
end
-
+
def test_reset_password
ben = users(:ben)
old_crypted_password = ben.crypted_password
old_password_salt = ben.password_salt
-
+
# soft reset
ben.reset_password
assert_not_equal old_crypted_password, ben.crypted_password
assert_not_equal old_password_salt, ben.password_salt
-
+
# make sure it didn't go into the db
ben.reload
assert_equal old_crypted_password, ben.crypted_password
assert_equal old_password_salt, ben.password_salt
-
+
# hard reset
assert ben.reset_password!
assert_not_equal old_crypted_password, ben.crypted_password
assert_not_equal old_password_salt, ben.password_salt
-
+
# make sure it did go into the db
ben.reload
assert_not_equal old_crypted_password, ben.crypted_password
assert_not_equal old_password_salt, ben.password_salt
end
-
+
private
def transition_password_to(crypto_provider, records, from_crypto_providers = Authlogic::CryptoProviders::Sha512)
records = [records] unless records.is_a?(Array)
@@ -224,7 +224,7 @@ def transition_password_to(crypto_provider, records, from_crypto_providers = Aut
assert record.valid_password?(password_for(record))
assert_not_equal old_hash.to_s, record.crypted_password.to_s
assert_not_equal old_persistence_token.to_s, record.persistence_token.to_s
-
+
old_hash = record.crypted_password
old_persistence_token = record.persistence_token
assert record.valid_password?(password_for(record))
View
3  test/test_helper.rb
@@ -166,3 +166,6 @@ def unset_session
controller.session["user_credentials"] = controller.session["user_credentials_id"] = nil
end
end
+
+# Set a standard timezone to avoid perishable_token timestamp conflicts
+Time.zone = 'UTC'
Something went wrong with that request. Please try again.