couchrest-uniqueness-validation 0.2.0 → 0.2.1
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.2.
|
1
|
+
0.2.1
|
@@ -24,7 +24,7 @@ module CouchRest
|
|
24
24
|
|
25
25
|
def unique?(target)
|
26
26
|
value = target.validation_property_value(@field_name)
|
27
|
-
value.downcase
|
27
|
+
value = value.downcase if @options[:downcase] && !value.blank?
|
28
28
|
existing_docs = target.class.view(@options[:view].to_sym, :key => value, :limit => 1, :include_docs => false)['rows']
|
29
29
|
|
30
30
|
# normal case when target.new_document? == true and
|
@@ -92,11 +92,19 @@ describe CouchRest::Validation::UniquenessValidator do
|
|
92
92
|
@some_doc.should be_valid
|
93
93
|
end
|
94
94
|
|
95
|
-
it "
|
95
|
+
it "should work for nil values" do
|
96
96
|
@some_doc.another_prop = nil
|
97
97
|
YetAnotherUniqueDoc.should_receive(:view).
|
98
98
|
with(:by_another_prop, hash_including(:key => nil, :limit => 1, :include_docs => false))
|
99
99
|
lambda{@some_doc.valid?}.should_not raise_error
|
100
100
|
end
|
101
|
+
|
102
|
+
it "should not have a side effect of the field being left downcased afterwards" do
|
103
|
+
YetAnotherUniqueDoc.should_receive(:view).
|
104
|
+
with(:by_another_prop, hash_including(:key => @some_doc.another_prop.downcase, :limit => 1, :include_docs => false))
|
105
|
+
@some_doc.should be_valid
|
106
|
+
@some_doc.another_prop.should == 'Some Property Value'
|
107
|
+
@some_doc.another_prop.should_not == 'some property value'
|
108
|
+
end
|
101
109
|
end
|
102
110
|
end
|