paranoia_uniqueness_validator 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -1
  3. data/.travis.yml +6 -9
  4. data/Dockerfile +13 -0
  5. data/Gemfile +3 -9
  6. data/README.md +4 -0
  7. data/docker-compose.yml +11 -0
  8. data/lib/paranoia_uniqueness_validator/validations/uniqueness_without_deleted.rb +16 -13
  9. data/lib/paranoia_uniqueness_validator/version.rb +1 -1
  10. data/paranoia_uniqueness_validator.gemspec +1 -1
  11. data/spec/dummy/.gitignore +9 -3
  12. data/spec/dummy/.rspec +1 -0
  13. data/spec/dummy/{README.rdoc → README.md} +1 -5
  14. data/spec/dummy/Rakefile +2 -2
  15. data/spec/dummy/app/assets/config/manifest.js +3 -0
  16. data/spec/dummy/app/{mailers → assets/images}/.keep +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +4 -4
  18. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  19. data/spec/dummy/app/{models → assets/javascripts/channels}/.keep +0 -0
  20. data/spec/dummy/app/assets/stylesheets/application.css +6 -4
  21. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  22. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  24. data/spec/dummy/app/jobs/application_job.rb +2 -0
  25. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  26. data/spec/dummy/app/models/application_record.rb +3 -0
  27. data/spec/dummy/app/models/dummy_model.rb +1 -1
  28. data/spec/dummy/app/models/dummy_non_nil_model.rb +1 -1
  29. data/spec/dummy/app/views/layouts/application.html.erb +9 -9
  30. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  31. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  32. data/spec/dummy/bin/rails +1 -1
  33. data/spec/dummy/bin/setup +34 -0
  34. data/spec/dummy/bin/update +29 -0
  35. data/spec/dummy/config.ru +2 -1
  36. data/spec/dummy/config/application.rb +8 -10
  37. data/spec/dummy/config/boot.rb +3 -5
  38. data/spec/dummy/config/cable.yml +9 -0
  39. data/spec/dummy/config/database.yml +7 -11
  40. data/spec/dummy/config/environment.rb +4 -4
  41. data/spec/dummy/config/environments/development.rb +30 -5
  42. data/spec/dummy/config/environments/production.rb +37 -31
  43. data/spec/dummy/config/environments/test.rb +10 -4
  44. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  45. data/spec/dummy/config/initializers/assets.rb +11 -0
  46. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  47. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  48. data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
  49. data/spec/dummy/config/initializers/session_store.rb +1 -1
  50. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  51. data/spec/dummy/config/puma.rb +47 -0
  52. data/spec/dummy/config/routes.rb +2 -48
  53. data/spec/dummy/config/secrets.yml +22 -0
  54. data/spec/dummy/config/spring.rb +6 -0
  55. data/spec/dummy/db/migrate/20130511080827_create_dummy_models.rb +1 -1
  56. data/spec/dummy/db/migrate/20160421194241_create_dummy_non_nil_models.rb +1 -1
  57. data/spec/dummy/db/schema.rb +5 -6
  58. data/spec/dummy/db/seeds.rb +3 -3
  59. data/spec/dummy/db/test.sqlite3 +0 -0
  60. data/spec/dummy/public/404.html +20 -11
  61. data/spec/dummy/public/422.html +20 -11
  62. data/spec/dummy/public/500.html +19 -10
  63. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  64. data/spec/dummy/public/apple-touch-icon.png +0 -0
  65. data/spec/dummy/public/robots.txt +1 -1
  66. data/spec/spec_helper.rb +1 -2
  67. data/spec/validations/uniqueness_without_deleted_spec.rb +9 -9
  68. metadata +61 -13
  69. data/spec/dummy/config/initializers/secret_token.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a61f98888b05a46e6a994dd16e1bdf7136a22c91
4
- data.tar.gz: 19699acd3367c7551a071a1accae0105c8f0a9cd
3
+ metadata.gz: d6c43ab07ae51e7b81827a2eb89534c4fd26ef36
4
+ data.tar.gz: a5a83e727c9ea0a0a6b45a06164fc52c2b44465d
5
5
  SHA512:
6
- metadata.gz: 45cddd3449be7e2d54767cd37e4251e0e9bb79aa9d019f32c093716aaa869acee8fefb21ebbc6e46b1d16460d4f4a85c367cac17978c8858024b9ee6122955de
7
- data.tar.gz: 2fd6d1fd44c9bb25fb7a34d87e08c9d638599ec9a42c6028322a0f769e645b2d47cd52528ce017ffd69fe172b62c3fb5b4bbf9d782b2c91f0e1ff8d6ab5fd597
6
+ metadata.gz: 5e57390dcc1bdee3a5d356fdf0d94bebc9c08b5501fe74de02c0bbee526139dad60a46ddf7d5cc32eb626d645bd6b32a199b3ec30e7abb4415762ff3ffd4ae62
7
+ data.tar.gz: 0bbf526c132a4c7efb252ed0704d946a0de03809595e4868cdbcdb7134c6940e41bc396a7c9c80d1beb1fb1e7e902115d5d60ba5223954024bfbab18d309d8e3
data/.gitignore CHANGED
@@ -8,4 +8,7 @@ spec/dummy/tmp/
8
8
  spec/dummy/.sass-cache
9
9
  Gemfile.lock
10
10
  .rbenv*
11
- coverage
11
+ coverage
12
+ .ruby-version
13
+ .gems/
14
+ .DS_Store
data/.travis.yml CHANGED
@@ -1,19 +1,16 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
3
+ - 2.2.5
4
+ - 2.3.0
7
5
  - ruby-head
8
- - jruby-19mode
9
6
  - jruby-head
10
- - rbx
11
7
  env:
12
- - "RAILS_VERSION=4.0.0"
13
- - "RAILS_VERSION=4.1.0"
14
- - "RAILS_VERSION=4.2.0"
8
+ - "RAILS_VERSION=master"
9
+ - "RAILS_VERSION=5.0.0"
10
+ - "RAILS_VERSION=5.0.0.1"
15
11
  matrix:
16
12
  allow_failures:
17
13
  - rvm: ruby-head
18
14
  - rvm: jruby-head
15
+ - env: RAILS_VERSION=master
19
16
  sudo: false
data/Dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.3
2
+
3
+ MAINTAINER Anthony Smith <anthony@sticksnleaves.com>
4
+
5
+ ENV APP_HOME /usr/src/app
6
+
7
+ RUN apt-get update -y \
8
+ && apt-get upgrade -y
9
+
10
+ RUN gem install rubygems-update --no-document
11
+ RUN gem install bundler --no-document
12
+
13
+ WORKDIR $APP_HOME
data/Gemfile CHANGED
@@ -6,10 +6,11 @@ gemspec
6
6
  rails_version = ENV['RAILS_VERSION'] || 'default'
7
7
 
8
8
  rails = case rails_version
9
+
9
10
  when 'master'
10
11
  { github: 'rails/rails' }
11
12
  when 'default'
12
- '>= 4.2.0'
13
+ '>= 5.0.0'
13
14
  else
14
15
  "~> #{rails_version}"
15
16
  end
@@ -30,16 +31,9 @@ platforms :ruby_19, :jruby_19 do
30
31
  gem "mime-types", "< 3.0"
31
32
  end
32
33
 
33
- platforms :rbx do
34
- #gem 'psych'
35
- #gem 'racc'
36
- #gem 'rubinius-coverage'
37
- #gem 'rubysl'
38
- #gem 'rubysl-test-unit'
39
- end
40
-
41
34
  group :development do
42
35
  gem 'bundler'
43
36
  gem 'coveralls', :require => false
37
+ gem 'listen'
44
38
  gem 'rake'
45
39
  end
data/README.md CHANGED
@@ -15,6 +15,10 @@ Add this line to your application's Gemfile:
15
15
 
16
16
  # Rails 4
17
17
  gem 'paranoia_uniqueness_validator', '1.1.0'
18
+
19
+ # Rails 5
20
+ gem 'paranoia_uniqueness_validator', '2.0.0'
21
+
18
22
  And then execute:
19
23
 
20
24
  $ bundle
@@ -0,0 +1,11 @@
1
+ version: '2'
2
+ services:
3
+ lib:
4
+ build: .
5
+ command: rspec
6
+ volumes:
7
+ - .:/usr/src/app
8
+ - lib.volume:/usr/local/bundle
9
+ volumes:
10
+ lib.volume:
11
+ driver: local
@@ -4,24 +4,27 @@ module ParanoiaUniquenessValidator
4
4
  def validate_each(record, attribute, value)
5
5
  finder_class = find_finder_class_for(record)
6
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
7
+ value = map_enum_attribute(finder_class, attribute, value)
13
8
 
14
9
  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
-
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
-
10
+ if record.persisted?
11
+ if finder_class.primary_key
12
+ relation = relation.where.not(finder_class.primary_key => record.id_was || record.id)
13
+ else
14
+ raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
15
+ end
16
+ end
21
17
  relation = scope_relation(record, table, relation)
22
- relation = finder_class.unscoped.where(relation)
23
18
  relation = relation.merge(options[:conditions]) if options[:conditions]
24
19
 
20
+ if defined?('Paranoia') && Paranoia.respond_to?(:default_sentinel_value)
21
+ sentinel_value = Paranoia.default_sentinel_value
22
+ else
23
+ sentinel_value = nil
24
+ end
25
+
26
+ relation = relation.where(deleted_at: sentinel_value)
27
+
25
28
  if relation.exists?
26
29
  error_options = options.except(:case_sensitive, :scope, :conditions)
27
30
  error_options[:value] = value
@@ -1,3 +1,3 @@
1
1
  module ParanoiaUniquenessValidator
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "activerecord", ">= 4.0.0"
20
+ gem.add_dependency "activerecord", ">= 5.0.0", "< 5.1"
21
21
 
22
22
  gem.add_development_dependency "paranoia"
23
23
  gem.add_development_dependency "database_cleaner"
@@ -1,4 +1,4 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
2
  #
3
3
  # If you find yourself ignoring temporary files generated by your text editor
4
4
  # or operating system, you probably want to add a global ignore instead:
@@ -8,8 +8,14 @@
8
8
  /.bundle
9
9
 
10
10
  # Ignore the default SQLite database.
11
+ /db/*.sqlite3
11
12
  /db/*.sqlite3-journal
12
13
 
13
14
  # Ignore all logfiles and tempfiles.
14
- /log/*.log
15
- /tmp
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore Byebug command history file.
21
+ .byebug_history
data/spec/dummy/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --require spec_helper
@@ -1,4 +1,4 @@
1
- == README
1
+ # README
2
2
 
3
3
  This README would normally document whatever steps are necessary to get the
4
4
  application up and running.
@@ -22,7 +22,3 @@ Things you may want to cover:
22
22
  * Deployment instructions
23
23
 
24
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative 'config/application'
5
5
 
6
- Dummy::Application.load_tasks
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
File without changes
@@ -2,13 +2,13 @@
2
2
  // listed below.
3
3
  //
4
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.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
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.
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
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.
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -3,11 +3,13 @@
3
3
  * listed below.
4
4
  *
5
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.
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
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.
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
10
12
  *
11
- *= require_self
12
13
  *= require_tree .
14
+ *= require_self
13
15
  */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -1,5 +1,3 @@
1
1
  class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
2
  protect_from_forgery with: :exception
5
3
  end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -1,3 +1,3 @@
1
- class DummyModel < ActiveRecord::Base
1
+ class DummyModel < ApplicationRecord
2
2
  validates :unique_field, :uniqueness_without_deleted => true
3
3
  end
@@ -1,3 +1,3 @@
1
- class DummyNonNilModel < ActiveRecord::Base
1
+ class DummyNonNilModel < ApplicationRecord
2
2
  validates :unique_field, :uniqueness_without_deleted => true
3
3
  end
@@ -1,14 +1,14 @@
1
1
  <!DOCTYPE html>
2
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>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
10
6
 
11
- <%= yield %>
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
12
10
 
13
- </body>
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
14
  </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
data/spec/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end