mongoid 2.0.0.beta.9 → 2.0.0.beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.rdoc +2 -4
  2. data/lib/mongoid.rb +2 -1
  3. data/lib/mongoid/associations.rb +2 -3
  4. data/lib/mongoid/associations/embeds_many.rb +6 -2
  5. data/lib/mongoid/associations/embeds_one.rb +1 -3
  6. data/lib/mongoid/associations/options.rb +11 -10
  7. data/lib/mongoid/associations/references_many.rb +27 -4
  8. data/lib/mongoid/associations/references_many_as_array.rb +24 -4
  9. data/lib/mongoid/associations/references_one.rb +1 -2
  10. data/lib/mongoid/atomicity.rb +17 -4
  11. data/lib/mongoid/config.rb +97 -20
  12. data/lib/mongoid/contexts/enumerable.rb +9 -4
  13. data/lib/mongoid/contexts/mongo.rb +1 -1
  14. data/lib/mongoid/criteria.rb +7 -1
  15. data/lib/mongoid/criterion/inclusion.rb +12 -5
  16. data/lib/mongoid/criterion/optional.rb +26 -3
  17. data/lib/mongoid/cursor.rb +0 -1
  18. data/lib/mongoid/deprecation.rb +1 -2
  19. data/lib/mongoid/document.rb +25 -3
  20. data/lib/mongoid/extensions.rb +2 -1
  21. data/lib/mongoid/extensions/float/conversions.rb +1 -1
  22. data/lib/mongoid/extensions/integer/conversions.rb +1 -1
  23. data/lib/mongoid/extensions/symbol/conversions.rb +21 -0
  24. data/lib/mongoid/finders.rb +3 -2
  25. data/lib/mongoid/indexes.rb +17 -6
  26. data/lib/mongoid/logger.rb +19 -0
  27. data/lib/mongoid/paranoia.rb +12 -14
  28. data/lib/mongoid/persistence/remove_embedded.rb +0 -4
  29. data/lib/mongoid/persistence/update.rb +3 -0
  30. data/lib/mongoid/railtie.rb +37 -4
  31. data/lib/mongoid/railties/database.rake +19 -1
  32. data/lib/mongoid/validations/associated.rb +1 -1
  33. data/lib/mongoid/validations/locale/en.yml +4 -3
  34. data/lib/mongoid/validations/uniqueness.rb +19 -8
  35. data/lib/mongoid/version.rb +1 -1
  36. metadata +50 -18
  37. data/lib/mongoid/extensions/array/aliasing.rb +0 -4
@@ -18,7 +18,7 @@ namespace :db do
18
18
 
19
19
  if not Rake::Task.task_defined?("db:setup")
20
20
  desc 'Create the database, and initialize with the seed data'
21
- task :setup => [ 'db:create', 'db:seed' ]
21
+ task :setup => [ 'db:create', 'db:create_indexes', 'db:seed' ]
22
22
  end
23
23
 
24
24
  if not Rake::Task.task_defined?("db:reseed")
@@ -46,6 +46,24 @@ namespace :db do
46
46
  end
47
47
  end
48
48
 
49
+ if not Rake::Task.task_defined?("db:test:prepare")
50
+ namespace :test do
51
+ task :prepare do
52
+ # noop
53
+ end
54
+ end
55
+ end
56
+
57
+ if not Rake::Task.task_defined?("db:create_indexes")
58
+ desc 'Create the indexes defined on your mongoid models'
59
+ task :create_indexes => :environment do
60
+ Mongoid::Document.descendents.each do |model|
61
+ model.create_indexes
62
+ end
63
+ end
64
+ end
65
+
66
+
49
67
  ########
50
68
  # TODO: lots more useful db tasks can be added here. stuff like copyDatabase, etc
51
69
  ########
@@ -25,7 +25,7 @@ module Mongoid #:nodoc:
25
25
  def validate_each(document, attribute, value)
26
26
  values = value.is_a?(Array) ? value : [ value ]
27
27
  return if values.collect { |doc| doc.nil? || doc.valid? }.all?
28
- document.errors.add(attribute, :invalid, :default => options[:message], :value => value)
28
+ document.errors.add(attribute, :invalid, options.merge!(:value => value))
29
29
  end
30
30
  end
31
31
  end
@@ -1,4 +1,5 @@
1
1
  en:
2
- errors:
3
- messages:
4
- taken: "is already taken"
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: "is already taken"
@@ -17,18 +17,29 @@ module Mongoid #:nodoc:
17
17
  def setup(klass)
18
18
  @klass = klass
19
19
  end
20
-
20
+
21
21
  def validate_each(document, attribute, value)
22
- criteria = @klass.where(attribute => value)
23
-
22
+ if document.embedded?
23
+ return if document._parent.nil?
24
+
25
+ criteria = document._parent.send(document.association_name)
26
+
27
+ # If the parent document embeds_one, no need to validate uniqueness
28
+ return if criteria.is_a?(Mongoid::Document)
29
+
30
+ criteria = criteria.where(attribute => value, :_id => {'$ne' => document._id})
31
+ else
32
+ criteria = @klass.where(attribute => value)
33
+
34
+ unless document.new_record?
35
+ criteria = criteria.where(:_id => {'$ne' => document._id})
36
+ end
37
+ end
38
+
24
39
  Array.wrap(options[:scope]).each do |item|
25
40
  criteria = criteria.where(item => document.attributes[item])
26
41
  end
27
-
28
- unless document.new_record?
29
- criteria = criteria.where(:_id => {'$ne' => document._id})
30
- end
31
-
42
+
32
43
  if criteria.exists?
33
44
  document.errors.add(attribute, :taken, :default => options[:message], :value => value)
34
45
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.0.0.beta.9"
3
+ VERSION = "2.0.0.beta.10"
4
4
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196465
4
+ hash: 62196471
5
5
  prerelease: true
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
9
  - 0
10
10
  - beta
11
- - 9
12
- version: 2.0.0.beta.9
11
+ - 10
12
+ version: 2.0.0.beta.10
13
13
  platform: ruby
14
14
  authors:
15
15
  - Durran Jordan
@@ -77,12 +77,12 @@ dependencies:
77
77
  requirements:
78
78
  - - ~>
79
79
  - !ruby/object:Gem::Version
80
- hash: 17
80
+ hash: 29
81
81
  segments:
82
82
  - 1
83
83
  - 0
84
- - 3
85
- version: 1.0.3
84
+ - 5
85
+ version: 1.0.5
86
86
  type: :runtime
87
87
  version_requirements: *id004
88
88
  - !ruby/object:Gem::Dependency
@@ -93,30 +93,28 @@ dependencies:
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- hash: 17
96
+ hash: 31
97
97
  segments:
98
98
  - 1
99
99
  - 0
100
- - 3
101
- version: 1.0.3
100
+ - 4
101
+ version: 1.0.4
102
102
  type: :runtime
103
103
  version_requirements: *id005
104
104
  - !ruby/object:Gem::Dependency
105
- name: rspec
105
+ name: bson_ext
106
106
  prerelease: false
107
107
  requirement: &id006 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
- - - "="
110
+ - - ~>
111
111
  - !ruby/object:Gem::Version
112
- hash: 62196475
112
+ hash: 31
113
113
  segments:
114
- - 2
115
- - 0
114
+ - 1
116
115
  - 0
117
- - beta
118
- - 12
119
- version: 2.0.0.beta.12
116
+ - 4
117
+ version: 1.0.4
120
118
  type: :development
121
119
  version_requirements: *id006
122
120
  - !ruby/object:Gem::Dependency
@@ -135,6 +133,39 @@ dependencies:
135
133
  version: 0.9.8
136
134
  type: :development
137
135
  version_requirements: *id007
136
+ - !ruby/object:Gem::Dependency
137
+ name: rspec
138
+ prerelease: false
139
+ requirement: &id008 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - "="
143
+ - !ruby/object:Gem::Version
144
+ hash: 62196419
145
+ segments:
146
+ - 2
147
+ - 0
148
+ - 0
149
+ - beta
150
+ - 16
151
+ version: 2.0.0.beta.16
152
+ type: :development
153
+ version_requirements: *id008
154
+ - !ruby/object:Gem::Dependency
155
+ name: watchr
156
+ prerelease: false
157
+ requirement: &id009 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - "="
161
+ - !ruby/object:Gem::Version
162
+ hash: 7
163
+ segments:
164
+ - 0
165
+ - 6
166
+ version: "0.6"
167
+ type: :development
168
+ version_requirements: *id009
138
169
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
139
170
  email:
140
171
  - durran@gmail.com
@@ -184,7 +215,6 @@ files:
184
215
  - lib/mongoid/document.rb
185
216
  - lib/mongoid/errors.rb
186
217
  - lib/mongoid/extensions/array/accessors.rb
187
- - lib/mongoid/extensions/array/aliasing.rb
188
218
  - lib/mongoid/extensions/array/assimilation.rb
189
219
  - lib/mongoid/extensions/array/conversions.rb
190
220
  - lib/mongoid/extensions/array/parentization.rb
@@ -208,6 +238,7 @@ files:
208
238
  - lib/mongoid/extensions/set/conversions.rb
209
239
  - lib/mongoid/extensions/string/conversions.rb
210
240
  - lib/mongoid/extensions/string/inflections.rb
241
+ - lib/mongoid/extensions/symbol/conversions.rb
211
242
  - lib/mongoid/extensions/symbol/inflections.rb
212
243
  - lib/mongoid/extensions/time_conversions.rb
213
244
  - lib/mongoid/extensions/true_class/equality.rb
@@ -222,6 +253,7 @@ files:
222
253
  - lib/mongoid/indexes.rb
223
254
  - lib/mongoid/javascript/functions.yml
224
255
  - lib/mongoid/javascript.rb
256
+ - lib/mongoid/logger.rb
225
257
  - lib/mongoid/matchers/all.rb
226
258
  - lib/mongoid/matchers/default.rb
227
259
  - lib/mongoid/matchers/exists.rb
@@ -1,4 +0,0 @@
1
- # encoding: utf-8
2
- class Array
3
- alias :count :size
4
- end