aboutsummaryrefslogtreecommitdiffstats
path: root/spec/active_relation/unit/relations/insertion_spec.rb
blob: f081743c507a191cbaa04a1b9c897c2386e64974 (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
require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper')

module ActiveRelation
  describe Insertion do
    before do
      @relation = Table.new(:users)
      @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation))
    end
  
    describe '#to_sql' do
      it 'manufactures sql inserting the data for one item' do
        @insertion.to_sql.should be_like("
          INSERT
          INTO `users`
          (`users`.`name`) VALUES ('nick')
        ")
      end
    end
    
    describe '#call' do
      it 'executes an insert on the connection' do
        mock(connection = Object.new).insert(@insertion.to_sql)
        @insertion.call(connection)
      end
    end
  end
end