|
1 | 1 | require "./spec_helper"
|
2 |
| -require "../src/db_setup" |
3 | 2 |
|
4 |
| -describe "database setup" do |
5 |
| - it "creates punches table with correct schema" do |
6 |
| - bag = PunchingBag::Tracker.new(PunchingBag.db) |
7 |
| - bag.setup_database |
8 |
| - |
9 |
| - result = PunchingBag.db.query_all(<<-SQL, as: {column_name: String, data_type: String}) |
10 |
| - SELECT column_name, data_type |
11 |
| - FROM information_schema.columns |
12 |
| - WHERE table_name = 'punches' |
13 |
| - ORDER BY ordinal_position |
14 |
| - SQL |
15 |
| - |
16 |
| - result.should contain({column_name: "id", data_type: "bigint"}) |
17 |
| - result.should contain({column_name: "punchable_type", data_type: "character varying"}) |
18 |
| - result.should contain({column_name: "hits", data_type: "integer"}) |
19 |
| - result.should contain({column_name: "created_at", data_type: "timestamp with time zone"}) |
20 |
| - end |
21 |
| - |
22 |
| - it "creates required indexes" do |
23 |
| - DB.open(PunchingBag::Configuration.database_url) do |db| |
24 |
| - indexes = db.query_all(<<-SQL, as: String) |
25 |
| - SELECT indexname |
26 |
| - FROM pg_indexes |
27 |
| - WHERE tablename = 'punches' |
28 |
| - AND indexname != 'punches_pkey'; |
29 |
| - SQL |
| 3 | +describe "DB Setup" do |
| 4 | + describe "database connection" do |
| 5 | + it "creates punches table with correct schema" do |
| 6 | + DB.open(PunchingBag::Configuration.database_url) do |db| |
| 7 | + bag = PunchingBag::Tracker.new(PunchingBag.db) |
| 8 | + bag.setup_database |
| 9 | + |
| 10 | + result = PunchingBag.db.query_all(<<-SQL, as: {column_name: String, data_type: String}) |
| 11 | + SELECT column_name, data_type |
| 12 | + FROM information_schema.columns |
| 13 | + WHERE table_name = 'punches' |
| 14 | + ORDER BY ordinal_position |
| 15 | + SQL |
30 | 16 |
|
31 |
| - indexes.should contain("punchable_index") |
32 |
| - indexes.should contain("idx_punches_created_at") |
| 17 | + result.should contain({column_name: "id", data_type: "bigint"}) |
| 18 | + result.should contain({column_name: "punchable_type", data_type: "character varying"}) |
| 19 | + result.should contain({column_name: "hits", data_type: "integer"}) |
| 20 | + result.should contain({column_name: "created_at", data_type: "timestamp with time zone"}) |
| 21 | + end |
33 | 22 | end
|
34 | 23 | end
|
35 | 24 |
|
36 |
| - it "maintains idempotency when running setup multiple times" do |
37 |
| - 3.times do |
| 25 | + describe "table schema" do |
| 26 | + it "has the expected columns" do |
38 | 27 | DB.open(PunchingBag::Configuration.database_url) do |db|
|
39 |
| - index_count = db.scalar(<<-SQL).as(Int64) |
40 |
| - SELECT COUNT(*) |
41 |
| - FROM pg_indexes |
42 |
| - WHERE tablename = 'punches' |
43 |
| - AND indexname != 'punches_pkey'; |
| 28 | + result = db.query_all(<<-SQL, as: {column_name: String, data_type: String}) |
| 29 | + SELECT column_name, data_type |
| 30 | + FROM information_schema.columns |
| 31 | + WHERE table_name = 'punches' |
| 32 | + ORDER BY ordinal_position |
44 | 33 | SQL
|
45 |
| - index_count.should eq(2) |
| 34 | + |
| 35 | + result.should contain({column_name: "id", data_type: "bigint"}) |
| 36 | + result.should contain({column_name: "punchable_type", data_type: "character varying"}) |
| 37 | + result.should contain({column_name: "hits", data_type: "integer"}) |
| 38 | + result.should contain({column_name: "created_at", data_type: "timestamp with time zone"}) |
46 | 39 | end
|
47 | 40 | end
|
48 | 41 | end
|
|
0 commit comments