paranoia_uniqueness_validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +117 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +41 -0
  7. data/Rakefile +9 -0
  8. data/lib/paranoia_uniqueness_validator.rb +10 -0
  9. data/lib/paranoia_uniqueness_validator/validations/uniqueness_without_deleted.rb +35 -0
  10. data/lib/paranoia_uniqueness_validator/version.rb +3 -0
  11. data/paranoia_uniqueness_validator.gemspec +26 -0
  12. data/spec/dummy/.rspec +1 -0
  13. data/spec/dummy/README.rdoc +261 -0
  14. data/spec/dummy/Rakefile +7 -0
  15. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  16. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  17. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  18. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  19. data/spec/dummy/app/mailers/.gitkeep +0 -0
  20. data/spec/dummy/app/models/.gitkeep +0 -0
  21. data/spec/dummy/app/models/dummy_model.rb +5 -0
  22. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/spec/dummy/config.ru +4 -0
  24. data/spec/dummy/config/application.rb +65 -0
  25. data/spec/dummy/config/boot.rb +10 -0
  26. data/spec/dummy/config/database.yml +25 -0
  27. data/spec/dummy/config/environment.rb +5 -0
  28. data/spec/dummy/config/environments/development.rb +37 -0
  29. data/spec/dummy/config/environments/production.rb +67 -0
  30. data/spec/dummy/config/environments/test.rb +37 -0
  31. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/dummy/config/initializers/inflections.rb +15 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  34. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  35. data/spec/dummy/config/initializers/session_store.rb +8 -0
  36. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/spec/dummy/config/locales/en.yml +5 -0
  38. data/spec/dummy/config/routes.rb +58 -0
  39. data/spec/dummy/db/migrate/20121009200838_create_dummy_models.rb +9 -0
  40. data/spec/dummy/db/schema.rb +23 -0
  41. data/spec/dummy/db/test.sqlite3 +0 -0
  42. data/spec/dummy/lib/assets/.gitkeep +0 -0
  43. data/spec/dummy/log/.gitkeep +0 -0
  44. data/spec/dummy/public/404.html +26 -0
  45. data/spec/dummy/public/422.html +26 -0
  46. data/spec/dummy/public/500.html +25 -0
  47. data/spec/dummy/public/favicon.ico +0 -0
  48. data/spec/dummy/script/rails +6 -0
  49. data/spec/spec_helper.rb +33 -0
  50. data/spec/validations/uniqueness_without_deleted_spec.rb +15 -0
  51. metadata +222 -0
@@ -0,0 +1,9 @@
1
+ class CreateDummyModels < ActiveRecord::Migration
2
+ def change
3
+ create_table :dummy_models do |t|
4
+ t.string :unique_field
5
+ t.datetime :deleted_at
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20121009200838) do
15
+
16
+ create_table "dummy_models", :force => true do |t|
17
+ t.string "unique_field"
18
+ t.datetime "deleted_at"
19
+ t.datetime "created_at", :null => false
20
+ t.datetime "updated_at", :null => false
21
+ end
22
+
23
+ end
Binary file
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,33 @@
1
+ ENV["RAILS_ENV"] = 'test'
2
+
3
+ # Require dummy Rails app
4
+ require File.expand_path("../../spec/dummy/config/environment", __FILE__)
5
+
6
+ require 'database_cleaner'
7
+ require 'rspec/rails'
8
+ require 'rspec/autorun'
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc,
11
+ # in spec/support/ and its subdirectories.
12
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+
14
+ DatabaseCleaner.strategy = :transaction
15
+
16
+ RSpec.configure do |config|
17
+ # If true, the base class of anonymous controllers will be inferred
18
+ # automatically. This will be the default behavior in future versions of
19
+ # rspec-rails.
20
+ config.infer_base_class_for_anonymous_controllers = false
21
+
22
+ config.before :suite do
23
+ DatabaseCleaner.clean_with :truncation
24
+ end
25
+
26
+ config.before :each do
27
+ DatabaseCleaner.start
28
+ end
29
+
30
+ config.after :each do
31
+ DatabaseCleaner.clean
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ 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
7
+ end
8
+
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
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,222 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paranoia_uniqueness_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anthony Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: paranoia
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: database_cleaner
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Adds the validates_uniqueness_without_deleted validator to ignore deleted
95
+ fields when validating for uniqueness.
96
+ email:
97
+ - anthony@sticksnleaves.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .travis.yml
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/paranoia_uniqueness_validator.rb
110
+ - lib/paranoia_uniqueness_validator/validations/uniqueness_without_deleted.rb
111
+ - lib/paranoia_uniqueness_validator/version.rb
112
+ - paranoia_uniqueness_validator.gemspec
113
+ - spec/dummy/.rspec
114
+ - spec/dummy/README.rdoc
115
+ - spec/dummy/Rakefile
116
+ - spec/dummy/app/assets/javascripts/application.js
117
+ - spec/dummy/app/assets/stylesheets/application.css
118
+ - spec/dummy/app/controllers/application_controller.rb
119
+ - spec/dummy/app/helpers/application_helper.rb
120
+ - spec/dummy/app/mailers/.gitkeep
121
+ - spec/dummy/app/models/.gitkeep
122
+ - spec/dummy/app/models/dummy_model.rb
123
+ - spec/dummy/app/views/layouts/application.html.erb
124
+ - spec/dummy/config.ru
125
+ - spec/dummy/config/application.rb
126
+ - spec/dummy/config/boot.rb
127
+ - spec/dummy/config/database.yml
128
+ - spec/dummy/config/environment.rb
129
+ - spec/dummy/config/environments/development.rb
130
+ - spec/dummy/config/environments/production.rb
131
+ - spec/dummy/config/environments/test.rb
132
+ - spec/dummy/config/initializers/backtrace_silencers.rb
133
+ - spec/dummy/config/initializers/inflections.rb
134
+ - spec/dummy/config/initializers/mime_types.rb
135
+ - spec/dummy/config/initializers/secret_token.rb
136
+ - spec/dummy/config/initializers/session_store.rb
137
+ - spec/dummy/config/initializers/wrap_parameters.rb
138
+ - spec/dummy/config/locales/en.yml
139
+ - spec/dummy/config/routes.rb
140
+ - spec/dummy/db/migrate/20121009200838_create_dummy_models.rb
141
+ - spec/dummy/db/schema.rb
142
+ - spec/dummy/db/test.sqlite3
143
+ - spec/dummy/lib/assets/.gitkeep
144
+ - spec/dummy/log/.gitkeep
145
+ - spec/dummy/public/404.html
146
+ - spec/dummy/public/422.html
147
+ - spec/dummy/public/500.html
148
+ - spec/dummy/public/favicon.ico
149
+ - spec/dummy/script/rails
150
+ - spec/spec_helper.rb
151
+ - spec/validations/uniqueness_without_deleted_spec.rb
152
+ homepage: ''
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 2743772073659751577
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ segments:
174
+ - 0
175
+ hash: 2743772073659751577
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 1.8.24
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Validate unique fields without letting those pesky deleted records get in
182
+ the way. Great for use with Paranoia.
183
+ test_files:
184
+ - spec/dummy/.rspec
185
+ - spec/dummy/README.rdoc
186
+ - spec/dummy/Rakefile
187
+ - spec/dummy/app/assets/javascripts/application.js
188
+ - spec/dummy/app/assets/stylesheets/application.css
189
+ - spec/dummy/app/controllers/application_controller.rb
190
+ - spec/dummy/app/helpers/application_helper.rb
191
+ - spec/dummy/app/mailers/.gitkeep
192
+ - spec/dummy/app/models/.gitkeep
193
+ - spec/dummy/app/models/dummy_model.rb
194
+ - spec/dummy/app/views/layouts/application.html.erb
195
+ - spec/dummy/config.ru
196
+ - spec/dummy/config/application.rb
197
+ - spec/dummy/config/boot.rb
198
+ - spec/dummy/config/database.yml
199
+ - spec/dummy/config/environment.rb
200
+ - spec/dummy/config/environments/development.rb
201
+ - spec/dummy/config/environments/production.rb
202
+ - spec/dummy/config/environments/test.rb
203
+ - spec/dummy/config/initializers/backtrace_silencers.rb
204
+ - spec/dummy/config/initializers/inflections.rb
205
+ - spec/dummy/config/initializers/mime_types.rb
206
+ - spec/dummy/config/initializers/secret_token.rb
207
+ - spec/dummy/config/initializers/session_store.rb
208
+ - spec/dummy/config/initializers/wrap_parameters.rb
209
+ - spec/dummy/config/locales/en.yml
210
+ - spec/dummy/config/routes.rb
211
+ - spec/dummy/db/migrate/20121009200838_create_dummy_models.rb
212
+ - spec/dummy/db/schema.rb
213
+ - spec/dummy/db/test.sqlite3
214
+ - spec/dummy/lib/assets/.gitkeep
215
+ - spec/dummy/log/.gitkeep
216
+ - spec/dummy/public/404.html
217
+ - spec/dummy/public/422.html
218
+ - spec/dummy/public/500.html
219
+ - spec/dummy/public/favicon.ico
220
+ - spec/dummy/script/rails
221
+ - spec/spec_helper.rb
222
+ - spec/validations/uniqueness_without_deleted_spec.rb