forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathar_dba_spec.rb
More file actions
57 lines (48 loc) · 1.92 KB
/
Copy pathar_dba_spec.rb
File metadata and controls
57 lines (48 loc) · 1.92 KB
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
describe "ar_dba extension" do
let(:connection) { ApplicationRecord.connection }
describe "#xlog_location" do
it "returns a valid lsn" do
expect(connection.xlog_location).to match(%r{\h+/\h+})
end
end
describe "#xlog_location_diff" do
it "returns the correct xlog difference" do
expect(connection.xlog_location_diff("18/72F84A48", "18/72F615B8")). to eq(144_528)
end
end
describe "#primary_key_index" do
it "returns nil when there is no primary key" do
table_name = "no_pk_test"
connection.select_value("CREATE TABLE #{table_name} (id INTEGER)")
expect(connection.primary_key_index(table_name)).to be nil
end
it "returns the correct primary key" do
index_def = connection.primary_key_index("miq_databases")
expect(index_def.table).to eq("miq_databases")
expect(index_def.unique).to be true
expect(index_def.columns).to eq(["id"])
end
it "works with composite primary keys" do
table_name = "comp_pk_test"
connection.select_value("CREATE TABLE #{table_name} (id1 INTEGER, id2 INTEGER)")
connection.select_value("ALTER TABLE #{table_name} ADD PRIMARY KEY (id1, id2)")
index_def = connection.primary_key_index(table_name)
expect(index_def.table).to eq(table_name)
expect(index_def.unique).to be true
expect(index_def.columns).to match_array(%w(id1 id2))
end
end
describe "#primary_key?" do
it "returns false for a table without a primary key" do
table_name = "no_pk_test"
connection.select_value("CREATE TABLE #{table_name} (id INTEGER)")
expect(connection.primary_key?(table_name)).to be false
end
it "returns true for a table with a primary key" do
expect(connection.primary_key?("miq_databases")).to be true
end
it "returns true for composite primary keys" do
expect(connection.primary_key?("storages_vms_and_templates")).to be true
end
end
end