active_repository 0.3.10 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88bcc2de4247471046b40735b92062c68435132f
|
4
|
+
data.tar.gz: 9b496d88de8a8d0b784e7bd2eca531b5acf6484a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1464d3c00f1ad26e2dcab554a1e8db0d176b25598e43760853120da7cd70d2027620772c026a0328dcad21f18c80b5fd8e341cec6d82e81fa223be0c7031962
|
7
|
+
data.tar.gz: 91dfb8189cf36f725807d0483b63d430f92aeb72277194187959bcea90d1d152d9ea6c78ffe5e579e985e16228ac267036b4ce3807aeb11631f894e0d7766a22
|
@@ -8,7 +8,15 @@ module ActiveModel
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def validate_each(record, attribute, value)
|
11
|
-
query
|
11
|
+
query = (record.id ? "id <> #{record.id}" : 'id is not null')
|
12
|
+
|
13
|
+
if(options[:scope])
|
14
|
+
value = record.send(options[:scope])
|
15
|
+
query += " and #{options[:scope]} = "
|
16
|
+
query += value.is_a?(String) ? "'#{value}'" : value
|
17
|
+
end
|
18
|
+
|
19
|
+
|
12
20
|
duplicate = record.class.where(query).all.select do |object|
|
13
21
|
object.id != record.id && object.send(attribute) == record.send(attribute)
|
14
22
|
end
|
@@ -105,6 +105,7 @@ describe ActiveRepository, "Base" do
|
|
105
105
|
it_behaves_like '.delete_all'
|
106
106
|
it_behaves_like '#delete'
|
107
107
|
it_behaves_like 'uniqueness'
|
108
|
+
it_behaves_like 'uniqueness_with_scope'
|
108
109
|
end
|
109
110
|
|
110
111
|
context "active_record", :active_record do
|
@@ -172,6 +173,7 @@ describe ActiveRepository, "Base" do
|
|
172
173
|
it_behaves_like '.delete_all'
|
173
174
|
it_behaves_like '#delete'
|
174
175
|
it_behaves_like 'uniqueness'
|
176
|
+
it_behaves_like 'uniqueness_with_scope'
|
175
177
|
end
|
176
178
|
|
177
179
|
context "mongoid", :mongoid do
|
@@ -244,5 +246,6 @@ describe ActiveRepository, "Base" do
|
|
244
246
|
it_behaves_like '.delete_all'
|
245
247
|
it_behaves_like '#delete'
|
246
248
|
it_behaves_like 'uniqueness'
|
249
|
+
it_behaves_like 'uniqueness_with_scope'
|
247
250
|
end
|
248
251
|
end
|
@@ -769,4 +769,23 @@ shared_examples "uniqueness" do
|
|
769
769
|
Country.count.should == 1
|
770
770
|
Country.all.should == [country1]
|
771
771
|
end
|
772
|
-
end
|
772
|
+
end
|
773
|
+
|
774
|
+
shared_examples "uniqueness_with_scope" do
|
775
|
+
before do
|
776
|
+
Country.delete_all
|
777
|
+
Country.validates_uniqueness_of :language, scope: 'name'
|
778
|
+
end
|
779
|
+
|
780
|
+
it "does not accept duplicated ids" do
|
781
|
+
country1 = Country.create(name: 'USA', language: 'English')
|
782
|
+
country2 = Country.create(name: 'Canada', language: 'English')
|
783
|
+
country3 = Country.create(name: 'USA', language: 'English')
|
784
|
+
|
785
|
+
country1.should be_valid
|
786
|
+
country2.should be_valid
|
787
|
+
country3.should_not be_valid
|
788
|
+
Country.count.should == 2
|
789
|
+
Country.all.should == [country1, country2]
|
790
|
+
end
|
791
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Torres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_hash
|