paranoia_uniqueness_validator 1.1.0 → 1.2.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: 1c8349a30e88d13b9971047c6d29d61dd7128bf0
4
- data.tar.gz: 287a9fdef45d7de4f778812ef448d16dca1c96c3
3
+ metadata.gz: a61f98888b05a46e6a994dd16e1bdf7136a22c91
4
+ data.tar.gz: 19699acd3367c7551a071a1accae0105c8f0a9cd
5
5
  SHA512:
6
- metadata.gz: 43e9b1d5ffdd891470b02979736783f422a236b678da580a8caf67b2c34a20db18e59efc3e4a58d91f3bbd4bc6941177dfd80d22a94d4e0643baa8b023092737
7
- data.tar.gz: 5c0a1049cf15ea515caa4f14acc70ab06b87b0e7d36940eeaa7cbf05e63fd69088b17ed29ddd4ca8c1f03d6e865ba1a47fbedcc6d4ab682dfdc84c182cf3f038
6
+ metadata.gz: 45cddd3449be7e2d54767cd37e4251e0e9bb79aa9d019f32c093716aaa869acee8fefb21ebbc6e46b1d16460d4f4a85c367cac17978c8858024b9ee6122955de
7
+ data.tar.gz: 2fd6d1fd44c9bb25fb7a34d87e08c9d638599ec9a42c6028322a0f769e645b2d47cd52528ce017ffd69fe172b62c3fb5b4bbf9d782b2c91f0e1ff8d6ab5fd597
@@ -16,3 +16,4 @@ matrix:
16
16
  allow_failures:
17
17
  - rvm: ruby-head
18
18
  - rvm: jruby-head
19
+ sudo: false
data/Gemfile CHANGED
@@ -26,6 +26,10 @@ platforms :ruby do
26
26
  gem "test-unit"
27
27
  end
28
28
 
29
+ platforms :ruby_19, :jruby_19 do
30
+ gem "mime-types", "< 3.0"
31
+ end
32
+
29
33
  platforms :rbx do
30
34
  #gem 'psych'
31
35
  #gem 'racc'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ParanoiaUniquenessValidator [![endorse](http://api.coderwall.com/anthonator/endorsecount.png)](http://coderwall.com/anthonator)
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.0.0'
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
- relation = relation.and(table[:deleted_at].eq(nil))
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]
@@ -1,3 +1,3 @@
1
1
  module ParanoiaUniquenessValidator
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ class DummyNonNilModel < ActiveRecord::Base
2
+ validates :unique_field, :uniqueness_without_deleted => true
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreateDummyNonNilModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :dummy_non_nil_models do |t|
4
+ t.string :unique_field
5
+ t.datetime :deleted_at, null: false, default: DateTime.new(0)
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -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: 20130511080827) do
14
+ ActiveRecord::Schema.define(version: 20160421194241) do
15
15
 
16
- create_table "dummy_models", force: true do |t|
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
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
- it "should validate uniqueness" do
5
- DummyModel.create(:unique_field => "unique")
6
- DummyModel.new(:unique_field => "unique").should_not be_valid
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
- it "should should be valid if not unqiue with a deleted record" do
10
- dummy_model = DummyModel.create(:unique_field => "unique")
11
- dummy_model.destroy
12
- dummy_model = DummyModel.new(:unique_field => "unique")
13
- dummy_model.should be_valid
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.1.0
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: 2015-01-08 00:00:00.000000000 Z
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.4.5
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