paranoia_uniqueness_validator-cmoran92 1.1.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 +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +18 -0
- data/Gemfile +41 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +9 -0
- data/lib/paranoia_uniqueness_validator/validations/uniqueness_without_deleted.rb +36 -0
- data/lib/paranoia_uniqueness_validator/version.rb +3 -0
- data/lib/paranoia_uniqueness_validator.rb +10 -0
- data/paranoia_uniqueness_validator.gemspec +25 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/dummy_model.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +49 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20130511080827_create_dummy_models.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/validations/uniqueness_without_deleted_spec.rb +15 -0
- metadata +211 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f2f03d27a6cc5c7a6ccbd950937e47da48c34a3
|
4
|
+
data.tar.gz: ac7767ba08aa81d2b47f93da7366f85d72c0d910
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92ca6599964aa460ca8840669ab308f57431903233af5a8f5f974adf7d6288af1bca2088fb9bf06d6de24a66bef831d5a1b9781bbf95aeee15de8ad670f94597
|
7
|
+
data.tar.gz: 01b2f8006ed078cc4e34e339ce02bf3de4a7fd3db5aa63cb2a69db9f7fb3baf6b1028e8c7b06a461f0d7b1bb3c26a9cbbb75fa6b296afdcad22025924dc54604
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.2.0
|
7
|
+
- ruby-head
|
8
|
+
- jruby-19mode
|
9
|
+
- jruby-head
|
10
|
+
- rbx
|
11
|
+
env:
|
12
|
+
- "RAILS_VERSION=4.0.0"
|
13
|
+
- "RAILS_VERSION=4.1.0"
|
14
|
+
- "RAILS_VERSION=4.2.0"
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
18
|
+
- rvm: jruby-head
|
data/Gemfile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in paranoia_uniqueness_validator.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
rails_version = ENV['RAILS_VERSION'] || 'default'
|
7
|
+
|
8
|
+
rails = case rails_version
|
9
|
+
when 'master'
|
10
|
+
{ github: 'rails/rails' }
|
11
|
+
when 'default'
|
12
|
+
'>= 4.2.0'
|
13
|
+
else
|
14
|
+
"~> #{rails_version}"
|
15
|
+
end
|
16
|
+
|
17
|
+
gem 'rails', rails
|
18
|
+
|
19
|
+
platforms :jruby do
|
20
|
+
gem "activerecord-jdbcsqlite3-adapter"
|
21
|
+
gem "jruby-openssl"
|
22
|
+
end
|
23
|
+
|
24
|
+
platforms :ruby do
|
25
|
+
gem "sqlite3"
|
26
|
+
gem "test-unit"
|
27
|
+
end
|
28
|
+
|
29
|
+
platforms :rbx do
|
30
|
+
#gem 'psych'
|
31
|
+
#gem 'racc'
|
32
|
+
#gem 'rubinius-coverage'
|
33
|
+
#gem 'rubysl'
|
34
|
+
#gem 'rubysl-test-unit'
|
35
|
+
end
|
36
|
+
|
37
|
+
group :development do
|
38
|
+
gem 'bundler'
|
39
|
+
gem 'coveralls', :require => false
|
40
|
+
gem 'rake'
|
41
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Anthony Smith
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# ParanoiaUniquenessValidator [](http://coderwall.com/anthonator)
|
2
|
+
|
3
|
+
Adds validator validates_uniqueness_without_deleted.
|
4
|
+
|
5
|
+
This validator will ignore any record that has a non-null value for the deleted_at field. This gem was made specifically for use with the [Paranoia](https://github.com/radar/paranoia) gem but it can be used with any gem that uses the deleted_at field for marking records as deleted.
|
6
|
+
|
7
|
+
[](http://badge.fury.io/rb/paranoia_uniqueness_validator) [](http://travis-ci.org/anthonator/paranoia_uniqueness_validator) [](https://gemnasium.com/anthonator/paranoia_uniqueness_validator) [](https://coveralls.io/r/anthonator/paranoia_uniqueness_validator) [](https://codeclimate.com/github/anthonator/paranoia_uniqueness_validator)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
# Rails 3
|
14
|
+
gem 'paranoia_uniqueness_validator', '0.1.0'
|
15
|
+
|
16
|
+
# Rails 4
|
17
|
+
gem 'paranoia_uniqueness_validator', '1.0.0'
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install paranoia_uniqueness_validator
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
|
28
|
+
This validator supports all configuration options used by the base ActiveRecord uniqueness validator. For more information check out the [Rails API documentation](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#method-i-validates_uniqueness_of).
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class SomeModel < ActiveRecord::Base
|
34
|
+
validates :some_field, :uniqueness_without_deleted => true
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
45
|
+
|
46
|
+
## Credits
|
47
|
+
|
48
|
+
[](http://www.sticksnleaves.com)
|
49
|
+
|
50
|
+
paranoia_uniqueness_validator is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
|
51
|
+
|
52
|
+
Thanks to all of our [contributors](https://github.com/anthonator/paranoia_uniqueness_validator/graphs/contributors)
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module ParanoiaUniquenessValidator
|
2
|
+
module Validations
|
3
|
+
class UniquenessWithoutDeletedValidator < ActiveRecord::Validations::UniquenessValidator
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
finder_class = find_finder_class_for(record)
|
6
|
+
table = finder_class.arel_table
|
7
|
+
|
8
|
+
if ActiveRecord.version.to_s >= '4.2.0'
|
9
|
+
value = map_enum_attribute(finder_class, attribute, value)
|
10
|
+
else
|
11
|
+
value = deserialize_attribute(record, attribute, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
relation = build_relation(finder_class, table, attribute, value)
|
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(Paranoia.default_sentinel_value))
|
17
|
+
relation = scope_relation(record, table, relation)
|
18
|
+
relation = finder_class.unscoped.where(relation)
|
19
|
+
relation = relation.merge(options[:conditions]) if options[:conditions]
|
20
|
+
|
21
|
+
if relation.exists?
|
22
|
+
error_options = options.except(:case_sensitive, :scope, :conditions)
|
23
|
+
error_options[:value] = value
|
24
|
+
|
25
|
+
record.errors.add(attribute, :taken, error_options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def validates_uniqueness_without_deleted_of(*attr_name)
|
32
|
+
validates_with UniquenessWithoutDeletedValidator, _merge_attributes(attr_names)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "paranoia_uniqueness_validator/validations/uniqueness_without_deleted"
|
2
|
+
require "paranoia_uniqueness_validator/version"
|
3
|
+
|
4
|
+
module ParanoiaUniquenessValidator
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
class ActiveRecord::Base
|
9
|
+
include ParanoiaUniquenessValidator::Validations
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paranoia_uniqueness_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "paranoia_uniqueness_validator-cmoran92"
|
8
|
+
gem.version = ParanoiaUniquenessValidator::VERSION
|
9
|
+
gem.authors = ["Anthony Smith"]
|
10
|
+
gem.email = ["anthony@sticksnleaves.com"]
|
11
|
+
gem.description = %q{Adds the validates_uniqueness_without_deleted validator to ignore deleted fields when validating for uniqueness.}
|
12
|
+
gem.summary = %q{Validate unique fields without letting those pesky deleted records get in the way. Great for use with Paranoia.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "activerecord", ">= 4.0.0"
|
21
|
+
|
22
|
+
gem.add_development_dependency "paranoia"
|
23
|
+
gem.add_development_dependency "database_cleaner"
|
24
|
+
gem.add_development_dependency "rspec-rails"
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3-journal
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/spec/dummy/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "sprockets/railtie"
|
8
|
+
# require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
# Require the gems listed in Gemfile, including any gems
|
11
|
+
# you've limited to :test, :development, or :production.
|
12
|
+
Bundler.require(:default, Rails.env)
|
13
|
+
require "paranoia_uniqueness_validator"
|
14
|
+
|
15
|
+
module Dummy
|
16
|
+
class Application < Rails::Application
|
17
|
+
# Settings in config/environments/* take precedence over those specified here.
|
18
|
+
# Application configuration should go into files in config/initializers
|
19
|
+
# -- all .rb files in that directory are automatically loaded.
|
20
|
+
|
21
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
22
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
23
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
24
|
+
|
25
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
26
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
27
|
+
# config.i18n.default_locale = :de
|
28
|
+
end
|
29
|
+
end
|