From 77ec1b08cd263e3cc766f78aca72b05f1334f943 Mon Sep 17 00:00:00 2001 From: Drew Ulmer Date: Sat, 1 Dec 2012 21:06:03 -0600 Subject: [PATCH] Move test models into their own file so they can be used elsewhere --- test/models/database_authenticatable_test.rb | 1 + test/models_test.rb | 23 +--------------- test/support/helpers.rb | 4 +++ test/test_models.rb | 28 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 test/test_models.rb diff --git a/test/models/database_authenticatable_test.rb b/test/models/database_authenticatable_test.rb index bacbe986..c184fcb4 100644 --- a/test/models/database_authenticatable_test.rb +++ b/test/models/database_authenticatable_test.rb @@ -1,4 +1,5 @@ require 'test_helper' +require 'test_models' require 'digest/sha1' class DatabaseAuthenticatableTest < ActiveSupport::TestCase diff --git a/test/models_test.rb b/test/models_test.rb index b3340465..705ad768 100644 --- a/test/models_test.rb +++ b/test/models_test.rb @@ -1,26 +1,5 @@ require 'test_helper' - -class Configurable < User - devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable, - :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days, - :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days -end - -class WithValidation < Admin - devise :database_authenticatable, :validatable, :password_length => 2..6 -end - -class UserWithValidation < User - validates_presence_of :username -end - -class Several < Admin - devise :validatable - devise :lockable -end - -class Inheritable < Admin -end +require 'test_models' class ActiveRecordTest < ActiveSupport::TestCase def include_module?(klass, mod) diff --git a/test/support/helpers.rb b/test/support/helpers.rb index a2554485..355001d9 100644 --- a/test/support/helpers.rb +++ b/test/support/helpers.rb @@ -29,6 +29,10 @@ class ActiveSupport::TestCase :password_confirmation => '12345678' }.update(attributes) end + def new_user_with_class(klass=User, attributes={}) + klass.new(valid_attributes(attributes)) + end + def new_user(attributes={}) User.new(valid_attributes(attributes)) end diff --git a/test/test_models.rb b/test/test_models.rb new file mode 100644 index 00000000..b17d3773 --- /dev/null +++ b/test/test_models.rb @@ -0,0 +1,28 @@ +class Configurable < User + devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable, + :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days, + :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days +end + +class WithValidation < Admin + devise :database_authenticatable, :validatable, :password_length => 2..6 +end + +class UserWithValidation < User + validates_presence_of :username +end + +class UserWithVirtualAttributes < User + devise :case_insensitive_keys => [ :email, :email_confirmation ] + validates :email, :presence => true, :confirmation => {:on => :create} + attr_accessible :email, :email_confirmation +end + +class Several < Admin + devise :validatable + devise :lockable +end + +class Inheritable < Admin +end +