dm-devise 1.4.0 → 1.5.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ == 1.5.0.beta
2
+
3
+ * enhancements
4
+ * determine validation library extensions to load based on which validation
5
+ library is loaded (dm-validations or Active Model)
6
+ * Add data_mapper_validation_messages config option so that default messages
7
+ can be overriden.
8
+ * Add data_mapper:devise_install generator with dm-devise related options
9
+
10
+ == 1.4.0
11
+
12
+ * enhancements
13
+ * Add Compatibility#email_changed? for email validations
14
+
15
+ == 1.3.1
16
+
17
+ * enhancements
18
+ * expired validation error message
19
+
20
+ == 1.3.0
21
+
22
+ * enhancements
23
+ * Add before_validation hook
24
+ * Add DataMapper::Validation::ValidationErrors#to_xml
25
+
26
+ == 1.2.0
27
+
28
+ * enhancements
29
+ * Verify compatibility with DM 1.1.0
30
+ * Ensure apply_schema won't try to re add an existing property
31
+
32
+ * bug fix
33
+ * Change DateTime#gmtime to use #new_offset instead of delegating to #to_time
34
+ * Correctly handle DataMapper required property option
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :test do
10
10
  gem 'mocha', :require => false
11
11
  end
12
12
 
13
- DM_VERSION = '~> 1.1.0.rc3'
13
+ DM_VERSION = '~> 1.1.0'
14
14
 
15
15
  group :development do
16
16
  gem 'rails', '~> 3.0.4'
@@ -23,6 +23,6 @@ group :development do
23
23
  gem 'dm-rails', DM_VERSION
24
24
  end
25
25
 
26
- group :data_mapper do
26
+ group :'dm-validations' do
27
27
  gem 'dm-validations', DM_VERSION
28
28
  end
data/Gemfile.lock CHANGED
@@ -1,14 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dm-devise (1.3.1)
4
+ dm-devise (1.5.0.beta)
5
5
  devise (~> 1.3)
6
6
  dm-core (>= 1.0.2, < 1.2)
7
7
  dm-migrations (>= 1.0.2, < 1.2)
8
8
  dm-rails (>= 1.0.3, < 1.2)
9
9
  dm-serializer (>= 1.0.2, < 1.2)
10
10
  dm-timestamps (>= 1.0.2, < 1.2)
11
- sugar-high (~> 0.2.10)
12
11
 
13
12
  GEM
14
13
  remote: http://rubygems.org/
@@ -46,7 +45,7 @@ GEM
46
45
  builder (2.1.2)
47
46
  data_objects (0.10.6)
48
47
  addressable (~> 2.1)
49
- devise (1.4.0)
48
+ devise (1.4.2)
50
49
  bcrypt-ruby (~> 2.1.2)
51
50
  orm_adapter (~> 0.0.3)
52
51
  warden (~> 1.0.3)
@@ -96,8 +95,8 @@ GEM
96
95
  mocha (0.9.12)
97
96
  multi_json (1.0.3)
98
97
  multi_xml (0.2.2)
99
- multipart-post (1.1.2)
100
- nokogiri (1.4.6)
98
+ multipart-post (1.1.3)
99
+ nokogiri (1.5.0)
101
100
  oa-core (0.2.6)
102
101
  oa-oauth (0.2.6)
103
102
  faraday (~> 0.6.1)
@@ -110,12 +109,12 @@ GEM
110
109
  oa-core (= 0.2.6)
111
110
  rack-openid (~> 1.3.1)
112
111
  ruby-openid-apps-discovery (~> 1.2.0)
113
- oauth (0.4.4)
112
+ oauth (0.4.5)
114
113
  oauth2 (0.4.1)
115
114
  faraday (~> 0.6.1)
116
115
  multi_json (>= 0.0.5)
117
116
  orm_adapter (0.0.5)
118
- polyglot (0.3.1)
117
+ polyglot (0.3.2)
119
118
  rack (1.2.3)
120
119
  rack-mount (0.6.14)
121
120
  rack (>= 1.0.0)
@@ -139,19 +138,16 @@ GEM
139
138
  rdoc (~> 3.4)
140
139
  thor (~> 0.14.4)
141
140
  rake (0.9.2)
142
- rdoc (3.6.1)
143
- require_all (1.2.0)
141
+ rdoc (3.8)
144
142
  ruby-openid (2.1.8)
145
143
  ruby-openid-apps-discovery (1.2.0)
146
144
  ruby-openid (>= 2.1.7)
147
- sugar-high (0.2.12)
148
- mocha (~> 0.9.8)
149
- require_all (~> 1.2.0)
150
145
  thor (0.14.6)
151
- treetop (1.4.9)
146
+ treetop (1.4.10)
147
+ polyglot
152
148
  polyglot (>= 0.3.1)
153
- tzinfo (0.3.28)
154
- warden (1.0.4)
149
+ tzinfo (0.3.29)
150
+ warden (1.0.5)
155
151
  rack (>= 1.0)
156
152
  webrat (0.7.2)
157
153
  nokogiri (>= 1.2.0)
@@ -162,14 +158,14 @@ PLATFORMS
162
158
  ruby
163
159
 
164
160
  DEPENDENCIES
165
- dm-core (~> 1.1.0.rc3)
161
+ dm-core (~> 1.1.0)
166
162
  dm-devise!
167
- dm-migrations (~> 1.1.0.rc3)
168
- dm-rails (~> 1.1.0.rc3)
169
- dm-serializer (~> 1.1.0.rc3)
170
- dm-sqlite-adapter (~> 1.1.0.rc3)
171
- dm-timestamps (~> 1.1.0.rc3)
172
- dm-validations (~> 1.1.0.rc3)
163
+ dm-migrations (~> 1.1.0)
164
+ dm-rails (~> 1.1.0)
165
+ dm-serializer (~> 1.1.0)
166
+ dm-sqlite-adapter (~> 1.1.0)
167
+ dm-timestamps (~> 1.1.0)
168
+ dm-validations (~> 1.1.0)
173
169
  mocha
174
170
  oa-oauth (~> 0.2.0)
175
171
  oa-openid (~> 0.2.0)
data/README.rdoc CHANGED
@@ -1,17 +1,7 @@
1
1
  = dm-devise
2
2
 
3
3
  dm-devise lets you use devise (http://github.com/plataformatec/devise) with
4
- DataMapper. The gem gives you the options of 2 ORM setups depending on what
5
- library you wish to use for validations:
6
-
7
- :data_mapper::
8
- Uses dm-validations. This involves a bit of monkey-patching, but you need to
9
- use this if you want auto-validations in *any* of your models.
10
- :data_mapper_active_model::
11
- Uses ActiveModel::Validations. Do not use if you require 'dm-validations'
12
- anywhere in your app (or include it in your Gemfile). Things will break.
13
- The advantage to this is ActiveModel's I18n support for error messages, and
14
- it uses the same validations lib as devise does by default.
4
+ DataMapper.
15
5
 
16
6
  dm-devise is intended for use with Rails 3 and devise >= 1.1. It may work with
17
7
  earlier versions, but it's not been tested (if you try, please let Jared Morgan
@@ -20,8 +10,8 @@ earlier versions, but it's not been tested (if you try, please let Jared Morgan
20
10
  This README only covers dm-devise specifics. Make sure to read the devise
21
11
  README http://github.com/plataformatec/devise/blob/master/README.rdoc
22
12
 
23
- Last tested against devise master: 2011-06-23, commit dba8f91f99dce0e102ad2e6aa78b142a92833bc3
24
- Last tested against devise release 1.4.0
13
+ Last tested against devise master: 2011-08-02, commit 919404df53a0ee9a8c5be50a3d74acf10ac2e38c
14
+ Last tested against devise release 1.4.2
25
15
 
26
16
  == Installation
27
17
 
@@ -33,9 +23,9 @@ Add dm-devise and dm gems to your Gemfile. The following gems are required:
33
23
  gem 'dm-timestamps', '~> 1.1.0'
34
24
  gem 'dm-rails', '~> 1.1.0'
35
25
  gem 'dm-validations', '~> 1.1.0' # Do not include if using data_mapper_active_model
36
- gem 'dm-devise', '~> 1.4.0'
26
+ gem 'dm-devise', '~> 1.5.0.beta'
37
27
 
38
- If you're using data_mapper_active_model do not include dm-validations in your
28
+ If you're using Active Model validations, do not include dm-validations in your
39
29
  Gemfile.
40
30
 
41
31
  dm-devise works with versions of DataMapper gems >= 1.0.2 on the 1.0 branch
@@ -43,19 +33,54 @@ and >= 1.1.0.rc3 on the 1.1 branch.
43
33
 
44
34
  Run the generator:
45
35
 
46
- rails generate devise:install
36
+ rails generate data_mapper:devise_install
47
37
 
48
38
  The generator will install an initializer which describes ALL Devise's
49
- configuration options and you MUST take a look at it. Make sure to specify
50
- either data_mapper (for using dm-validations) or data_mapper_active_model
51
- (ActiveModel::Validations) as the orm in the configuration file.
39
+ configuration options and you MUST take a look at it. See Config section below
40
+ for three config options that have particular importance to dm-devise.
52
41
 
53
- To add Devise to any of your models using the generator:
42
+ Add Devise to any of your models using the generator:
54
43
 
55
44
  rails generate data_mapper:devise MODEL
56
45
 
57
46
  Read the README for devise at http://github.com/plataformatec/devise/blob/master/README.rdoc
58
47
 
48
+ == Config Options
49
+
50
+ See the generated initializer for all the config options, but dm-devise users
51
+ should be particularly aware of these three:
52
+
53
+ === data_mapper_validation_lib
54
+
55
+ dm-devise adds some compatibility methods for either dm-validations or
56
+ Active Model validations. By default, it determines what to load based on
57
+ which library is found (giving preference to dm-validations). You may
58
+ explicitly set this to 'dm-validations' or 'active_model', or false to not
59
+ load any of the validations compatibility code. Details of the options:
60
+
61
+ dm-validations::
62
+ Uses dm-validations. This involves a bit of monkey-patching, but you need to
63
+ use this if you want auto-validations in *any* of your models.
64
+ active_model::
65
+ Uses ActiveModel::Validations. Do not use if you require 'dm-validations'
66
+ anywhere in your app (or include it in your Gemfile). Things will break.
67
+ The advantage to this is Active Model's I18n support for error messages, and
68
+ it uses the same validations lib as devise does by default.
69
+
70
+ === apply_schema
71
+
72
+ Tells if dm-devise should apply the devise database schema. You may want to
73
+ set this to false if working with a legacy schema.
74
+
75
+ === data_mapper_validation_messages
76
+
77
+ Messages to use as the default DataMapper validation error messages. The
78
+ messages are updated from those included in dm-validations to be consistent
79
+ with ActiveModel (i.e. with the Devise test expectations) and include
80
+ additional messages that devise uses (:not_found, :already_confirmed,
81
+ :not_locked, and :expired). If set to false, the messages are left as
82
+ defined by the dm-validations gem.
83
+
59
84
  == TODO
60
85
 
61
86
  * Example app
@@ -64,16 +89,14 @@ Read the README for devise at http://github.com/plataformatec/devise/blob/master
64
89
  == Testing
65
90
 
66
91
  The dm-devise test rake task runs all of devise's tests using the data_mapper
67
- and data_mapper_active_model ORM setups. In order to run tests, you'll need a
92
+ ORM with both dm-validations and active_model validations (you can specify one
93
+ with rake test VALIDATION_LIB=lib_name). In order to run tests, you'll need a
68
94
  local copy of devise (a gem is fine as long as you specify the path). By default,
69
95
  dm-devise looks for devise in [path-to-dm-devise]/../devise. You can override
70
96
  this by setting a DEVISE_PATH env variable. For example:
71
97
 
72
98
  rake test DEVISE_PATH=/path/to/devise
73
99
 
74
- Tests of the master branch should be run against devise master. Tests of the
75
- 1.1 branch should be run against the devise 1.1 branch (or a 1.1.x gem).
76
-
77
100
  == Note on Patches/Pull Requests
78
101
 
79
102
  * Fork the project.
@@ -100,4 +123,4 @@ http://github.com/jm81/dm-devise/issues
100
123
 
101
124
  == Copyright
102
125
 
103
- Copyright (c) 2010 Jared Morgan. See LICENSE for details.
126
+ Copyright (c) 2010-2011 Jared Morgan. See LICENSE for details.
data/Rakefile CHANGED
@@ -11,24 +11,25 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
  require 'rake/testtask'
14
- require 'rake/rdoctask'
15
- require File.join(File.dirname(__FILE__), 'lib', 'dm-devise', 'version')
14
+ require 'rdoc/task'
15
+ require 'dm-devise/version'
16
16
 
17
17
  desc 'Default: run tests for all DataMapper ORM setups.'
18
18
  task :default => :pre_commit
19
19
 
20
20
  desc 'Run Devise tests for all DataMapper ORM setups.'
21
21
  task :pre_commit do
22
- Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
23
- orm = File.basename(file).split(".").first
22
+ Dir[File.join(File.dirname(__FILE__), 'lib', 'devise', 'orm', 'data_mapper', 'validations', '*.rb')].each do |file|
23
+ validation_lib = File.basename(file).split(".").first
24
24
  ENV['DEVISE_PATH'] ||= File.expand_path('../devise')
25
- system "rake test DEVISE_ORM=#{orm} DEVISE_PATH=#{ENV['DEVISE_PATH']}"
25
+ system "rake test DEVISE_ORM=data_mapper VALIDATION_LIB=#{validation_lib} DEVISE_PATH=#{ENV['DEVISE_PATH']}"
26
26
  end
27
27
  end
28
28
 
29
29
  desc 'Run Devise tests using DataMapper. Specify path to devise with DEVISE_PATH'
30
30
  Rake::TestTask.new(:test) do |test|
31
31
  ENV['DEVISE_ORM'] ||= 'data_mapper'
32
+ ENV['VALIDATION_LIB'] ||= 'dm-validations'
32
33
  ENV['DEVISE_PATH'] ||= File.expand_path('../devise')
33
34
  unless File.exist?(ENV['DEVISE_PATH'])
34
35
  puts "Specify the path to devise (e.g. rake DEVISE_PATH=/path/to/devise). Not found at #{ENV['DEVISE_PATH']}"
data/dm-devise.gemspec CHANGED
@@ -22,5 +22,4 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency('dm-timestamps', '>= 1.0.2', '< 1.2')
23
23
  s.add_dependency('dm-rails', '>= 1.0.3', '< 1.2')
24
24
  s.add_dependency('devise', '~> 1.3')
25
- s.add_dependency('sugar-high', '~> 0.2.10')
26
25
  end
@@ -2,7 +2,9 @@ require 'dm-devise'
2
2
  require 'devise/orm/data_mapper/compatibility'
3
3
  require 'devise/orm/data_mapper/schema'
4
4
  require 'devise/orm/data_mapper/date_time'
5
- require 'devise/orm/data_mapper/dm-validations'
5
+ require 'devise/orm/data_mapper/serializable'
6
+ require 'devise/orm/data_mapper/validations/dm-validations'
7
+ require 'devise/orm/data_mapper/validations/active_model'
6
8
  require 'orm_adapter/adapters/data_mapper'
7
9
 
8
10
  module Devise
@@ -11,7 +13,15 @@ module Devise
11
13
  module Hook
12
14
  def devise_modules_hook!
13
15
  extend Schema
16
+
17
+ if Devise.data_mapper_validation_lib == 'active_model'
18
+ include ActiveModel::Validations
19
+ include ActiveModelCompatibility
20
+ extend ActiveModelUniquenessCompatibility
21
+ end
22
+
14
23
  include Compatibility
24
+
15
25
  yield
16
26
  return unless Devise.apply_schema
17
27
  devise_modules.each { |m| send(m) if respond_to?(m, true) }
@@ -0,0 +1,36 @@
1
+ module Devise
2
+ module Models
3
+ # This module redefines properties_to_serialize in models for more
4
+ # secure defaults. By default, it removes from the serializable model
5
+ # all attributes whose writer or reader is *not* public. You can remove this default
6
+ # by using :force_except and passing a new list of attributes you want
7
+ # to exempt. All attributes given to :exclude will simply add names to
8
+ # exempt to Devise internal list.
9
+ module Serializable
10
+ extend ActiveSupport::Concern
11
+
12
+ def properties_to_serialize(options=nil)
13
+ options ||= {}
14
+ if options.key?(:force_except) || options.key?(:force_exclude)
15
+ options[:exclude] = options.delete(:force_except) || options.delete(:force_exclude)
16
+ super(options)
17
+ else
18
+ except = Array(options[:exclude]) + Array(options[:except])
19
+ super(options.merge(:exclude => except + self.class.blacklist_keys))
20
+ end
21
+ end
22
+
23
+ # Get back to DataMapper's #to_xml.
24
+ def to_xml(*args)
25
+ super
26
+ end
27
+
28
+ module ClassMethods
29
+ # Returns keys that should be removed when serializing the record.
30
+ def blacklist_keys
31
+ @blacklist_keys ||= properties.select { |property| property.reader_visibility != :public || property.writer_visibility != :public }.map(&:name)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Devise
2
+ module Orm
3
+ module DataMapper
4
+ module ActiveModelCompatibility
5
+ # include ActiveModel::Validations does not make save check valid?.
6
+ # This may not be the best solution, but it seems to work. Note that
7
+ # Compatibility is included after this module; its #save method handles
8
+ # the :validate => false option.
9
+ def save(*args)
10
+ retval = valid? && super(*args)
11
+ assert_save_successful(:save, retval)
12
+ retval
13
+ end
14
+ end
15
+
16
+ module ActiveModelUniquenessCompatibility
17
+ def validates_uniqueness_of(*fields)
18
+ validates_with UniquenessValidator, _merge_attributes(fields)
19
+ end
20
+ end
21
+
22
+ class UniquenessValidator < ActiveModel::EachValidator
23
+ def validate_each(target, attribute, value)
24
+ resource = ::DataMapper.repository(target.repository.name) { target.model.first(attribute => value) }
25
+ if resource.nil? || (target.saved? && resource.key == target.key)
26
+ return true
27
+ else
28
+ target.errors.add(attribute, :taken)
29
+ return false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ if Devise.data_mapper_validation_lib == 'dm-validations'
2
+ module DataMapper
3
+ module Validations
4
+
5
+ # Monkey-patch ValidationErrors to support generation of error message from
6
+ # a Symbol. This does not translate, consistent with normal DataMapper
7
+ # operation. Set DataMapper::Validate::ValidationErrors.default_error_messages
8
+ # if alternate messages are needed (after devise has been initialized).
9
+ class ValidationErrors
10
+ alias_method :original_add, :add
11
+
12
+ # If the message is a Symbol, allow +default_error_message+ to generate
13
+ # the message, including translation.
14
+ def add(field_name, message)
15
+ if message.kind_of?(Symbol)
16
+ message = self.class.default_error_message(message, field_name)
17
+ end
18
+ original_add(field_name, message) unless errors[field_name].include?(message)
19
+ end
20
+
21
+ # Some devise controller actions expect resource#errors to respond to
22
+ # #to_xml. Otherwise, we get a Missing template error
23
+ def to_xml(options = {})
24
+ @errors.to_hash.to_xml(options.merge(:root => 'errors'))
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ if Devise.data_mapper_validation_messages
31
+ DataMapper::Validations::ValidationErrors.default_error_messages = Devise.data_mapper_validation_messages
32
+ end
33
+ end
@@ -1,55 +1,11 @@
1
- require 'dm-devise'
2
- require 'devise/orm/data_mapper/compatibility'
3
- require 'devise/orm/data_mapper/schema'
4
- require 'devise/orm/data_mapper/date_time'
5
- require 'orm_adapter/adapters/data_mapper'
1
+ puts <<DEPRECATION
2
+ WARN: orm/data_mapper/data_mapper_active_model is deprecated. dm-devise now
3
+ checks for which validation library is available. To force dm-devise to use
4
+ ActiveModel::Validations, add the following above the ORM require line in your
5
+ devise initializer:
6
6
 
7
- module Devise
8
- module Orm
9
- module DataMapper
10
- module Hook
11
- def devise_modules_hook!
12
- extend Schema
13
- include ActiveModel::Validations
14
- include ActiveModelCompatibility
15
- include Compatibility
7
+ config.data_mapper_validation_lib = 'active_model'
8
+ DEPRECATION
16
9
 
17
- def self.validates_uniqueness_of(*fields)
18
- validates_with UniquenessValidator, _merge_attributes(fields)
19
- end
20
-
21
- yield
22
- return unless Devise.apply_schema
23
- devise_modules.each { |m| send(m) if respond_to?(m, true) }
24
- end
25
- end
26
-
27
- class UniquenessValidator < ActiveModel::EachValidator
28
- def validate_each(target, attribute, value)
29
- resource = ::DataMapper.repository(target.repository.name) { target.model.first(attribute => value) }
30
- if resource.nil? || (target.saved? && resource.key == target.key)
31
- return true
32
- else
33
- target.errors.add(attribute, :taken)
34
- return false
35
- end
36
- end
37
- end
38
-
39
- module ActiveModelCompatibility
40
- # include ActiveModel::Validations does not make save check valid?.
41
- # This may not be the best solution, but it seems to work. Note that
42
- # Compatibility is included after this module; its #save method handles
43
- # the :validate => false option.
44
- def save(*args)
45
- retval = valid? && super(*args)
46
- assert_save_successful(:save, retval)
47
- retval
48
- end
49
- end
50
- end
51
- end
52
- end
53
-
54
- DataMapper::Model.append_extensions(Devise::Models)
55
- DataMapper::Model.append_extensions(Devise::Orm::DataMapper::Hook)
10
+ Devise.data_mapper_validation_lib = 'active_model'
11
+ require 'devise/orm/data_mapper'
data/lib/dm-devise.rb CHANGED
@@ -5,3 +5,65 @@ require 'dm-timestamps'
5
5
  require 'dm-rails'
6
6
 
7
7
  require 'dm-devise/version'
8
+
9
+ module Devise
10
+ # Messages to use as the default DataMapper validation error messages. The
11
+ # messages are updated from those included in dm-validations to be consistent
12
+ # with ActiveModel (i.e. with the Devise test expectations) and include
13
+ # additional messages that devise uses (:not_found, :already_confirmed,
14
+ # :not_locked, and :expired). If set to false, the messages are left as
15
+ # defined by the dm-validations gem.
16
+ mattr_accessor :data_mapper_validation_messages
17
+ @@data_mapper_validation_messages = {
18
+ :absent => '%s must be absent',
19
+ :inclusion => '%s is not included in the list',
20
+ :exclusion => '%s is reserved',
21
+ :invalid => '%s is invalid',
22
+ :confirmation => "%s doesn't match confirmation",
23
+ :accepted => '%s must be accepted',
24
+ :nil => '%s must not be nil',
25
+ :empty => "%s can't be empty",
26
+ :blank => "%s can't be blank",
27
+ :length_between => '%s must be between %s and %s characters long',
28
+ :too_long => '%s is too long (maximum is %s characters)',
29
+ :too_short => '%s is too short (minimum is %s characters)',
30
+ :wrong_length => '%s "is the wrong length (should be %s characters)"',
31
+ :taken => '%s has already been taken',
32
+ :not_a_number => '%s is not a number',
33
+ :not_an_integer => '%s must be an integer',
34
+ :greater_than => '%s must be greater than %s',
35
+ :greater_than_or_equal_to => '%s must be greater than or equal to %s',
36
+ :equal_to => '%s must be equal to %s',
37
+ :not_equal_to => '%s must not be equal to %s',
38
+ :less_than => '%s must be less than %s',
39
+ :less_than_or_equal_to => '%s must be less than or equal to %s',
40
+ :value_between => '%s must be between %s and %s',
41
+ :odd => 'must be odd',
42
+ :even => 'must be even',
43
+ :primitive => '%s must be of type %s',
44
+ :not_found => '%s not found',
45
+ :already_confirmed => '%s was already confirmed, please try signing in',
46
+ :not_locked => '%s was not locked',
47
+ :expired => '%s has expired, please request a new one'
48
+ }
49
+
50
+ class << self
51
+ # Determine which validation library to use based on which validation
52
+ # library is loaded. May be set explicitly to one of:
53
+ #
54
+ # - 'dm-validations'
55
+ # - 'active_model'
56
+ # - Any other value (false) to not load any validation compatibility code.
57
+ mattr_writer :data_mapper_validation_lib
58
+ @@data_mapper_validation_lib = nil
59
+ def data_mapper_validation_lib
60
+ if !@@data_mapper_validation_lib.nil?
61
+ @@data_mapper_validation_lib.to_s
62
+ elsif defined? DataMapper::Validations
63
+ 'dm-validations'
64
+ elsif defined? ActiveModel::Validations
65
+ 'active_model'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Devise
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.5.0.beta'.freeze
4
4
  end
5
5
  end
@@ -1,13 +1,4 @@
1
1
  require 'generators/devise/orm_helpers'
2
- require 'sugar-high/file'
3
-
4
- # Reload Active Support's String#blank?, overridden by sugar-high. Active Support's
5
- # version considers any all-space String blank, behavior that devise expects.
6
- class String #:nodoc:
7
- def blank?
8
- self !~ /\S/
9
- end
10
- end
11
2
 
12
3
  module DataMapper
13
4
  module Generators
@@ -21,11 +12,6 @@ module DataMapper
21
12
  def inject_devise_content
22
13
  inject_into_file model_path, model_contents, :after => "include DataMapper::Resource\n" if model_exists?
23
14
  end
24
-
25
- def replace_default_devise_orm
26
- devise_init_file = File.join(Rails.root, 'config', 'initializers', 'devise.rb')
27
- File.replace_content_from devise_init_file, :where => 'orm/active_record', :with => 'orm/data_mapper'
28
- end
29
15
  end
30
16
  end
31
17
  end
@@ -0,0 +1,43 @@
1
+ module DataMapper
2
+ module Generators
3
+ class DeviseInstallGenerator < Rails::Generators::Base
4
+ def generate_devise_install
5
+ invoke 'devise:install'
6
+ end
7
+
8
+ def inject_data_mapper_content
9
+ devise_init_file = File.join(Rails.root, 'config', 'initializers', 'devise.rb')
10
+ validations = <<VALIDATIONS
11
+ # ==> Validations Library
12
+ # dm-devise adds some compatibility methods for either dm-validations or
13
+ # Active Model validations. By default, it determines what to load based on
14
+ # which library is found (giving preference to dm-validations). You may
15
+ # explicitly set this to 'dm-validations' or 'active_model', or false to not
16
+ # load any of the validations compatibility code.
17
+ # config.data_mapper_validation_lib = nil
18
+
19
+ VALIDATIONS
20
+ inject_into_file devise_init_file, validations, :before => ' # ==> ORM configuration'
21
+
22
+ data_mapper_options = <<APPLY_SCHEMA
23
+
24
+ # ==> Apply Schema
25
+ # Tells if dm-devise should apply the devise database schema via property
26
+ # declarations. You may want to set this to false if working with a legacy
27
+ # schema.
28
+ # config.apply_schema = true
29
+
30
+ # ==> dm-validations Default Error Messages
31
+ # Messages to use as the default DataMapper validation error messages. The
32
+ # messages are updated from those included in dm-validations to be consistent
33
+ # with ActiveModel (i.e. with the Devise test expectations) and include
34
+ # additional messages that devise uses (:not_found, :already_confirmed,
35
+ # :not_locked, and :expired). If set to false, the messages are left as
36
+ # defined by the dm-validations gem. See dm-devise.rb for default.
37
+ # config.data_mapper_validation_messages = {}
38
+ APPLY_SCHEMA
39
+ inject_into_file devise_init_file, data_mapper_options, :after => "orm/data_mapper'\n"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -9,20 +9,22 @@ class ActiveSupport::TestCase
9
9
  end
10
10
  end
11
11
 
12
- module DataMapper
13
- module Validate
14
- class ValidationErrors
12
+ if VALIDATION_LIB == 'dm-validations'
13
+ module DataMapper
14
+ module Validations
15
+ class ValidationErrors
15
16
 
16
- # ActiveModel prepends field names in +#full_messages+, and so the
17
- # expected result of calling errors[field_name] will not include the
18
- # field name in the message. However, DM expects the field name to be
19
- # included in the original message. Assuming that the field name will
20
- # begin the message, just strip it out (plus the following space) for
21
- # testing purposes. This has no effect on #full_messages.
22
- def [](property_name)
23
- if property_errors = errors[property_name.to_sym]
24
- property_errors.collect do |message|
25
- message[(property_name.to_s.length + 1)..-1]
17
+ # ActiveModel prepends field names in +#full_messages+, and so the
18
+ # expected result of calling errors[field_name] will not include the
19
+ # field name in the message. However, DM expects the field name to be
20
+ # included in the original message. Assuming that the field name will
21
+ # begin the message, just strip it out (plus the following space) for
22
+ # testing purposes. This has no effect on #full_messages.
23
+ def [](property_name)
24
+ if property_errors = errors[property_name.to_sym]
25
+ property_errors.collect do |message|
26
+ message[(property_name.to_s.length + 1)..-1]
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -5,12 +5,10 @@ require 'test_helper'
5
5
  # particularly important and getting DM to pass the original devise tests would
6
6
  # be difficult.
7
7
  #
8
- # This file contains tests shared by both data_mapper and
9
- # data_mapper_active_model ORM setups.
10
- # Tests specific to the data_mapper orm which uses dm-validations are in dm_validations_test.rb
11
- # Tests specific to the data_mapper_active_model orm which uses ActiveModel
12
- # validations would be in active_model_test.rb, but there aren't any (I would
13
- # be rather surprised if there ever were any).
8
+ # This file contains tests that are overriden regardless of validation library.
9
+ # Tests specific to dm-validations are in dm_validations_test.rb
10
+ # Tests specific to ActiveModel validations would be in active_model_test.rb,
11
+ # but there aren't any (I would be rather surprised if there ever were any).
14
12
  #
15
13
  # For each test, an explanation is given as to why I chose to override the test,
16
14
  # and the original assertion is commented above the DM-specific assertion.
@@ -120,3 +118,35 @@ class ValidatableTest < ActiveSupport::TestCase
120
118
  end
121
119
  end
122
120
  end
121
+
122
+ class SerializableTest < ActiveSupport::TestCase
123
+ # AR's #to_xml replaces underscore with dash. DM does not.
124
+ undef test_should_not_include_unsafe_keys_on_XML
125
+ undef test_should_not_include_unsafe_keys_on_XML_even_if_a_new_except_is_provided
126
+ undef test_should_include_unsafe_keys_on_XML_if_a_force_except_is_provided
127
+
128
+ test 'should not include unsafe keys on XML' do
129
+ assert_match /email/, @user.to_xml
130
+ assert_no_match /confirmation_token/, @user.to_xml
131
+ end
132
+
133
+ test 'should not include unsafe keys on XML even if a new except is provided' do
134
+ assert_no_match /email/, @user.to_xml(:except => :email)
135
+ assert_no_match /confirmation_token/, @user.to_xml(:except => :email)
136
+ end
137
+
138
+ test 'should include unsafe keys on XML if a force_except is provided' do
139
+ assert_no_match /email/, @user.to_xml(:force_except => :email)
140
+ assert_match /confirmation_token/, @user.to_xml(:force_except => :email)
141
+ end
142
+ end
143
+
144
+ class DeviseHelperTest < ActionController::IntegrationTest
145
+ # Ensure test finds the translation of the model name.
146
+ setup do
147
+ I18n.backend.store_translations :fr,
148
+ {
149
+ :data_mapper => { :models => { :user => "utilisateur" } }
150
+ }
151
+ end
152
+ end
@@ -1,8 +1,7 @@
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
-
4
+ if VALIDATION_LIB == 'dm-validations'
6
5
  class ValidatableTest < ActiveSupport::TestCase
7
6
  undef test_should_require_a_password_with_minimum_of_6_characters
8
7
 
@@ -6,20 +6,23 @@ class User
6
6
  property :id, Serial
7
7
  property :username, String
8
8
  property :facebook_token, String
9
+ property :confirmation_token, String, :writer => :private
9
10
  timestamps :at
10
11
 
11
12
  include SharedUser
12
13
  include Shim
13
14
 
14
- before :valid?, :update_password_confirmation
15
+ if VALIDATION_LIB == 'dm-validations'
16
+ before :valid?, :update_password_confirmation
15
17
 
16
- # DM's validates_confirmation_of requires the confirmation field to be present,
17
- # while ActiveModel by default skips the confirmation test if the confirmation
18
- # value is nil. This test takes advantage of AM's behavior, so just add the
19
- # :password_confirmation value.
20
- def update_password_confirmation
21
- if self.password && self.password_confirmation.nil?
22
- self.password_confirmation = self.password
18
+ # DM's validates_confirmation_of requires the confirmation field to be present,
19
+ # while ActiveModel by default skips the confirmation test if the confirmation
20
+ # value is nil. This test takes advantage of AM's behavior, so just add the
21
+ # :password_confirmation value.
22
+ def update_password_confirmation
23
+ if self.password && self.password_confirmation.nil?
24
+ self.password_confirmation = self.password
25
+ end
23
26
  end
24
- end
27
+ end
25
28
  end
@@ -6,7 +6,7 @@ require "action_mailer/railtie"
6
6
  require "active_resource/railtie"
7
7
  require "rails/test_unit/railtie"
8
8
 
9
- Bundler.require :default, DEVISE_ORM
9
+ Bundler.require :default, VALIDATION_LIB
10
10
 
11
11
  begin
12
12
  require "#{DEVISE_ORM}/railtie"
@@ -21,7 +21,7 @@ module RailsApp
21
21
  config.root = APP_ROOT
22
22
  config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers views).include?($1) }
23
23
  config.autoload_paths += [ File.expand_path("#{File.dirname(__FILE__)}/../app/#{DEVISE_ORM}") ]
24
-
24
+
25
25
  # Configure generators values. Many other options are available, be sure to check the documentation.
26
26
  # config.generators do |g|
27
27
  # g.orm :active_record
data/test/test_helper.rb CHANGED
@@ -1,8 +1,9 @@
1
- ENV["RAILS_ENV"] = "test"
2
- DEVISE_ORM = (ENV["DEVISE_ORM"] || :data_mapper).to_sym
1
+ ENV['RAILS_ENV'] = 'test'
2
+ DEVISE_ORM = (ENV['DEVISE_ORM'] || :data_mapper).to_sym
3
3
  DEVISE_PATH = ENV['DEVISE_PATH']
4
+ VALIDATION_LIB = (ENV['VALIDATION_LIB'] || 'dm-validations')
4
5
 
5
- puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
6
+ puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}, Devise.data_mapper_validation_lib = #{VALIDATION_LIB.inspect}"
6
7
 
7
8
  require 'dm-migrations'
8
9
  require "rails_app/config/environment"
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-devise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease:
4
+ hash: 31098233
5
+ prerelease: 6
6
6
  segments:
7
7
  - 1
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 1.4.0
10
+ - beta
11
+ version: 1.5.0.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - Jared Morgan
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-06-24 00:00:00 -05:00
19
+ date: 2011-08-03 00:00:00 -05:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -148,22 +149,6 @@ dependencies:
148
149
  version: "1.3"
149
150
  type: :runtime
150
151
  version_requirements: *id006
151
- - !ruby/object:Gem::Dependency
152
- name: sugar-high
153
- prerelease: false
154
- requirement: &id007 !ruby/object:Gem::Requirement
155
- none: false
156
- requirements:
157
- - - ~>
158
- - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
- - 2
163
- - 10
164
- version: 0.2.10
165
- type: :runtime
166
- version_requirements: *id007
167
152
  description: dm-devise adds DataMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails
168
153
  email: jmorgan@morgancreative.net
169
154
  executables: []
@@ -175,6 +160,7 @@ extra_rdoc_files: []
175
160
  files:
176
161
  - .document
177
162
  - .gitignore
163
+ - CHANGELOG.rdoc
178
164
  - Gemfile
179
165
  - Gemfile.lock
180
166
  - LICENSE
@@ -184,24 +170,24 @@ files:
184
170
  - lib/devise/orm/data_mapper.rb
185
171
  - lib/devise/orm/data_mapper/compatibility.rb
186
172
  - lib/devise/orm/data_mapper/date_time.rb
187
- - lib/devise/orm/data_mapper/dm-validations.rb
188
173
  - lib/devise/orm/data_mapper/schema.rb
174
+ - lib/devise/orm/data_mapper/serializable.rb
175
+ - lib/devise/orm/data_mapper/validations/active_model.rb
176
+ - lib/devise/orm/data_mapper/validations/dm-validations.rb
189
177
  - lib/devise/orm/data_mapper_active_model.rb
190
178
  - lib/dm-devise.rb
191
179
  - lib/dm-devise/version.rb
192
180
  - lib/generators/data_mapper/devise_generator.rb
181
+ - lib/generators/data_mapper/devise_install_generator.rb
193
182
  - test/data_mapper/compatibility_test.rb
194
183
  - test/data_mapper/schema_test.rb
195
184
  - test/generators/data_mapper_generator_test.rb
196
185
  - test/orm/data_mapper.rb
197
- - test/orm/data_mapper_active_model.rb
198
186
  - test/overrides/data_mapper_test.rb
199
187
  - test/overrides/dm_validations_test.rb
200
188
  - test/rails_app/app/data_mapper/admin.rb
201
189
  - test/rails_app/app/data_mapper/shim.rb
202
190
  - test/rails_app/app/data_mapper/user.rb
203
- - test/rails_app/app/data_mapper_active_model/admin.rb
204
- - test/rails_app/app/data_mapper_active_model/user.rb
205
191
  - test/rails_app/config/application.rb
206
192
  - test/rails_app/config/environment.rb
207
193
  - test/test_helper.rb
@@ -226,12 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
212
  required_rubygems_version: !ruby/object:Gem::Requirement
227
213
  none: false
228
214
  requirements:
229
- - - ">="
215
+ - - ">"
230
216
  - !ruby/object:Gem::Version
231
- hash: 3
217
+ hash: 25
232
218
  segments:
233
- - 0
234
- version: "0"
219
+ - 1
220
+ - 3
221
+ - 1
222
+ version: 1.3.1
235
223
  requirements: []
236
224
 
237
225
  rubyforge_project:
@@ -1,68 +0,0 @@
1
- module DataMapper
2
- module Validate
3
-
4
- # Monkey-patch ValidationErrors to support generation of error message from
5
- # a Symbol. This does not translate, consistent with normal DataMapper
6
- # operation. Set DataMapper::Validate::ValidationErrors.default_error_messages
7
- # if alternate messages are needed (after devise has been initialized).
8
- class ValidationErrors
9
- alias_method :original_add, :add
10
-
11
- # If the message is a Symbol, allow +default_error_message+ to generate
12
- # the message, including translation.
13
- def add(field_name, message)
14
- if message.kind_of?(Symbol)
15
- message = self.class.default_error_message(message, field_name)
16
- end
17
- original_add(field_name, message) unless errors[field_name].include?(message)
18
- end
19
- end
20
- end
21
- end
22
-
23
- # Default error messages consistent with ActiveModel messages and devise
24
- # expectations.
25
- DataMapper::Validate::ValidationErrors.default_error_messages = {
26
- :absent => '%s must be absent',
27
- :inclusion => '%s is not included in the list',
28
- :exclusion => '%s is reserved',
29
- :invalid => '%s is invalid',
30
- :confirmation => "%s doesn't match confirmation",
31
- :accepted => '%s must be accepted',
32
- :nil => '%s must not be nil',
33
- :empty => "%s can't be empty",
34
- :blank => "%s can't be blank",
35
- :length_between => '%s must be between %s and %s characters long',
36
- :too_long => '%s is too long (maximum is %s characters)',
37
- :too_short => '%s is too short (minimum is %s characters)',
38
- :wrong_length => '%s "is the wrong length (should be %s characters)"',
39
- :taken => '%s has already been taken',
40
- :not_a_number => '%s is not a number',
41
- :not_an_integer => '%s must be an integer',
42
- :greater_than => '%s must be greater than %s',
43
- :greater_than_or_equal_to => '%s must be greater than or equal to %s',
44
- :equal_to => '%s must be equal to %s',
45
- :not_equal_to => '%s must not be equal to %s',
46
- :less_than => '%s must be less than %s',
47
- :less_than_or_equal_to => '%s must be less than or equal to %s',
48
- :value_between => '%s must be between %s and %s',
49
- :odd => 'must be odd',
50
- :even => 'must be even',
51
- :primitive => '%s must be of type %s',
52
- :not_found => '%s not found',
53
- :already_confirmed => '%s was already confirmed, please try signing in',
54
- :not_locked => '%s was not locked',
55
- :expired => '%s has expired, please request a new one'
56
- }
57
-
58
- module DataMapper
59
- module Validations
60
- class ValidationErrors
61
- # Some devise controller actions expect resource#errors to respond to
62
- # #to_xml. Otherwise, we get a Missing template error
63
- def to_xml(options = {})
64
- @errors.to_hash.to_xml(options.merge(:root => 'errors'))
65
- end
66
- end
67
- end
68
- end
@@ -1,10 +0,0 @@
1
- require 'rails/test_help'
2
-
3
- DataMapper.auto_migrate!
4
-
5
- class ActiveSupport::TestCase
6
- setup do
7
- User.all.destroy!
8
- Admin.all.destroy!
9
- end
10
- end
@@ -1,14 +0,0 @@
1
- require 'shared_admin'
2
- require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
3
-
4
- class Admin
5
- include DataMapper::Resource
6
-
7
- property :id, Serial
8
- property :username, String
9
-
10
- include SharedAdmin
11
- include Shim
12
-
13
- property :remember_token, String
14
- end
@@ -1,14 +0,0 @@
1
- require 'shared_user'
2
- require File.join(File.dirname(__FILE__), '../data_mapper/shim.rb')
3
-
4
- class User
5
- include DataMapper::Resource
6
-
7
- property :id, Serial
8
- property :username, String
9
- property :facebook_token, String
10
- timestamps :at
11
-
12
- include SharedUser
13
- include Shim
14
- end