paranoia_uniqueness_validator 1.1.0 → 1.2.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/README.md +2 -2
- data/lib/paranoia_uniqueness_validator/validations/uniqueness_without_deleted.rb +5 -1
- data/lib/paranoia_uniqueness_validator/version.rb +1 -1
- data/spec/dummy/app/models/dummy_non_nil_model.rb +3 -0
- data/spec/dummy/db/migrate/20160421194241_create_dummy_non_nil_models.rb +10 -0
- data/spec/dummy/db/schema.rb +10 -3
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/validations/uniqueness_without_deleted_spec.rb +40 -8
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a61f98888b05a46e6a994dd16e1bdf7136a22c91
|
4
|
+
data.tar.gz: 19699acd3367c7551a071a1accae0105c8f0a9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45cddd3449be7e2d54767cd37e4251e0e9bb79aa9d019f32c093716aaa869acee8fefb21ebbc6e46b1d16460d4f4a85c367cac17978c8858024b9ee6122955de
|
7
|
+
data.tar.gz: 2fd6d1fd44c9bb25fb7a34d87e08c9d638599ec9a42c6028322a0f769e645b2d47cd52528ce017ffd69fe172b62c3fb5b4bbf9d782b2c91f0e1ff8d6ab5fd597
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ParanoiaUniquenessValidator
|
1
|
+
# ParanoiaUniquenessValidator
|
2
2
|
|
3
3
|
Adds validator validates_uniqueness_without_deleted.
|
4
4
|
|
@@ -14,7 +14,7 @@ Add this line to your application's Gemfile:
|
|
14
14
|
gem 'paranoia_uniqueness_validator', '0.1.0'
|
15
15
|
|
16
16
|
# Rails 4
|
17
|
-
gem 'paranoia_uniqueness_validator', '1.
|
17
|
+
gem 'paranoia_uniqueness_validator', '1.1.0'
|
18
18
|
And then execute:
|
19
19
|
|
20
20
|
$ bundle
|
@@ -13,7 +13,11 @@ module ParanoiaUniquenessValidator
|
|
13
13
|
|
14
14
|
relation = build_relation(finder_class, table, attribute, value)
|
15
15
|
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.id)) if record.persisted?
|
16
|
-
|
16
|
+
|
17
|
+
default_sentinel_value = Object.const_defined?('Paranoia') ? Paranoia.default_sentinel_value : nil
|
18
|
+
|
19
|
+
relation = relation.and(table[:deleted_at].eq(default_sentinel_value))
|
20
|
+
|
17
21
|
relation = scope_relation(record, table, relation)
|
18
22
|
relation = finder_class.unscoped.where(relation)
|
19
23
|
relation = relation.merge(options[:conditions]) if options[:conditions]
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,13 +11,20 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160421194241) do
|
15
15
|
|
16
|
-
create_table "dummy_models", force:
|
17
|
-
t.string "unique_field"
|
16
|
+
create_table "dummy_models", force: :cascade do |t|
|
17
|
+
t.string "unique_field", limit: 255
|
18
18
|
t.datetime "deleted_at"
|
19
19
|
t.datetime "created_at"
|
20
20
|
t.datetime "updated_at"
|
21
21
|
end
|
22
22
|
|
23
|
+
create_table "dummy_non_nil_models", force: :cascade do |t|
|
24
|
+
t.string "unique_field"
|
25
|
+
t.datetime "deleted_at", default: '0000-01-01 00:00:00', null: false
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
28
|
+
end
|
29
|
+
|
23
30
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -1,15 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'paranoia'
|
3
|
+
|
2
4
|
|
3
5
|
describe ParanoiaUniquenessValidator::Validations::UniquenessWithoutDeletedValidator do
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
context 'with nil default_sentinel_value' do
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
Paranoia.default_sentinel_value = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should validate uniqueness" do
|
14
|
+
DummyModel.create(:unique_field => "unique")
|
15
|
+
DummyModel.new(:unique_field => "unique").should_not be_valid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should should be valid if not unique with a deleted record" do
|
19
|
+
dummy_model = DummyModel.create(:unique_field => "unique")
|
20
|
+
dummy_model.destroy
|
21
|
+
dummy_model = DummyModel.new(:unique_field => "unique")
|
22
|
+
dummy_model.should be_valid
|
23
|
+
end
|
24
|
+
|
7
25
|
end
|
8
26
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
27
|
+
context 'with datetime (non nil) default_sentinel_value' do
|
28
|
+
|
29
|
+
before(:all) do
|
30
|
+
Paranoia.default_sentinel_value = DateTime.new(0)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should validate uniqueness" do
|
34
|
+
DummyNonNilModel.create(:unique_field => "unique")
|
35
|
+
DummyNonNilModel.new(:unique_field => "unique").should_not be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should should be valid if not unique with a deleted record" do
|
39
|
+
dummy_model = DummyNonNilModel.create(:unique_field => "unique")
|
40
|
+
dummy_model.destroy
|
41
|
+
dummy_model = DummyNonNilModel.new(:unique_field => "unique")
|
42
|
+
dummy_model.should be_valid
|
43
|
+
end
|
44
|
+
|
14
45
|
end
|
46
|
+
|
15
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoia_uniqueness_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- spec/dummy/app/models/.keep
|
98
98
|
- spec/dummy/app/models/concerns/.keep
|
99
99
|
- spec/dummy/app/models/dummy_model.rb
|
100
|
+
- spec/dummy/app/models/dummy_non_nil_model.rb
|
100
101
|
- spec/dummy/app/views/layouts/application.html.erb
|
101
102
|
- spec/dummy/bin/bundle
|
102
103
|
- spec/dummy/bin/rails
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- spec/dummy/config/locales/en.yml
|
120
121
|
- spec/dummy/config/routes.rb
|
121
122
|
- spec/dummy/db/migrate/20130511080827_create_dummy_models.rb
|
123
|
+
- spec/dummy/db/migrate/20160421194241_create_dummy_non_nil_models.rb
|
122
124
|
- spec/dummy/db/schema.rb
|
123
125
|
- spec/dummy/db/seeds.rb
|
124
126
|
- spec/dummy/db/test.sqlite3
|
@@ -153,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
155
|
version: '0'
|
154
156
|
requirements: []
|
155
157
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.5.1
|
157
159
|
signing_key:
|
158
160
|
specification_version: 4
|
159
161
|
summary: Validate unique fields without letting those pesky deleted records get in
|
@@ -172,6 +174,7 @@ test_files:
|
|
172
174
|
- spec/dummy/app/models/.keep
|
173
175
|
- spec/dummy/app/models/concerns/.keep
|
174
176
|
- spec/dummy/app/models/dummy_model.rb
|
177
|
+
- spec/dummy/app/models/dummy_non_nil_model.rb
|
175
178
|
- spec/dummy/app/views/layouts/application.html.erb
|
176
179
|
- spec/dummy/bin/bundle
|
177
180
|
- spec/dummy/bin/rails
|
@@ -194,6 +197,7 @@ test_files:
|
|
194
197
|
- spec/dummy/config/locales/en.yml
|
195
198
|
- spec/dummy/config/routes.rb
|
196
199
|
- spec/dummy/db/migrate/20130511080827_create_dummy_models.rb
|
200
|
+
- spec/dummy/db/migrate/20160421194241_create_dummy_non_nil_models.rb
|
197
201
|
- spec/dummy/db/schema.rb
|
198
202
|
- spec/dummy/db/seeds.rb
|
199
203
|
- spec/dummy/db/test.sqlite3
|