Permalink
Browse files

Add specs for zaius's find_or_create block patch

  • Loading branch information...
1 parent 3ec32dc commit 61860866029597d6ceb76608411620bb73796c6c @jeremyevans committed Jun 25, 2010
Showing with 8 additions and 0 deletions.
  1. +2 −0 CHANGELOG
  2. +6 −0 spec/model/model_spec.rb
View
@@ -1,5 +1,7 @@
=== HEAD
+* Allow Model.find_or_create to take a block which is yielded the object to be created, if no object is found (zaius, jeremyevans)
+
* Make PlaceholderLiteralString a GenericExpression subclass (jeremyevans)
* Allow nil/NULL to be used as a CASE expression value (jeremyevans)
@@ -302,6 +302,12 @@ def fetch_rows(sql)
"INSERT INTO items (x) VALUES (1)"
]
end
+
+ it "should pass the new record to be created to the block if no record is found" do
+ @c.meta_def(:find){|*|}
+ @c.find_or_create(:x => 1){|x| x[:y] = 2}
+ ["INSERT INTO items (x, y) VALUES (1, 2)", "INSERT INTO items (y, x) VALUES (2, 1)"].should include(MODEL_DB.sqls.first)
+ end
end
describe Sequel::Model, ".all" do

0 comments on commit 6186086

Please sign in to comment.