hashrocket-mongomapper 0.3.14 → 0.3.15

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.3.15
@@ -15,9 +15,14 @@ module MongoMapper
15
15
  end
16
16
 
17
17
  class ValidatesUniquenessOf < Validatable::ValidationBase
18
+ option :scope
19
+
18
20
  def valid?(instance)
19
- # TODO: scope
20
- doc = instance.class.find(:first, :conditions => {self.attribute => instance[attribute]}, :limit => 1)
21
+ conditions = {self.attribute => instance[attribute]}
22
+ if scope
23
+ conditions.merge!(scope => instance[scope])
24
+ end
25
+ doc = instance.class.find(:first, :conditions => conditions, :limit => 1)
21
26
  doc.nil? || instance.id == doc.id
22
27
  end
23
28
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongomapper}
8
- s.version = "0.3.14"
8
+ s.version = "0.3.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Nunemaker"]
12
- s.date = %q{2009-09-17}
12
+ s.date = %q{2009-09-22}
13
13
  s.default_executable = %q{mmconsole}
14
14
  s.email = %q{nunemaker@gmail.com}
15
15
  s.executables = ["mmconsole"]
@@ -121,6 +121,22 @@ class ValidationsTest < Test::Unit::TestCase
121
121
  doc.should_not have_error_on(:name)
122
122
  end
123
123
 
124
+ should "not fail when new object is out of scope" do
125
+ document = Class.new do
126
+ include MongoMapper::Document
127
+ key :name
128
+ key :adult
129
+ validates_uniqueness_of :name, :scope => :adult
130
+ end
131
+ doc = document.new("name" => "joe", :adult => true)
132
+ doc.save.should be_true
133
+
134
+ doc2 = document.new("name" => "joe", :adult => false)
135
+ doc2.should be_valid
136
+
137
+ document.collection.clear
138
+ end
139
+
124
140
  should "allow to update an object" do
125
141
  doc = @document.new("name" => "joe")
126
142
  doc.save.should be_true
@@ -147,6 +163,21 @@ class ValidationsTest < Test::Unit::TestCase
147
163
  doc2 = @document.new("name" => "joe")
148
164
  doc2.should have_error_on(:name)
149
165
  end
166
+
167
+ should "fail when object is not unique within scope" do
168
+ document = Class.new do
169
+ include MongoMapper::Document
170
+ key :name
171
+ key :adult
172
+ validates_uniqueness_of :name, :scope => :adult
173
+ end
174
+ doc = document.new("name" => "joe", :adult => true)
175
+ doc.save.should be_true
176
+
177
+ doc2 = document.new("name" => "joe", :adult => true)
178
+ doc2.should have_error_on(:name)
179
+ document.collection.clear
180
+ end
150
181
  end
151
182
 
152
183
  context "validates uniqueness of with :unique shortcut" do
@@ -169,4 +200,4 @@ class ValidationsTest < Test::Unit::TestCase
169
200
  second_john.should have_error_on(:name, 'has already been taken')
170
201
  end
171
202
  end
172
- end
203
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashrocket-mongomapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-17 00:00:00 -07:00
12
+ date: 2009-09-22 00:00:00 -07:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency