aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/unit/relations/deletion_spec.rb
blob: 08f7bc03bbef58a2b215ecc9840a96ef64cbd842 (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 ActiveRelation
  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 selection relation' do
        Deletion.new(@relation.select(@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