From bb504e08aa61d915d99680581ef7a7be67fec64a Mon Sep 17 00:00:00 2001 From: Jacques Crocker Date: Sat, 27 Mar 2010 16:15:23 -0700 Subject: [PATCH] Initial Datamapper test suite Test suite runs, however there's still some failing tests. This allows us to at least have a working test suite so they can fix these datamapper spec failures individually. --- Gemfile | 9 +++++++++ lib/devise/orm/data_mapper.rb | 20 ++++++++++++++------ test/orm/data_mapper.rb | 4 ++++ test/rails_app/app/data_mapper/admin.rb | 17 +++++++++++++++++ test/rails_app/app/data_mapper/user.rb | 21 +++++++++++++++++++++ 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 test/orm/data_mapper.rb create mode 100644 test/rails_app/app/data_mapper/admin.rb create mode 100644 test/rails_app/app/data_mapper/user.rb diff --git a/Gemfile b/Gemfile index f96015b0..6a85736a 100644 --- a/Gemfile +++ b/Gemfile @@ -16,4 +16,13 @@ group :mongoid do gem "mongo", ">= 0.18.3" gem "mongo_ext", ">= 0.18.3", :require => false gem "mongoid", :git => "git://github.com/durran/mongoid.git" +end + +group :data_mapper do + gem 'do_sqlite3', '>= 0.10.1' + gem "dm-core", :git => "git://github.com/datamapper/dm-core.git" + + gem "dm-validations", :git => "git://github.com/datamapper/dm-more.git" + gem "dm-timestamps", :git => "git://github.com/datamapper/dm-more.git" + gem "dm-rails", :git => "git://github.com/datamapper/dm-rails.git" end \ No newline at end of file diff --git a/lib/devise/orm/data_mapper.rb b/lib/devise/orm/data_mapper.rb index 5fb75d5a..6b045238 100644 --- a/lib/devise/orm/data_mapper.rb +++ b/lib/devise/orm/data_mapper.rb @@ -38,18 +38,22 @@ module Devise module ClassMethods # Hooks for confirmable def before_create(*args) - wrap_hook(:before, *args) + wrap_hook(:before, :create, *args) end def after_create(*args) - wrap_hook(:after, *args) + wrap_hook(:after, :create, *args) + end + + def before_save(*args) + wrap_hook(:before, :save, *args) end - def wrap_hook(action, *args) + def wrap_hook(action, method, *args) options = args.extract_options! args.each do |callback| - send action, :create, callback + send action, method, callback class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{callback} super if #{options[:if] || true} @@ -68,10 +72,14 @@ module Devise end end end - + + def changed? + dirty? + end + def save(options=nil) if options.is_a?(Hash) && options[:validate] == false - save! + save else super() end diff --git a/test/orm/data_mapper.rb b/test/orm/data_mapper.rb new file mode 100644 index 00000000..f33d935a --- /dev/null +++ b/test/orm/data_mapper.rb @@ -0,0 +1,4 @@ +require File.expand_path('../../rails_app/config/environment', __FILE__) +require 'rails/test_help' + +DataMapper.auto_migrate! diff --git a/test/rails_app/app/data_mapper/admin.rb b/test/rails_app/app/data_mapper/admin.rb new file mode 100644 index 00000000..3e16eda7 --- /dev/null +++ b/test/rails_app/app/data_mapper/admin.rb @@ -0,0 +1,17 @@ +class Admin + include DataMapper::Resource + + property :id, Serial + property :username, String + + devise :authenticatable, :registerable, :timeoutable, :recoverable + + def self.find_for_authentication(conditions) + last(conditions) + end + + def self.create!(*args) + create(*args) + end + +end diff --git a/test/rails_app/app/data_mapper/user.rb b/test/rails_app/app/data_mapper/user.rb new file mode 100644 index 00000000..6c8fcd58 --- /dev/null +++ b/test/rails_app/app/data_mapper/user.rb @@ -0,0 +1,21 @@ +class User + include DataMapper::Resource + + property :id, Serial + property :username, String + + devise :authenticatable, :http_authenticatable, :confirmable, :lockable, :recoverable, + :registerable, :rememberable, :timeoutable, :token_authenticatable, + :trackable + + # :validatable disabled for now + timestamps :at + + def save!(*args) + save + end + + def self.create!(*args) + create(*args) + end +end