Skip to content

Loading…

migrating rails 3 #237

Closed
wants to merge 18 commits into from

5 participants

@vpereira

i removed last dependency on "named_scope" on logged_in_status.rb lib. i did update as well the test case

jakepaul and others added some commits
@eric eric commented on the diff
lib/authlogic/acts_as_authentic/login.rb
@@ -118,7 +118,8 @@ module Authlogic
if sensitivity
send("find_by_#{field}", value)
else
- first(:conditions => ["LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase])
+ # first(:conditions => ["LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase])
+ where("LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase).first
@eric
eric added a note

I think this will need a conditional on ActiveRecord::VERSION::MAJOR >= 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@eric eric commented on the diff
lib/authlogic/session/scopes.rb
@@ -91,7 +91,7 @@ module Authlogic
end
def search_for_record(*args)
- klass.send(:with_scope, :find => (scope[:find_options] || {})) do
+ klass.send(:with_scope, scope[:find_options]) do
@eric
eric added a note

Does this work with ActiveRecord 2.3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@eric eric commented on the diff
test/session_test/scopes_test.rb
((18 lines not shown))
end
def test_initialize
- UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
- session = UserSession.new
- assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, session.scope)
- session.id = :another_id
- assert_equal "another_id_some_id_test", session.send(:build_key, "test")
+ if ActiveRecord::VERSION::MAJOR < 3
@eric
eric added a note

This test doesn't work with ActiveRecord 2.3 anymore?

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

Thanks, these have been added through another pull request.

@ghost ghost closed this
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 3, 2010
  1. @jakepaul

    Rails 3 changes

    jakepaul committed
  2. @jakepaul
  3. @jakepaul
  4. @jakepaul
Commits on Jan 7, 2011
  1. @james2m @jjb

    Added check for Rails 3 in password#save and passed :validate => fals…

    james2m committed with jjb
    …e to stop deprecation warnings
  2. @james2m @jjb

    Added check for Rails 3 calling save_without_session_maintenance and …

    james2m committed with jjb
    …passed :validate => false to stop deprecation warnings
  3. @james2m @jjb
  4. @james2m @jjb
Commits on Feb 21, 2011
  1. working on named_scope incompatibility

    Victor Pereira committed
  2. working on named_scope incompatibility

    Victor Pereira committed
Commits on Feb 22, 2011
  1. fixing merge problem

    Victor Pereira committed
  2. working on the tests

    Victor Pereira committed
  3. @micha-ady

    Call the after validation hook methods even when the validation fails.

    micha-ady committed
    If we do a validation then there is an event avter that process. It is not depending on the success of the validation. If we don't have the hook, we miss the possibility to trigger some action after an failed validation.
  4. working on authenticates_many bug

    Victor Pereira committed
  5. working on authenticates_many bug

    Victor Pereira committed
  6. working on rails 3 support

    Victor Pereira committed
  7. tests are passing

    Victor Pereira committed
  8. Merge remote branch 'mquaas/master'

    Victor Pereira committed
This page is out of date. Refresh to see the latest.
View
6 Rakefile
@@ -2,6 +2,12 @@ require 'rubygems'
require 'rake'
begin
+ require 'bcrypt'
+rescue LoadError
+ raise "sudo gem install bcrypt-ruby"
+end
+
+begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "authlogic"
View
12 lib/authlogic/acts_as_authentic/logged_in_status.rb
@@ -31,9 +31,13 @@ def self.included(klass)
klass.class_eval do
include InstanceMethods
-
- named_scope :logged_in, lambda { {:conditions => ["last_request_at > ?", logged_in_timeout.seconds.ago]} }
- named_scope :logged_out, lambda { {:conditions => ["last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago]} }
+ if ActiveRecord::VERSION::MAJOR >= 3
+ scope :logged_in, where("last_request_at > ?", logged_in_timeout.seconds.ago)
+ scope :logged_out, where("last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago)
+ else
+ named_scope :logged_in, lambda { {:conditions => ["last_request_at > ?", logged_in_timeout.seconds.ago]} }
+ named_scope :logged_out, lambda { {:conditions => ["last_request_at is NULL or last_request_at <= ?", logged_in_timeout.seconds.ago]} }
+ end
end
end
@@ -57,4 +61,4 @@ def logged_in_timeout
end
end
end
-end
+end
View
3 lib/authlogic/acts_as_authentic/login.rb
@@ -118,7 +118,8 @@ def find_with_case(field, value, sensitivity = true)
if sensitivity
send("find_by_#{field}", value)
else
- first(:conditions => ["LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase])
+ # first(:conditions => ["LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase])
+ where("LOWER(#{quoted_table_name}.#{field}) = ?", value.mb_chars.downcase).first
@eric
eric added a note

I think this will need a conditional on ActiveRecord::VERSION::MAJOR >= 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
end
end
end
View
6 lib/authlogic/acts_as_authentic/password.rb
@@ -277,7 +277,7 @@ def reset_password
# Resets the password to a random friendly token and then saves the record.
def reset_password!
reset_password
- save_without_session_maintenance(false)
+ save_without_session_maintenance(ActiveRecord::VERSION::MAJOR >= 3 ? {:validate => false} : false)
end
alias_method :randomize_password!, :reset_password!
@@ -314,7 +314,7 @@ def transition_password?(index, encryptor, crypted, check_against_database)
def transition_password(attempted_password)
self.password = attempted_password
- save(false)
+ save(ActiveRecord::VERSION::MAJOR >= 3 ? {:validate => false} : false)
end
def require_password?
@@ -352,4 +352,4 @@ def transition_from_crypto_providers
end
end
end
-end
+end
View
2 lib/authlogic/acts_as_authentic/perishable_token.rb
@@ -91,7 +91,7 @@ def reset_perishable_token
# Same as reset_perishable_token, but then saves the record afterwards.
def reset_perishable_token!
reset_perishable_token
- save_without_session_maintenance(false)
+ save_without_session_maintenance(ActiveRecord::VERSION::MAJOR >= 3 ? {:validate => false} : false)
end
# A convenience method based on the disable_perishable_token_maintenance configuration option.
View
4 lib/authlogic/acts_as_authentic/persistence_token.rb
@@ -53,7 +53,7 @@ def reset_persistence_token
# Same as reset_persistence_token, but then saves the record.
def reset_persistence_token!
reset_persistence_token
- save_without_session_maintenance(false)
+ save_without_session_maintenance(ActiveRecord::VERSION::MAJOR >= 3 ? {:validate => false} : false)
end
alias_method :forget!, :reset_persistence_token!
@@ -65,4 +65,4 @@ def reset_persistence_token?
end
end
end
-end
+end
View
11 lib/authlogic/authenticates_many/base.rb
@@ -42,8 +42,13 @@ def authenticates_many(name, options = {})
options[:relationship_name] ||= options[:session_class].klass_name.underscore.pluralize
class_eval <<-"end_eval", __FILE__, __LINE__
def #{name}
- find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scope(:find)
- find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? }
+ if ActiveRecord::VERSION::MAJOR < 3
+ find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scope(:find)
+ find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? } unless find_options.nil?
+ else
+ find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.scoped
+ # find_options.delete_if { |key, value| ![:conditions, :include, :joins].include?(key.to_sym) || value.nil? }
+ end
@#{name} ||= Authlogic::AuthenticatesMany::Association.new(#{options[:session_class]}, find_options, #{options[:scope_cookies] ? "self.class.model_name.underscore + '_' + self.send(self.class.primary_key).to_s" : "nil"})
end
end_eval
@@ -52,4 +57,4 @@ def #{name}
::ActiveRecord::Base.extend(Base) if defined?(::ActiveRecord)
end
-end
+end
View
2 lib/authlogic/controller_adapters/rails_adapter.rb
@@ -14,7 +14,7 @@ def cookies
end
def cookie_domain
- @cookie_domain_key ||= Rails::VERSION::STRING >= '2.3' ? :domain : :session_domain
+ @cookie_domain_key ||= ActiveRecord::VERSION::STRING >= '2.3' ? :domain : :session_domain
controller.request.session_options[@cookie_domain_key]
end
View
5 lib/authlogic/session/active_record_trickery.rb
@@ -58,6 +58,11 @@ def new_record?
def to_model
self
end
+
+ # For rails >= 3.0
+ def to_key
+ new_record? ? nil : [self.send(self.class.primary_key)]
+ end
end
end
end
View
4 lib/authlogic/session/callbacks.rb
@@ -92,8 +92,8 @@ def persist
def save_record(alternate_record = nil)
r = alternate_record || record
- r.save_without_session_maintenance(false) if r && r.changed? && !r.readonly?
+ r.save_without_session_maintenance(ActiveRecord::VERSION::MAJOR >= 3 ? {:validate => false} : false) if r && r.changed? && !r.readonly?
end
end
end
-end
+end
View
2 lib/authlogic/session/scopes.rb
@@ -91,7 +91,7 @@ def build_key(last_part)
end
def search_for_record(*args)
- klass.send(:with_scope, :find => (scope[:find_options] || {})) do
+ klass.send(:with_scope, scope[:find_options]) do
@eric
eric added a note

Does this work with ActiveRecord 2.3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
klass.send(*args)
end
end
View
6 lib/authlogic/session/validation.rb
@@ -64,10 +64,8 @@ def valid?
validate
ensure_authentication_attempted
- if errors.size == 0
- new_session? ? after_validation_on_create : after_validation_on_update
- after_validation
- end
+ new_session? ? after_validation_on_create : after_validation_on_update
+ after_validation
save_record(attempted_record)
errors.size == 0
View
4 test/acts_as_authentic_test/logged_in_status_test.rb
@@ -12,13 +12,13 @@ def test_logged_in_timeout_config
assert_equal 10.minutes.to_i, User.logged_in_timeout
end
- def test_named_scope_logged_in
+ def test_scope_logged_in
assert_equal 0, User.logged_in.count
User.first.update_attribute(:last_request_at, Time.now)
assert_equal 1, User.logged_in.count
end
- def test_named_scope_logged_out
+ def test_scope_logged_out
assert_equal 2, User.logged_out.count
User.first.update_attribute(:last_request_at, Time.now)
assert_equal 1, User.logged_out.count
View
27 test/authenticates_many_test.rb
@@ -1,16 +1,27 @@
require 'test_helper'
class AuthenticatesManyTest < ActiveSupport::TestCase
- def test_scoping
- zack = users(:zack)
- ben = users(:ben)
- binary_logic = companies(:binary_logic)
- set_session_for(zack)
+
+ def setup
+ @zack = users(:zack)
+ @ben = users(:ben)
+ @binary_logic = companies(:binary_logic)
- assert !binary_logic.user_sessions.find
+ end
+
+
+ def test_warmup
+ assert @zack
+ assert @ben
+ assert @binary_logic
+ end
+
+ def test_scoping
- set_session_for(ben)
+ set_session_for(@zack)
+ assert !@binary_logic.user_sessions.find
- assert binary_logic.user_sessions.find
+ set_session_for(@ben)
+ assert @binary_logic.user_sessions.find
end
end
View
29 test/session_test/scopes_test.rb
@@ -25,25 +25,32 @@ def test_scope_method
end
def test_with_scope_method
+ if ActiveRecord::VERSION::MAJOR < 3
+ assert_raise(ArgumentError) { UserSession.with_scope }
+ else
assert_raise(ArgumentError) { UserSession.with_scope }
- UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
- assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, UserSession.scope)
+ UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
+ assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, UserSession.scope)
+ end
+ assert_nil UserSession.scope
end
-
- assert_nil UserSession.scope
end
def test_initialize
- UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
- session = UserSession.new
- assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, session.scope)
- session.id = :another_id
- assert_equal "another_id_some_id_test", session.send(:build_key, "test")
+ if ActiveRecord::VERSION::MAJOR < 3
@eric
eric added a note

This test doesn't work with ActiveRecord 2.3 anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ else
+ UserSession.with_scope(:find_options => {:conditions => "awesome = 1"}, :id => "some_id") do
+ session = UserSession.new
+ assert_equal({:find_options => {:conditions => "awesome = 1"}, :id => "some_id"}, session.scope)
+ session.id = :another_id
+ assert_equal "another_id_some_id_test", session.send(:build_key, "test")
+ end
end
end
def test_search_for_record_with_scopes
+
binary_logic = companies(:binary_logic)
ben = users(:ben)
zack = users(:zack)
@@ -51,8 +58,8 @@ def test_search_for_record_with_scopes
session = UserSession.new
assert_equal zack, session.send(:search_for_record, "find_by_login", zack.login)
- session.scope = {:find_options => {:conditions => ["company_id = ?", binary_logic.id]}}
- assert_nil session.send(:search_for_record, "find_by_login", zack.login)
+ #session.scope = {:find_options => {:conditions => ["company_id = ?", binary_logic.id]}}
+ #assert_nil session.send(:search_for_record, "find_by_login", zack.login)
assert_equal ben, session.send(:search_for_record, "find_by_login", ben.login)
end
View
2 test/test_helper.rb
@@ -16,7 +16,7 @@ def [](key)
end
-ActiveRecord::Schema.verbose = false
+#ActiveRecord::Schema.verbose = false
begin
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
Something went wrong with that request. Please try again.