From 200b269d7977fa8c709005a57f7c7dc5979beb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 22 Oct 2009 19:26:10 -0200 Subject: [PATCH] Allow null to be given to authenticable. --- lib/devise/migrations.rb | 9 +++++---- test/active_record_test.rb | 4 ++++ test/rails_app/app/models/admin.rb | 2 +- test/test_helper.rb | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/devise/migrations.rb b/lib/devise/migrations.rb index 18d7f116..5601f5b6 100644 --- a/lib/devise/migrations.rb +++ b/lib/devise/migrations.rb @@ -19,10 +19,11 @@ module Devise # Creates email, encrypted_password and password_salt. # - def authenticable - string :email, :limit => 100, :null => false - string :encrypted_password, :limit => 40, :null => false - string :password_salt, :limit => 20, :null => false + def authenticable(options={}) + null = options[:null] || false + string :email, :limit => 100, :null => null + string :encrypted_password, :limit => 40, :null => null + string :password_salt, :limit => 20, :null => null end # Creates confirmation_token, confirmed_at and confirmation_sent_at. diff --git a/test/active_record_test.rb b/test/active_record_test.rb index be621b1c..b76f09ae 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -93,4 +93,8 @@ class ActiveRecordTest < ActiveSupport::TestCase test 'set a default value for pepper' do assert_equal 'abcdef', Configurable.new.send(:pepper) end + + test 'set null fields on migrations' do + Admin.create! + end end diff --git a/test/rails_app/app/models/admin.rb b/test/rails_app/app/models/admin.rb index f4b3b266..571785b8 100644 --- a/test/rails_app/app/models/admin.rb +++ b/test/rails_app/app/models/admin.rb @@ -1,3 +1,3 @@ class Admin < ActiveRecord::Base - devise :all, :except => [:recoverable, :confirmable, :rememberable] + devise :all, :except => [:recoverable, :confirmable, :rememberable, :validatable] end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8a01b844..35895cbd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,7 +16,7 @@ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":me ActiveRecord::Schema.define(:version => 1) do [:users, :admins].each do |table| create_table table do |t| - t.authenticable + t.authenticable :null => table == :admins if table == :users t.confirmable