Permalink
Browse files

Update test models to support Oauth testing

  • Loading branch information...
jm81 committed Jul 28, 2010
1 parent 4d4448f commit 4f890ed0505314627b99f5f0589edc66a62b18fa
View
@@ -22,7 +22,7 @@ README http://github.com/plataformatec/devise/blob/master/README.rdoc
Last tested against devise release: v1.1.1
-Last tested against devise master: 2010-07-27, commit 879b64edc945e3531e65abf4a6b7970052927e39
+Last tested against devise master: 2010-07-28, commit a707423d23bd0cf25472839d14ef612f826cb15f
== Installation
@@ -1,12 +1,11 @@
+require 'shared_admin'
+
class Admin
- include DataMapper::Resource
-
+ include DataMapper::Resource
+
property :id, Serial
property :username, String
-
- devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
-
- def self.create!(*args)
- create(*args)
- end
+
+ include SharedAdmin
+ include Shim
end
@@ -1,2 +1,25 @@
+# Shim should be included after SharedUser / SharedAdmin
module Shim
+ def self.included(klass)
+ klass.extend(ModelMethods)
+ end
+
+ module ModelMethods
+ # Override version in SharedUser which uses #find_by_email.
+ def find_for_facebook_oauth(access_token, signed_in_resource=nil)
+ data = ActiveSupport::JSON.decode(access_token.get('/me'))
+ user = signed_in_resource || User.first(:email => data["email"]) || User.new
+ user.update_with_facebook_oauth(access_token, data)
+ user.save
+ user
+ end
+
+ def create!(*args)
+ create(*args)
+ end
+
+ def destroy_all
+ all.destroy
+ end
+ end
end
@@ -1,20 +1,27 @@
+require 'shared_user'
+
class User
include DataMapper::Resource
property :id, Serial
property :username, String
-
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
- :trackable, :validatable
-
+ property :facebook_token, String
timestamps :at
-
- def self.create!(*args)
- create(*args)
- end
-
- def self.destroy_all
- all.destroy
- end
+
+ include SharedUser
+ include Shim
+
+ unless DEVISE_ORM == :data_mapper_active_model
+ before :valid?, :update_password_confirmation
+
+ # DM's validates_confirmation_of requires the confirmation field to be present,
+ # while ActiveModel by default skips the confirmation test if the confirmation
+ # value is nil. This test takes advantage of AM's behavior, so just add the
+ # :password_confirmation value.
+ def update_password_confirmation
+ if self.password && self.password_confirmation.nil?
+ self.password_confirmation = self.password
+ end
+ end
+ end
end
@@ -1,12 +1,12 @@
+require 'shared_admin'
+require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
+
class Admin
- include DataMapper::Resource
-
+ include DataMapper::Resource
+
property :id, Serial
property :username, String
-
- devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
-
- def self.create!(*args)
- create(*args)
- end
+
+ include SharedAdmin
+ include Shim
end
@@ -1,2 +0,0 @@
-module Shim
-end
@@ -1,20 +1,14 @@
+require 'shared_user'
+require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
+
class User
include DataMapper::Resource
property :id, Serial
property :username, String
-
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
- :trackable, :validatable
-
+ property :facebook_token, String
timestamps :at
-
- def self.create!(*args)
- create(*args)
- end
-
- def self.destroy_all
- all.destroy
- end
+
+ include SharedUser
+ include Shim
end
View
@@ -16,6 +16,8 @@
config.open_error_files = false
end
+Devise::Oauth.test_mode!
+
# Add support to load paths so we can overwrite broken webrat setup
$:.unshift "#{DEVISE_PATH}/test/support"
Dir["#{DEVISE_PATH}/test/support/**/*.rb"].each { |f| require f }

0 comments on commit 4f890ed

Please sign in to comment.