Skip to content
Browse files

deprecating the "delete" method in favor of compile_delete

  • Loading branch information...
1 parent a852164 commit 9e05f7e01be3840b1a66bbda0292f97740f6947e @tenderlove tenderlove committed
Showing with 21 additions and 10 deletions.
  1. +3 −0 History.txt
  2. +12 −2 lib/arel/crud.rb
  3. +2 −4 test/test_crud.rb
  4. +4 −4 test/test_select_manager.rb
View
3 History.txt
@@ -12,6 +12,9 @@
* Calls to `update` are deprecated. Please use `compile_update` then call
`to_sql` on the resulting object and execute that SQL.
+ * Calls to `delete` are deprecated. Please use `compile_delete` then call
+ `to_sql` on the resulting object and execute that SQL.
+
== 2.0.6 12/01/2010
* Bug Fixes
View
14 lib/arel/crud.rb
@@ -48,11 +48,21 @@ def insert values
@engine.connection.insert compile_insert(values).to_sql
end
- def delete
+ def compile_delete
dm = DeleteManager.new @engine
dm.wheres = @ctx.wheres
dm.from @ctx.froms
- @engine.connection.delete dm.to_sql, 'AREL'
+ dm
+ end
+
+ def delete
+ if $VERBOSE
+ warn <<-eowarn
+delete (#{caller.first}) is deprecated and will be removed in ARel 2.2.0. Please
+switch to `compile_delete`
+ eowarn
+ end
+ @engine.connection.delete compile_delete.to_sql, 'AREL'
end
end
end
View
6 test/test_crud.rb
@@ -57,10 +57,8 @@ def initialize engine = FakeEngine.new
table = Table.new :users
fc = FakeCrudder.new
fc.from table
- fc.delete
- fc.engine.calls.find { |method, _|
- method == :delete
- }.wont_be_nil
+ stmt = fc.compile_delete
+ assert_instance_of Arel::DeleteManager, stmt
end
end
end
View
8 test/test_select_manager.rb
@@ -390,9 +390,9 @@ def execute sql, name = nil, *args
table = Table.new :users
manager = Arel::SelectManager.new engine
manager.from table
- manager.delete
+ stmt = manager.compile_delete
- engine.executed.last.must_be_like %{ DELETE FROM "users" }
+ stmt.to_sql.must_be_like %{ DELETE FROM "users" }
end
it "copies where" do
@@ -401,9 +401,9 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new engine
manager.from table
manager.where table[:id].eq 10
- manager.delete
+ stmt = manager.compile_delete
- engine.executed.last.must_be_like %{
+ stmt.to_sql.must_be_like %{
DELETE FROM "users" WHERE "users"."id" = 10
}
end

0 comments on commit 9e05f7e

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