Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added option to modify options for validates_presence_of for the pass…
…word confirmation field
  • Loading branch information
binarylogic committed Dec 2, 2008
1 parent af9712b commit 6306af3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Manifest
@@ -1,4 +1,6 @@
CHANGELOG.rdoc
generators/session/session_generator.rb
generators/session/templates/session.rb
init.rb
lib/authlogic/controller_adapters/abstract_adapter.rb
lib/authlogic/controller_adapters/merb_adapter.rb
Expand Down Expand Up @@ -27,6 +29,7 @@ lib/authlogic/session/params.rb
lib/authlogic/session/perishability.rb
lib/authlogic/session/scopes.rb
lib/authlogic/session/session.rb
lib/authlogic/testing/test_unit_helpers.rb
lib/authlogic/version.rb
lib/authlogic.rb
Manifest
Expand Down
6 changes: 5 additions & 1 deletion README.rdoc
Expand Up @@ -100,6 +100,10 @@ Lets assume you are setting up a session for your User model.

Create your user_session.rb file:

$ script/generate session user_session

This will create a file that looks similar to:

# app/models/user_session.rb
class UserSession < Authlogic::Session::Base
# configuration here, just like ActiveRecord, or in an initializer
Expand Down Expand Up @@ -452,7 +456,7 @@ You get the following methods:
set_cookie_for(record_object)
set_http_auth_for(username, password)

In your test, before you execute a request, just call one of those methods and it will set the proper values so that it will seems as if that record is logged in.
In your test, before you execute a request, just call one of those methods and it will set the proper values so that it will seem as if that record is logged in.

You can also checkout the authlogic_example application (see helpful links above), the tests there use this.

Expand Down
Expand Up @@ -127,9 +127,12 @@ module ActsAsAuthentic
# * <tt>password_field_validates_length_of_options</tt> - default: {:minimum => 4},
# These options are applied to the validates_length_of call for the :password_field
#
# * <tt>login_field_validates_confirmation_of_options</tt> - default: {},
# * <tt>password_field_validates_confirmation_of_options</tt> - default: {},
# These options are applied to the validates_confirmation_of call for the :password_field
#
# * <tt>password_confirmation_field_validates_presence_of_options</tt> - default: {},
# These options are applied to the validates_presence_of call for the :password_confirmation_field.
#
# * <tt>email_field_validation_options</tt> - default: {},
# The same as :validation_options but these are only applied to validations that pertain to the :email_field
#
Expand Down Expand Up @@ -198,6 +201,8 @@ def acts_as_authentic_with_config(options = {})
end
end

options[:password_confirmation_field_validates_presence_of_options] ||= {}

if options[:scope]
options[:login_field_validates_uniqueness_of_options][:scope] ||= options[:scope]
options[:email_field_validates_uniqueness_of_options][:scope] ||= options[:scope]
Expand Down
Expand Up @@ -42,7 +42,7 @@ def acts_as_authentic_with_credentials(options = {})
if options[:validate_password_field]
validates_length_of options[:password_field], {:minimum => 4}.merge(options[:password_field_validates_length_of_options].merge(:if => "validate_#{options[:password_field]}?".to_sym))
validates_confirmation_of options[:password_field], options[:password_field_validates_confirmation_of_options].merge(:if => "#{options[:password_salt_field]}_changed?".to_sym)
validates_presence_of "#{options[:password_field]}_confirmation", :if => "#{options[:password_salt_field]}_changed?".to_sym
validates_presence_of "#{options[:password_field]}_confirmation", options[:password_confirmation_field_validates_presence_of_options].merge(:if => "#{options[:password_salt_field]}_changed?".to_sym)
end

if options[:validate_email_field] && options[:email_field]
Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic/session/base.rb
Expand Up @@ -357,7 +357,7 @@ def create_configurable_methods!
return if respond_to?(login_field) # already created these methods

self.class.class_eval <<-"end_eval", __FILE__, __LINE__
alias_method :#{klass_name.underscore.split("/").last}, :record
alias_method :#{klass_name.demodulize.underscore}, :record
attr_reader :#{login_field}
Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic/version.rb
Expand Up @@ -44,7 +44,7 @@ def to_a

MAJOR = 1
MINOR = 3
TINY = 6
TINY = 7

# The current version as a Version instance
CURRENT = new(MAJOR, MINOR, TINY)
Expand Down
Expand Up @@ -45,7 +45,8 @@ def test_acts_as_authentic_config
:validate_email_field => true,
:validation_options => {},
:login_field_validation_options => {},
:transition_from_crypto_provider => []
:transition_from_crypto_provider => [],
:password_confirmation_field_validates_presence_of_options => {}
}
assert_equal default_config, User.acts_as_authentic_config
end
Expand Down

0 comments on commit 6306af3

Please sign in to comment.