Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding note/spec about validates_uniqueness_of and the todo list

  • Loading branch information...
commit 1293eca21a3507bc6b9fa307acb00cd1117d3d0c 1 parent 0b47839
Jeffrey Chupp authored

Showing 2 changed files with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. +8 0 README.textile
  2. +10 0 spec/android_spec.rb
8 README.textile
Source Rendered
@@ -57,10 +57,18 @@ One thing to note, destroying is always undo-able, but deleting is not.
57 57 # And you may say to yourself, "My god! What have I done?"
58 58 </pre>
59 59
  60 +h3. Note:
  61 +
  62 + validates_uniqueness_of does not ignore items marked with a deleted_at flag. This is a behavior difference between is_paranoid and acts_as_paranoid. I'm going to treat this as a bug until I get a chance to make it an optional feature. Be aware of it.
  63 +
60 64 h3. and you may ask yourself, where does that highway go to?
61 65
62 66 If you find any bugs, have any ideas of features you think are missing, or find things you're like to see work differently, feel free to send me a message or a pull request.
63 67
  68 +Currently on the todo list:
  69 +* deal with validates_uniqueness_of issue
  70 +* add options for merging additional default_scope options (i.e. order, etc.)
  71 +
64 72 h3. Thanks
65 73
66 74 Thanks to Rick Olson for acts_as_paranoid which is obviously an inspiration in concept and execution, Ryan Bates for mentioning the idea of using default_scope for this on Ryan Daigle's "post introducing default_scope":defscope, and the Talking Heads for being the Talking Heads.
10 spec/android_spec.rb
@@ -5,6 +5,7 @@ class Person < ActiveRecord::Base
5 5 end
6 6
7 7 class Android < ActiveRecord::Base
  8 + validates_uniqueness_of :name
8 9 is_paranoid
9 10 end
10 11
@@ -73,4 +74,13 @@ class Android < ActiveRecord::Base
73 74 @r2d2.restore
74 75 }.should change(Android, :count).from(1).to(2)
75 76 end
  77 +
  78 + # Note: this isn't necessarily ideal, this just serves to demostrate
  79 + # how it currently works
  80 + it "should not ignore deleted items in validation checks" do
  81 + @r2d2.destroy
  82 + lambda{
  83 + Android.create!(:name => 'R2D2')
  84 + }.should raise_error(ActiveRecord::RecordInvalid)
  85 + end
76 86 end

0 comments on commit 1293eca

Please sign in to comment.
Something went wrong with that request. Please try again.