blob: 7004ff4879d30a65e6ef81fc8e9a8841ee2bad8f (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
require 'test_helper'
module Arel
describe 'update manager' do
describe 'new' do
it 'takes an engine' do
Arel::UpdateManager.new Table.engine
end
end
describe 'set' do
it "updates with null" do
table = Table.new(:users)
um = Arel::UpdateManager.new Table.engine
um.table table
um.set [[table[:name], nil]]
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = NULL }
end
it 'takes a string' do
table = Table.new(:users)
um = Arel::UpdateManager.new Table.engine
um.table table
um.set Nodes::SqlLiteral.new "foo = bar"
um.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
end
it 'takes a list of lists' do
table = Table.new(:users)
um = Arel::UpdateManager.new Table.engine
um.table table
um.set [[table[:id], 1], [table[:name], 'hello']]
um.to_sql.must_be_like %{
UPDATE "users" SET "id" = 1, "name" = 'hello'
}
end
it 'chains' do
table = Table.new(:users)
um = Arel::UpdateManager.new Table.engine
um.set([[table[:id], 1], [table[:name], 'hello']]).must_equal um
end
end
describe 'table' do
it 'generates an update statement' do
um = Arel::UpdateManager.new Table.engine
um.table Table.new(:users)
um.to_sql.must_be_like %{ UPDATE "users" }
end
it 'chains' do
um = Arel::UpdateManager.new Table.engine
um.table(Table.new(:users)).must_equal um
end
end
describe 'where' do
it 'generates a where clause' do
table = Table.new :users
um = Arel::UpdateManager.new Table.engine
um.table table
um.where table[:id].eq(1)
um.to_sql.must_be_like %{
UPDATE "users" WHERE "users"."id" = 1
}
end
it 'chains' do
table = Table.new :users
um = Arel::UpdateManager.new Table.engine
um.table table
um.where(table[:id].eq(1)).must_equal um
end
end
end
end
|