aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/unit/relations/delete_spec.rb
blob: fa887d20fdde3acba6221850819388b280120bb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')

module Arel
  describe Deletion do
    before do
      @relation = Table.new(:users)
    end

    describe '#to_sql' do
      it 'manufactures sql deleting a table relation' do
        Deletion.new(@relation).to_sql.should be_like("
          DELETE
          FROM `users`
        ")
      end

      it 'manufactures sql deleting a where relation' do
        Deletion.new(@relation.where(@relation[:id].eq(1))).to_sql.should be_like("
          DELETE
          FROM `users`
          WHERE `users`.`id` = 1
        ")
      end

      it "manufactures sql deleting a ranged relation" do
        Deletion.new(@relation.take(1)).to_sql.should be_like("
          DELETE
          FROM `users`
          LIMIT 1
        ")
      end
    end

    describe '#call' do
      it 'executes a delete on the connection' do
        deletion = Deletion.new(@relation)
        mock(connection = Object.new).delete(deletion.to_sql)
        deletion.call(connection)
      end
    end
  end
end