dm-devise 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gem "warden", "0.10.7"
6
6
  gem "webrat", "0.7.0"
7
7
  gem "mocha", :require => false
8
8
  gem "bcrypt-ruby", :require => "bcrypt"
9
+ gem "oauth2"
9
10
 
10
11
  gem 'dm-core', '~> 1.0.0'
11
12
  gem 'dm-migrations', '~> 1.0.0'
data/Gemfile.lock CHANGED
@@ -11,46 +11,47 @@ GIT
11
11
 
12
12
  GIT
13
13
  remote: git://github.com/rails/rails.git
14
- revision: 8079484
14
+ revision: 4952a80
15
15
  specs:
16
- actionmailer (3.0.0.beta4)
17
- actionpack (= 3.0.0.beta4)
18
- mail (~> 2.2.3)
19
- actionpack (3.0.0.beta4)
20
- activemodel (= 3.0.0.beta4)
21
- activesupport (= 3.0.0.beta4)
16
+ actionmailer (3.0.0.rc)
17
+ actionpack (= 3.0.0.rc)
18
+ mail (~> 2.2.5)
19
+ actionpack (3.0.0.rc)
20
+ activemodel (= 3.0.0.rc)
21
+ activesupport (= 3.0.0.rc)
22
22
  builder (~> 2.1.2)
23
23
  erubis (~> 2.6.6)
24
24
  i18n (~> 0.4.1)
25
25
  rack (~> 1.2.1)
26
+ rack-mount (~> 0.6.9)
26
27
  rack-test (~> 0.5.4)
27
- tzinfo (~> 0.3.16)
28
- activemodel (3.0.0.beta4)
29
- activesupport (= 3.0.0.beta4)
28
+ tzinfo (~> 0.3.22)
29
+ activemodel (3.0.0.rc)
30
+ activesupport (= 3.0.0.rc)
30
31
  builder (~> 2.1.2)
31
32
  i18n (~> 0.4.1)
32
- activerecord (3.0.0.beta4)
33
- activemodel (= 3.0.0.beta4)
34
- activesupport (= 3.0.0.beta4)
33
+ activerecord (3.0.0.rc)
34
+ activemodel (= 3.0.0.rc)
35
+ activesupport (= 3.0.0.rc)
35
36
  arel (~> 0.4.0)
36
- tzinfo (~> 0.3.16)
37
- activeresource (3.0.0.beta4)
38
- activemodel (= 3.0.0.beta4)
39
- activesupport (= 3.0.0.beta4)
40
- activesupport (3.0.0.beta4)
41
- rails (3.0.0.beta4)
42
- actionmailer (= 3.0.0.beta4)
43
- actionpack (= 3.0.0.beta4)
44
- activerecord (= 3.0.0.beta4)
45
- activeresource (= 3.0.0.beta4)
46
- activesupport (= 3.0.0.beta4)
47
- bundler (>= 1.0.0.beta.2)
48
- railties (= 3.0.0.beta4)
49
- railties (3.0.0.beta4)
50
- actionpack (= 3.0.0.beta4)
51
- activesupport (= 3.0.0.beta4)
37
+ tzinfo (~> 0.3.22)
38
+ activeresource (3.0.0.rc)
39
+ activemodel (= 3.0.0.rc)
40
+ activesupport (= 3.0.0.rc)
41
+ activesupport (3.0.0.rc)
42
+ rails (3.0.0.rc)
43
+ actionmailer (= 3.0.0.rc)
44
+ actionpack (= 3.0.0.rc)
45
+ activerecord (= 3.0.0.rc)
46
+ activeresource (= 3.0.0.rc)
47
+ activesupport (= 3.0.0.rc)
48
+ bundler (>= 1.0.0.rc.1)
49
+ railties (= 3.0.0.rc)
50
+ railties (3.0.0.rc)
51
+ actionpack (= 3.0.0.rc)
52
+ activesupport (= 3.0.0.rc)
52
53
  rake (>= 0.8.3)
53
- thor (~> 0.13.7)
54
+ thor (~> 0.14.0)
54
55
 
55
56
  GEM
56
57
  remote: http://rubygems.org/
@@ -90,6 +91,9 @@ GEM
90
91
  erubis (2.6.6)
91
92
  abstract (>= 1.0.0)
92
93
  extlib (0.9.15)
94
+ faraday (0.4.6)
95
+ addressable (>= 2.1.1)
96
+ rack (>= 1.0.1)
93
97
  fastercsv (1.5.3)
94
98
  i18n (0.4.1)
95
99
  json_pure (1.4.3)
@@ -100,13 +104,19 @@ GEM
100
104
  mime-types (1.16)
101
105
  mocha (0.9.8)
102
106
  rake
107
+ multi_json (0.0.4)
103
108
  nokogiri (1.4.2)
109
+ oauth2 (0.0.10)
110
+ faraday (~> 0.4.1)
111
+ multi_json (>= 0.0.4)
104
112
  polyglot (0.3.1)
105
113
  rack (1.2.1)
114
+ rack-mount (0.6.9)
115
+ rack (>= 1.0.0)
106
116
  rack-test (0.5.4)
107
117
  rack (>= 1.0)
108
118
  rake (0.8.7)
109
- thor (0.13.7)
119
+ thor (0.14.0)
110
120
  treetop (1.4.8)
111
121
  polyglot (>= 0.3.1)
112
122
  tzinfo (0.3.22)
@@ -130,6 +140,7 @@ DEPENDENCIES
130
140
  dm-timestamps (~> 1.0.0)
131
141
  dm-validations (~> 1.0.0)
132
142
  mocha
143
+ oauth2
133
144
  rails!
134
145
  warden (= 0.10.7)
135
146
  webrat (= 0.7.0)
data/README.rdoc CHANGED
@@ -22,7 +22,7 @@ README http://github.com/plataformatec/devise/blob/master/README.rdoc
22
22
 
23
23
  Last tested against devise release: v1.1.1
24
24
 
25
- Last tested against devise master: 2010-07-27, commit 879b64edc945e3531e65abf4a6b7970052927e39
25
+ Last tested against devise master: 2010-08-04, commit c0c7aefce4a2a0ba2b85c1185abf73cb213cd79c
26
26
 
27
27
  == Installation
28
28
 
data/Rakefile CHANGED
@@ -28,10 +28,7 @@ Rake::TestTask.new(:test) do |test|
28
28
  test.libs << 'lib' << 'test'
29
29
  test.libs << "#{ENV['DEVISE_PATH']}/lib"
30
30
  test.libs << "#{ENV['DEVISE_PATH']}/test"
31
- # Need to ensure overrides tests are loaded last
32
- overrides = ['test/overrides/data_mapper_test.rb']
33
- overrides += ['test/overrides/dm_validations_test.rb'] if ENV['DEVISE_ORM'] == 'data_mapper'
34
- test.test_files = FileList["#{ENV['DEVISE_PATH']}/test/**/*_test.rb"] + overrides
31
+ test.test_files = FileList["#{ENV['DEVISE_PATH']}/test/**/*_test.rb"] + FileList['test/**/*_test.rb']
35
32
  test.verbose = true
36
33
  end
37
34
 
data/dm-devise.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-devise}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jared Morgan"]
12
- s.date = %q{2010-07-28}
12
+ s.date = %q{2010-08-05}
13
13
  s.description = %q{dm-devise adds DataMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails}
14
14
  s.email = %q{jmorgan@morgancreative.net}
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/devise/orm/data_mapper_active_model.rb",
34
34
  "lib/dm-devise/version.rb",
35
35
  "lib/generators/data_mapper/devise_generator.rb",
36
+ "test/data_mapper/compatibility_test.rb",
36
37
  "test/orm/data_mapper.rb",
37
38
  "test/orm/data_mapper_active_model.rb",
38
39
  "test/overrides/data_mapper_test.rb",
@@ -41,7 +42,6 @@ Gem::Specification.new do |s|
41
42
  "test/rails_app/app/data_mapper/shim.rb",
42
43
  "test/rails_app/app/data_mapper/user.rb",
43
44
  "test/rails_app/app/data_mapper_active_model/admin.rb",
44
- "test/rails_app/app/data_mapper_active_model/shim.rb",
45
45
  "test/rails_app/app/data_mapper_active_model/user.rb",
46
46
  "test/rails_app/config/application.rb",
47
47
  "test/rails_app/config/environment.rb",
@@ -54,13 +54,13 @@ Gem::Specification.new do |s|
54
54
  s.summary = %q{Support for using DataMapper ORM with devise}
55
55
  s.test_files = [
56
56
  "test/test_helper.rb",
57
+ "test/data_mapper/compatibility_test.rb",
57
58
  "test/rails_app/config/environment.rb",
58
59
  "test/rails_app/config/application.rb",
59
60
  "test/rails_app/app/data_mapper/admin.rb",
60
61
  "test/rails_app/app/data_mapper/shim.rb",
61
62
  "test/rails_app/app/data_mapper/user.rb",
62
63
  "test/rails_app/app/data_mapper_active_model/admin.rb",
63
- "test/rails_app/app/data_mapper_active_model/shim.rb",
64
64
  "test/rails_app/app/data_mapper_active_model/user.rb",
65
65
  "test/overrides/data_mapper_test.rb",
66
66
  "test/overrides/dm_validations_test.rb",
@@ -51,11 +51,14 @@ module Devise
51
51
  if options.is_a?(Hash) && options[:validate] == false
52
52
  save!
53
53
  else
54
- # valid? checking isn't added automatically with ActiveModel
55
- valid? && super()
54
+ super()
56
55
  end
57
56
  end
58
57
 
58
+ def update_attribute(name, value)
59
+ update(name => value)
60
+ end
61
+
59
62
  def update_attributes(*args)
60
63
  update(*args)
61
64
  end
@@ -8,8 +8,9 @@ module Devise
8
8
  module Hook
9
9
  def devise_modules_hook!
10
10
  extend Schema
11
- include Compatibility
12
11
  include ActiveModel::Validations
12
+ include ActiveModelCompatibility
13
+ include Compatibility
13
14
  class << self; attr_reader :descendants; end;
14
15
 
15
16
  def self.validates_uniqueness_of(*fields)
@@ -33,6 +34,18 @@ module Devise
33
34
  end
34
35
  end
35
36
  end
37
+
38
+ module ActiveModelCompatibility
39
+ # include ActiveModel::Validations does not make save check valid?.
40
+ # This may not be the best solution, but it seems to work. Note that
41
+ # Compatibility is included after this module; its #save method handles
42
+ # the :validate => false option.
43
+ def save(*args)
44
+ retval = valid? && super(*args)
45
+ assert_save_successful(:save, retval)
46
+ retval
47
+ end
48
+ end
36
49
  end
37
50
  end
38
51
  end
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Devise
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.1.1'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class DataMapperCompatibilityTest < ActiveSupport::TestCase
4
+ def teardown
5
+ User.raise_on_save_failure = false
6
+ end
7
+
8
+ test 'respects raise_on_save_failure' do
9
+ User.raise_on_save_failure = true
10
+ user = new_user(:email => nil)
11
+ assert user.invalid?
12
+ assert_raise DataMapper::SaveFailureError do
13
+ user.save
14
+ end
15
+
16
+ user = new_user
17
+ assert user.valid?
18
+ assert user.save
19
+
20
+ User.raise_on_save_failure = false
21
+ user = new_user(:email => nil)
22
+ assert !user.save
23
+ end
24
+ end
@@ -1,43 +1,46 @@
1
1
  require 'test_helper'
2
2
 
3
3
  # See data_mapper_test.rb in this folder for what this file is doing.
4
+ if DEVISE_ORM == :data_mapper
5
+
6
+ class ValidatableTest < ActiveSupport::TestCase
7
+ undef test_should_require_a_password_with_minimum_of_6_characters
8
+
9
+ # DataMapper uses a :value_between error message when given a minimum and
10
+ # maximum; ActiveModel shows either the :too_long or :too_short message.
11
+ test 'should require a password with minimum of 6 characters' do
12
+ user = new_user(:password => '12345', :password_confirmation => '12345')
13
+ assert user.invalid?
14
+ # assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
15
+ assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join
16
+ end
4
17
 
5
- class ValidatableTest < ActiveSupport::TestCase
6
- undef test_should_require_a_password_with_minimum_of_6_characters
7
-
8
- # DataMapper uses a :value_between error message when given a minimum and
9
- # maximum; ActiveModel shows either the :too_long or :too_short message.
10
- test 'should require a password with minimum of 6 characters' do
11
- user = new_user(:password => '12345', :password_confirmation => '12345')
12
- assert user.invalid?
13
- # assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
14
- assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join
15
- end
18
+ undef test_should_require_a_password_with_maximum_of_20_characters_long
16
19
 
17
- undef test_should_require_a_password_with_maximum_of_20_characters_long
20
+ # Same issue as previous test
21
+ test 'should require a password with maximum of 20 characters long' do
22
+ user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
23
+ assert user.invalid?
24
+ # assert_equal 'is too long (maximum is 20 characters)', user.errors[:password].join
25
+ assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join
26
+ end
18
27
 
19
- # Same issue as previous test
20
- test 'should require a password with maximum of 20 characters long' do
21
- user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
22
- assert user.invalid?
23
- # assert_equal 'is too long (maximum is 20 characters)', user.errors[:password].join
24
- assert_equal 'must be between 6 and 20 characters long', user.errors[:password].join
25
28
  end
26
29
 
27
- end
28
-
29
- class AuthenticationOthersTest < ActionController::IntegrationTest
30
+ class AuthenticationOthersTest < ActionController::IntegrationTest
30
31
 
31
- undef test_registration_in_xml_format
32
+ undef test_registration_in_xml_format_works_when_recognizing_path
32
33
 
33
- # DM's validates_confirmation_of requires the confirmation field to be present,
34
- # while ActiveModel by default skips the confirmation test if the confirmation
35
- # value is nil. This test takes advantage of AM's behavior, so just add the
36
- # :password_confirmation value.
37
- test 'registration in xml format' do
38
- assert_nothing_raised do
39
- # post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
40
- post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid", :password_confirmation => "invalid"} )
34
+ # DM's validates_confirmation_of requires the confirmation field to be present,
35
+ # while ActiveModel by default skips the confirmation test if the confirmation
36
+ # value is nil. This test takes advantage of AM's behavior, so just add the
37
+ # :password_confirmation value.
38
+ test 'registration in xml format works when recognizing path' do
39
+ assert_nothing_raised do
40
+ # post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid"} )
41
+ post user_registration_path(:format => 'xml', :user => {:email => "test@example.com", :password => "invalid", :password_confirmation => "invalid"} )
42
+ end
41
43
  end
42
44
  end
45
+
43
46
  end
@@ -1,12 +1,11 @@
1
+ require 'shared_admin'
2
+
1
3
  class Admin
2
- include DataMapper::Resource
3
-
4
+ include DataMapper::Resource
5
+
4
6
  property :id, Serial
5
7
  property :username, String
6
-
7
- devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
8
-
9
- def self.create!(*args)
10
- create(*args)
11
- end
8
+
9
+ include SharedAdmin
10
+ include Shim
12
11
  end
@@ -1,2 +1,25 @@
1
+ # Shim should be included after SharedUser / SharedAdmin
1
2
  module Shim
3
+ def self.included(klass)
4
+ klass.extend(ModelMethods)
5
+ end
6
+
7
+ module ModelMethods
8
+ # Override version in SharedUser which uses #find_by_email.
9
+ def find_for_facebook_oauth(access_token, signed_in_resource=nil)
10
+ data = ActiveSupport::JSON.decode(access_token.get('/me'))
11
+ user = signed_in_resource || User.first(:email => data["email"]) || User.new
12
+ user.update_with_facebook_oauth(access_token, data)
13
+ user.save
14
+ user
15
+ end
16
+
17
+ def create!(*args)
18
+ create(*args)
19
+ end
20
+
21
+ def destroy_all
22
+ all.destroy
23
+ end
24
+ end
2
25
  end
@@ -1,20 +1,27 @@
1
+ require 'shared_user'
2
+
1
3
  class User
2
4
  include DataMapper::Resource
3
5
 
4
6
  property :id, Serial
5
7
  property :username, String
6
-
7
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
8
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
9
- :trackable, :validatable
10
-
8
+ property :facebook_token, String
11
9
  timestamps :at
12
-
13
- def self.create!(*args)
14
- create(*args)
15
- end
16
-
17
- def self.destroy_all
18
- all.destroy
19
- end
10
+
11
+ include SharedUser
12
+ include Shim
13
+
14
+ unless DEVISE_ORM == :data_mapper_active_model
15
+ before :valid?, :update_password_confirmation
16
+
17
+ # DM's validates_confirmation_of requires the confirmation field to be present,
18
+ # while ActiveModel by default skips the confirmation test if the confirmation
19
+ # value is nil. This test takes advantage of AM's behavior, so just add the
20
+ # :password_confirmation value.
21
+ def update_password_confirmation
22
+ if self.password && self.password_confirmation.nil?
23
+ self.password_confirmation = self.password
24
+ end
25
+ end
26
+ end
20
27
  end
@@ -1,12 +1,12 @@
1
+ require 'shared_admin'
2
+ require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
3
+
1
4
  class Admin
2
- include DataMapper::Resource
3
-
5
+ include DataMapper::Resource
6
+
4
7
  property :id, Serial
5
8
  property :username, String
6
-
7
- devise :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :unlock_strategy => :time
8
-
9
- def self.create!(*args)
10
- create(*args)
11
- end
9
+
10
+ include SharedAdmin
11
+ include Shim
12
12
  end
@@ -1,20 +1,14 @@
1
+ require 'shared_user'
2
+ require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
3
+
1
4
  class User
2
5
  include DataMapper::Resource
3
6
 
4
7
  property :id, Serial
5
8
  property :username, String
6
-
7
- devise :database_authenticatable, :confirmable, :lockable, :recoverable,
8
- :registerable, :rememberable, :timeoutable, :token_authenticatable,
9
- :trackable, :validatable
10
-
9
+ property :facebook_token, String
11
10
  timestamps :at
12
-
13
- def self.create!(*args)
14
- create(*args)
15
- end
16
-
17
- def self.destroy_all
18
- all.destroy
19
- end
11
+
12
+ include SharedUser
13
+ include Shim
20
14
  end
data/test/test_helper.rb CHANGED
@@ -16,6 +16,8 @@ Webrat.configure do |config|
16
16
  config.open_error_files = false
17
17
  end
18
18
 
19
+ Devise::Oauth.test_mode!
20
+
19
21
  # Add support to load paths so we can overwrite broken webrat setup
20
22
  $:.unshift "#{DEVISE_PATH}/test/support"
21
23
  Dir["#{DEVISE_PATH}/test/support/**/*.rb"].each { |f| require f }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-devise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 0
10
- version: 1.1.0
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jared Morgan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-28 00:00:00 -05:00
18
+ date: 2010-08-05 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -186,6 +186,7 @@ files:
186
186
  - lib/devise/orm/data_mapper_active_model.rb
187
187
  - lib/dm-devise/version.rb
188
188
  - lib/generators/data_mapper/devise_generator.rb
189
+ - test/data_mapper/compatibility_test.rb
189
190
  - test/orm/data_mapper.rb
190
191
  - test/orm/data_mapper_active_model.rb
191
192
  - test/overrides/data_mapper_test.rb
@@ -194,7 +195,6 @@ files:
194
195
  - test/rails_app/app/data_mapper/shim.rb
195
196
  - test/rails_app/app/data_mapper/user.rb
196
197
  - test/rails_app/app/data_mapper_active_model/admin.rb
197
- - test/rails_app/app/data_mapper_active_model/shim.rb
198
198
  - test/rails_app/app/data_mapper_active_model/user.rb
199
199
  - test/rails_app/config/application.rb
200
200
  - test/rails_app/config/environment.rb
@@ -235,13 +235,13 @@ specification_version: 3
235
235
  summary: Support for using DataMapper ORM with devise
236
236
  test_files:
237
237
  - test/test_helper.rb
238
+ - test/data_mapper/compatibility_test.rb
238
239
  - test/rails_app/config/environment.rb
239
240
  - test/rails_app/config/application.rb
240
241
  - test/rails_app/app/data_mapper/admin.rb
241
242
  - test/rails_app/app/data_mapper/shim.rb
242
243
  - test/rails_app/app/data_mapper/user.rb
243
244
  - test/rails_app/app/data_mapper_active_model/admin.rb
244
- - test/rails_app/app/data_mapper_active_model/shim.rb
245
245
  - test/rails_app/app/data_mapper_active_model/user.rb
246
246
  - test/overrides/data_mapper_test.rb
247
247
  - test/overrides/dm_validations_test.rb
@@ -1,2 +0,0 @@
1
- module Shim
2
- end