diff --git a/test/mapping_test.rb b/test/mapping_test.rb index ce515dbc..0bae4794 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -14,8 +14,8 @@ class MappingTest < ActiveSupport::TestCase assert_equal :admin_area, Devise.mappings[:admin].as end - test 'allow custom singular to be given' do - assert_equal :organizers, Devise.mappings[:manager].as + test 'allow custom scope to be given' do + assert_equal :accounts, Devise.mappings[:manager].as end test 'allows a controller depending on the mapping' do @@ -70,7 +70,7 @@ class MappingTest < ActiveSupport::TestCase end test 'allow custom path names to be given' do - mapping = Devise.mappings[:account] + mapping = Devise.mappings[:manager] assert_equal 'login', mapping.path_names[:sign_in] assert_equal 'logout', mapping.path_names[:sign_out] assert_equal 'secret', mapping.path_names[:password] @@ -78,7 +78,7 @@ class MappingTest < ActiveSupport::TestCase end test 'has an empty path as default path prefix' do - mapping = Devise.mappings[:account] + mapping = Devise.mappings[:user] assert_equal '/', mapping.path_prefix end @@ -88,20 +88,20 @@ class MappingTest < ActiveSupport::TestCase end test 'retrieve as from the proper position' do - assert_equal 1, Devise.mappings[:account].as_position + assert_equal 1, Devise.mappings[:user].as_position assert_equal 2, Devise.mappings[:manager].as_position end test 'raw path is returned' do - assert_equal '/account', Devise.mappings[:account].raw_path - assert_equal '/:locale/organizers', Devise.mappings[:manager].raw_path + assert_equal '/users', Devise.mappings[:user].raw_path + assert_equal '/:locale/accounts', Devise.mappings[:manager].raw_path end test 'parsed path is returned' do begin Devise.default_url_options {{ :locale => I18n.locale }} - assert_equal '/account', Devise.mappings[:account].parsed_path - assert_equal '/en/organizers', Devise.mappings[:manager].parsed_path + assert_equal '/users', Devise.mappings[:user].parsed_path + assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path ensure Devise.default_url_options {{ }} end diff --git a/test/models_test.rb b/test/models_test.rb index 3e3238aa..9286cf0c 100644 --- a/test/models_test.rb +++ b/test/models_test.rb @@ -24,7 +24,7 @@ class Timeoutable < User devise :authenticatable, :timeoutable end -class Validatable < User +class IsValidatable < User devise :authenticatable, :validatable end @@ -85,7 +85,7 @@ class ActiveRecordTest < ActiveSupport::TestCase end test 'add validatable module only' do - assert_include_modules Validatable, :authenticatable, :validatable + assert_include_modules IsValidatable, :authenticatable, :validatable end test 'add all modules' do diff --git a/test/orm/active_record.rb b/test/orm/active_record.rb new file mode 100644 index 00000000..e76ba090 --- /dev/null +++ b/test/orm/active_record.rb @@ -0,0 +1,29 @@ +require File.join(File.dirname(__FILE__), '..', 'rails_app', 'config', 'environment') + +ActiveRecord::Migration.verbose = false +ActiveRecord::Base.logger = Logger.new(nil) +ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") + +ActiveRecord::Schema.define(:version => 1) do + [:users, :admins, :accounts].each do |table| + create_table table do |t| + t.authenticatable :null => table == :admins + + if table != :admin + t.string :username + t.confirmable + t.recoverable + t.rememberable + t.trackable + end + + t.timestamps + end + end +end + +require 'test_help' +class ActiveSupport::TestCase + self.use_transactional_fixtures = true + self.use_instantiated_fixtures = false +end diff --git a/test/orm/mongo_mapper.rb b/test/orm/mongo_mapper.rb new file mode 100644 index 00000000..c2d1631a --- /dev/null +++ b/test/orm/mongo_mapper.rb @@ -0,0 +1,14 @@ +require 'mongo_mapper' +MongoMapper.database = "devise-test-suite" +MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017) +require File.join(File.dirname(__FILE__), '..', 'rails_app', 'config', 'environment') + +require 'test_help' + +class ActiveSupport::TestCase + setup do + User.delete_all + Admin.delete_all + Account.delete_all + end +end \ No newline at end of file diff --git a/test/rails_app/app/models/account.rb b/test/rails_app/app/active_record/account.rb similarity index 100% rename from test/rails_app/app/models/account.rb rename to test/rails_app/app/active_record/account.rb diff --git a/test/rails_app/app/models/admin.rb b/test/rails_app/app/active_record/admin.rb similarity index 100% rename from test/rails_app/app/models/admin.rb rename to test/rails_app/app/active_record/admin.rb diff --git a/test/rails_app/app/models/user.rb b/test/rails_app/app/active_record/user.rb similarity index 100% rename from test/rails_app/app/models/user.rb rename to test/rails_app/app/active_record/user.rb diff --git a/test/rails_app/app/models/organizer.rb b/test/rails_app/app/models/organizer.rb deleted file mode 100644 index 4e628d47..00000000 --- a/test/rails_app/app/models/organizer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Organizer < ActiveRecord::Base - devise :all -end diff --git a/test/rails_app/app/mongo_mapper/account.rb b/test/rails_app/app/mongo_mapper/account.rb new file mode 100644 index 00000000..8c69e687 --- /dev/null +++ b/test/rails_app/app/mongo_mapper/account.rb @@ -0,0 +1,9 @@ +class Account + include MongoMapper::Document + + devise :all + + def self.find_for_authentication(conditions) + nil + end +end diff --git a/test/rails_app/app/mongo_mapper/admin.rb b/test/rails_app/app/mongo_mapper/admin.rb new file mode 100644 index 00000000..2be4d2c3 --- /dev/null +++ b/test/rails_app/app/mongo_mapper/admin.rb @@ -0,0 +1,9 @@ +class Admin + include MongoMapper::Document + + devise :all, :timeoutable, :except => [:recoverable, :confirmable, :rememberable, :validatable, :trackable] + + def self.find_for_authentication(conditions) + last(:conditions => conditions) + end +end diff --git a/test/rails_app/app/mongo_mapper/user.rb b/test/rails_app/app/mongo_mapper/user.rb new file mode 100644 index 00000000..c58b8429 --- /dev/null +++ b/test/rails_app/app/mongo_mapper/user.rb @@ -0,0 +1,5 @@ +class User + include MongoMapper::Document + devise :all, :timeoutable + # attr_accessible :username, :email, :password, :password_confirmation +end diff --git a/test/rails_app/config/environment.rb b/test/rails_app/config/environment.rb index 12c3a828..01ad187c 100644 --- a/test/rails_app/config/environment.rb +++ b/test/rails_app/config/environment.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION +RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -12,7 +12,7 @@ Rails::Initializer.run do |config| # -- all .rb files in that directory are automatically loaded. # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) + config.load_paths += [ "#{RAILS_ROOT}/app/#{DEVISE_ORM}/" ] # Specify gems that this application depends on and have them installed with rake gems:install # config.gem "bj" @@ -26,7 +26,7 @@ Rails::Initializer.run do |config| # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] + config.frameworks -= [ :active_record ] unless DEVISE_ORM == :active_record # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index af7a0140..75778c04 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -46,8 +46,8 @@ Devise.setup do |config| # config.mailer_sender = "foo.bar@yourapp.com" # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper. - # require 'devise/orm/mongo_mapper' - # config.orm = :mongo_mapper + require "devise/orm/#{DEVISE_ORM}" + config.orm = DEVISE_ORM # Turn scoped views on. Before rendering "sessions/new", it will first check for # "sessions/users/new". It's turned off by default because it's slower if you diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index b279089d..30542845 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -1,12 +1,9 @@ ActionController::Routing::Routes.draw do |map| map.devise_for :users map.devise_for :admin, :as => 'admin_area' - map.devise_for :account, :path_names => { + map.devise_for :accounts, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' - } - map.devise_for :organizers, :scope => 'manager', - :path_prefix => '/:locale', - :requirements => { :extra => 'value' } + }, :scope => 'manager', :path_prefix => '/:locale', :requirements => { :extra => 'value' } map.resources :users, :only => [:index], :member => { :expire => :get } map.resources :admins, :only => :index diff --git a/test/routes_test.rb b/test/routes_test.rb index accf8b8a..ac8928a6 100644 --- a/test/routes_test.rb +++ b/test/routes_test.rb @@ -53,30 +53,18 @@ class MapRoutingTest < ActionController::TestCase end test 'map account with custom path name for session sign in' do - assert_recognizes({:controller => 'sessions', :action => 'new'}, 'account/login') + assert_recognizes({:controller => 'sessions', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/login') end test 'map account with custom path name for session sign out' do - assert_recognizes({:controller => 'sessions', :action => 'destroy'}, 'account/logout') + assert_recognizes({:controller => 'sessions', :action => 'destroy', :locale => 'en', :extra => 'value'}, '/en/accounts/logout') end test 'map account with custom path name for password' do - assert_recognizes({:controller => 'passwords', :action => 'new'}, 'account/secret/new') + assert_recognizes({:controller => 'passwords', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/secret/new') end test 'map account with custom path name for confirmation' do - assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'account/verification/new') - end - - test 'map organizer with custom singular name' do - assert_recognizes({:controller => 'passwords', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/password/new') - end - - test 'map organizer with path prefix' do - assert_recognizes({:controller => 'sessions', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/sign_in') - end - - test 'map organizer with additional route options' do - assert_recognizes({:controller => 'passwords', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/password/new') + assert_recognizes({:controller => 'confirmations', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/verification/new') end end diff --git a/test/test_helper.rb b/test/test_helper.rb index bd345e10..eed202cf 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,9 @@ -ENV["RAILS_ENV"] = "test" -require File.join(File.dirname(__FILE__), 'rails_app', 'config', 'environment') +require 'rubygems' + +ENV["RAILS_ENV"] = "test" +DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym +require File.join(File.dirname(__FILE__), 'orm', DEVISE_ORM.to_s) -require 'test_help' require 'webrat' require 'mocha' @@ -11,34 +13,7 @@ ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.default_url_options[:host] = 'test.com' -ActiveRecord::Migration.verbose = false -ActiveRecord::Base.logger = Logger.new(nil) -ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") - -ActiveRecord::Schema.define(:version => 1) do - [:users, :admins, :accounts].each do |table| - create_table table do |t| - t.authenticatable :null => table == :admins - - if table != :admin - t.string :username - t.confirmable - t.recoverable - t.rememberable - t.trackable - end - - t.timestamps - end - end -end - Webrat.configure do |config| config.mode = :rails config.open_error_files = false -end - -class ActiveSupport::TestCase - self.use_transactional_fixtures = true - self.use_instantiated_fixtures = false -end +end \ No newline at end of file