pg_assets 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/lib/pg_assets/helpers/views_migration_helper.rb +59 -0
- data/lib/pg_assets/models/concerns/loadable_asset.rb +28 -0
- data/lib/pg_assets/models/pg_constraint.rb +46 -0
- data/lib/pg_assets/models/pg_function.rb +46 -0
- data/lib/pg_assets/models/pg_mat_view.rb +29 -0
- data/lib/pg_assets/models/pg_trigger.rb +46 -0
- data/lib/pg_assets/models/pg_view.rb +29 -0
- data/lib/pg_assets/railtie.rb +29 -0
- data/lib/pg_assets/services/pg_asset_manager.rb +100 -0
- data/lib/pg_assets/version.rb +3 -0
- data/lib/pg_assets.rb +15 -0
- data/test/assets/constraint_check.sql +4 -0
- data/test/assets/constraint_multiple.sql +5 -0
- data/test/assets/constraint_unique.sql +4 -0
- data/test/assets/function1.sql +5 -0
- data/test/assets/function2.sql +5 -0
- data/test/assets/materialized_view_with_table.sql +7 -0
- data/test/assets/matview1.sql +2 -0
- data/test/assets/matview2.sql +2 -0
- data/test/assets/trigger1.sql +12 -0
- data/test/assets/trigger2.sql +12 -0
- data/test/assets/view1.sql +2 -0
- data/test/assets/view2.sql +2 -0
- data/test/assets/view_with_table.sql +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +19 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +32 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/test.log +41514 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/helpers/views_migration_helper_test.rb +99 -0
- data/test/models/pg_constraint_test.rb +53 -0
- data/test/models/pg_func_test.rb +38 -0
- data/test/models/pg_mat_view_test.rb +44 -0
- data/test/models/pg_trigger_test.rb +38 -0
- data/test/models/pg_view_test.rb +44 -0
- data/test/services/pg_asset_manager_test.rb +117 -0
- data/test/test_helper.rb +34 -0
- metadata +219 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/404.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
|
55
|
+
</div>
|
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/422.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
55
|
+
</div>
|
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/500.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
54
|
+
</div>
|
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::ViewsMigrationHelper do
|
|
4
|
+
include PGAssets::ViewsMigrationHelper
|
|
5
|
+
before do
|
|
6
|
+
load_asset :view1
|
|
7
|
+
load_asset :matview1
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe '.touching_view with unchanged table' do
|
|
11
|
+
it "removes and reinstalls the view" do
|
|
12
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
13
|
+
|
|
14
|
+
touching_view :view1 do
|
|
15
|
+
PGAssets::PGView.ours.count.must_equal 0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# this is really a postgresql function.. not sure where else to test it though
|
|
22
|
+
it "propogates table changes to the view" do
|
|
23
|
+
load_asset :view_with_table
|
|
24
|
+
asset_sql_before = PGAssets::Services::PGAssetManager.assets_dump
|
|
25
|
+
|
|
26
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
|
27
|
+
ALTER TABLE table_for_view RENAME COLUMN test2 TO bomboclaat;
|
|
28
|
+
SQL
|
|
29
|
+
|
|
30
|
+
asset_sql_after = PGAssets::Services::PGAssetManager.assets_dump
|
|
31
|
+
|
|
32
|
+
asset_sql_before.wont_match /bomboclaat/
|
|
33
|
+
asset_sql_after.must_match /bomboclaat/
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "allows for changing a view" do
|
|
37
|
+
asset_sql_before = PGAssets::Services::PGAssetManager.assets_dump
|
|
38
|
+
|
|
39
|
+
new_view = <<-SQL
|
|
40
|
+
CREATE OR REPLACE VIEW view1 AS
|
|
41
|
+
SELECT 1, 2 AS "rasclaat";
|
|
42
|
+
SQL
|
|
43
|
+
|
|
44
|
+
touching_view :view1, new_view do
|
|
45
|
+
wat = 'wat'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
asset_sql_after = PGAssets::Services::PGAssetManager.assets_dump
|
|
49
|
+
|
|
50
|
+
asset_sql_before.wont_match /rasclaat/
|
|
51
|
+
asset_sql_after.must_match /rasclaat/
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe '.touching_materialized_view with unchanged table' do
|
|
56
|
+
it "removes and reinstalls the materialized view" do
|
|
57
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
58
|
+
|
|
59
|
+
touching_materialized_view :matview1 do
|
|
60
|
+
PGAssets::PGMatView.ours.count.must_equal 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
PGAssets::PGMatView.ours.count.must_equal 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# this is really a postgresql function.. not sure where else to test it though
|
|
67
|
+
it "propogates table changes to the materilialized view" do
|
|
68
|
+
load_asset :materialized_view_with_table
|
|
69
|
+
asset_sql_before = PGAssets::Services::PGAssetManager.assets_dump
|
|
70
|
+
|
|
71
|
+
ActiveRecord::Base.connection.execute <<-SQL
|
|
72
|
+
ALTER TABLE table_for_view RENAME COLUMN test2 TO bomboclaat;
|
|
73
|
+
SQL
|
|
74
|
+
|
|
75
|
+
asset_sql_after = PGAssets::Services::PGAssetManager.assets_dump
|
|
76
|
+
|
|
77
|
+
asset_sql_before.wont_match /bomboclaat/
|
|
78
|
+
asset_sql_after.must_match /bomboclaat/
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "allows for changing a view" do
|
|
82
|
+
asset_sql_before = PGAssets::Services::PGAssetManager.assets_dump
|
|
83
|
+
|
|
84
|
+
new_view = <<-SQL
|
|
85
|
+
CREATE MATERIALIZED VIEW matview1 AS
|
|
86
|
+
SELECT 1, 2 AS "rasclaat";
|
|
87
|
+
SQL
|
|
88
|
+
|
|
89
|
+
touching_materialized_view :matview1, new_view do
|
|
90
|
+
wat = 'wat'
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
asset_sql_after = PGAssets::Services::PGAssetManager.assets_dump
|
|
94
|
+
|
|
95
|
+
asset_sql_before.wont_match /rasclaat/
|
|
96
|
+
asset_sql_after.must_match /rasclaat/
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::PGConstraint do
|
|
4
|
+
describe ".ours" do
|
|
5
|
+
it "lists the constraints" do
|
|
6
|
+
PGAssets::PGConstraint.ours.count.must_equal 0
|
|
7
|
+
load_asset :constraint_check
|
|
8
|
+
PGAssets::PGConstraint.ours.count.must_equal 1
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "remove" do
|
|
13
|
+
it "removes the constraint" do
|
|
14
|
+
load_asset :constraint_unique
|
|
15
|
+
load_asset :constraint_check
|
|
16
|
+
@constraint = PGAssets::PGConstraint.ours.first
|
|
17
|
+
PGAssets::PGConstraint.ours.count.must_equal 2
|
|
18
|
+
@constraint.remove
|
|
19
|
+
PGAssets::PGConstraint.ours.pluck(:conname).include?(@constraint.conname).must_equal false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "doesn't effect other constraints" do
|
|
23
|
+
load_asset :constraint_multiple
|
|
24
|
+
PGAssets::PGConstraint.ours.count.must_equal 3
|
|
25
|
+
|
|
26
|
+
@constraint = PGAssets::PGConstraint.ours.sample
|
|
27
|
+
@constraint.remove
|
|
28
|
+
PGAssets::PGConstraint.ours.count.must_equal 2
|
|
29
|
+
|
|
30
|
+
@constraint = PGAssets::PGConstraint.ours.sample
|
|
31
|
+
@constraint.remove
|
|
32
|
+
PGAssets::PGConstraint.ours.count.must_equal 1
|
|
33
|
+
|
|
34
|
+
@constraint = PGAssets::PGConstraint.ours.sample
|
|
35
|
+
@constraint.remove
|
|
36
|
+
PGAssets::PGConstraint.ours.count.must_equal 0
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe "reinstall" do
|
|
41
|
+
before do
|
|
42
|
+
load_asset :constraint_unique
|
|
43
|
+
load_asset :constraint_check
|
|
44
|
+
@constraint = PGAssets::PGConstraint.ours.first
|
|
45
|
+
@constraint.remove
|
|
46
|
+
end
|
|
47
|
+
it "reinstalls the constraint" do
|
|
48
|
+
PGAssets::PGConstraint.ours.count.must_equal 1
|
|
49
|
+
@constraint.reinstall
|
|
50
|
+
PGAssets::PGConstraint.ours.pluck(:conname).include?(@constraint.conname).must_equal true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::PGFunction do
|
|
4
|
+
describe ".ours" do
|
|
5
|
+
it "lists the functions" do
|
|
6
|
+
PGAssets::PGFunction.ours.count.must_equal 0
|
|
7
|
+
load_asset :function1
|
|
8
|
+
PGAssets::PGFunction.ours.count.must_equal 1
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "remove" do
|
|
13
|
+
before do
|
|
14
|
+
load_asset :function2
|
|
15
|
+
load_asset :function1
|
|
16
|
+
@function = PGAssets::PGFunction.ours.first
|
|
17
|
+
end
|
|
18
|
+
it "removes the function" do
|
|
19
|
+
PGAssets::PGFunction.ours.count.must_equal 2
|
|
20
|
+
@function.remove
|
|
21
|
+
PGAssets::PGFunction.ours.pluck(:proname).include?(@function.proname).must_equal false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "reinstall" do
|
|
26
|
+
before do
|
|
27
|
+
load_asset :function1
|
|
28
|
+
load_asset :function2
|
|
29
|
+
@function = PGAssets::PGFunction.ours.first
|
|
30
|
+
@function.remove
|
|
31
|
+
end
|
|
32
|
+
it "reinstalls the function" do
|
|
33
|
+
PGAssets::PGFunction.ours.count.must_equal 1
|
|
34
|
+
@function.reinstall
|
|
35
|
+
PGAssets::PGFunction.ours.pluck(:proname).include?(@function.proname).must_equal true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::PGMatView do
|
|
4
|
+
describe ".ours" do
|
|
5
|
+
it "lists the materialized views" do
|
|
6
|
+
PGAssets::PGMatView.ours.count.must_equal 0
|
|
7
|
+
load_asset :matview1
|
|
8
|
+
PGAssets::PGMatView.ours.count.must_equal 1
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "doesn't include regular views" do
|
|
12
|
+
load_asset :matview1
|
|
13
|
+
load_asset :view1
|
|
14
|
+
PGAssets::PGMatView.ours.count.must_equal 1
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "remove" do
|
|
19
|
+
before do
|
|
20
|
+
load_asset :matview1
|
|
21
|
+
load_asset :matview2
|
|
22
|
+
@matview = PGAssets::PGMatView.ours.first
|
|
23
|
+
end
|
|
24
|
+
it "removes the materialized view" do
|
|
25
|
+
PGAssets::PGMatView.ours.count.must_equal 2
|
|
26
|
+
@matview.remove
|
|
27
|
+
PGAssets::PGMatView.ours.pluck(:matviewname).include?(@matview.matviewname).must_equal false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "reinstall" do
|
|
32
|
+
before do
|
|
33
|
+
load_asset :matview1
|
|
34
|
+
load_asset :matview2
|
|
35
|
+
@matview = PGAssets::PGMatView.ours.first
|
|
36
|
+
@matview.remove
|
|
37
|
+
end
|
|
38
|
+
it "reinstalls the materialized view" do
|
|
39
|
+
PGAssets::PGMatView.ours.count.must_equal 1
|
|
40
|
+
@matview.reinstall
|
|
41
|
+
PGAssets::PGMatView.ours.pluck(:matviewname).include?(@matview.matviewname).must_equal true
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::PGTrigger do
|
|
4
|
+
describe ".ours" do
|
|
5
|
+
it "lists the functions" do
|
|
6
|
+
PGAssets::PGTrigger.ours.count.must_equal 0
|
|
7
|
+
load_asset :trigger1
|
|
8
|
+
PGAssets::PGTrigger.ours.count.must_equal 1
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "remove" do
|
|
13
|
+
before do
|
|
14
|
+
load_asset :trigger1
|
|
15
|
+
load_asset :trigger2
|
|
16
|
+
@trigger = PGAssets::PGTrigger.ours.first
|
|
17
|
+
end
|
|
18
|
+
it "removes the trigger" do
|
|
19
|
+
PGAssets::PGTrigger.ours.count.must_equal 2
|
|
20
|
+
@trigger.remove
|
|
21
|
+
PGAssets::PGTrigger.ours.pluck(:tgname).include?(@trigger.tgname).must_equal false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "reinstall" do
|
|
26
|
+
before do
|
|
27
|
+
load_asset :trigger1
|
|
28
|
+
load_asset :trigger2
|
|
29
|
+
@trigger = PGAssets::PGTrigger.ours.first
|
|
30
|
+
@trigger.remove
|
|
31
|
+
end
|
|
32
|
+
it "reinstalls the function" do
|
|
33
|
+
PGAssets::PGTrigger.ours.count.must_equal 1
|
|
34
|
+
@trigger.reinstall
|
|
35
|
+
PGAssets::PGTrigger.ours.pluck(:tgname).include?(@trigger.tgname).must_equal true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::PGView do
|
|
4
|
+
describe ".ours" do
|
|
5
|
+
it "lists the views" do
|
|
6
|
+
PGAssets::PGView.ours.count.must_equal 0
|
|
7
|
+
load_asset :view1
|
|
8
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "doesn't include materialized views" do
|
|
12
|
+
load_asset :matview1
|
|
13
|
+
load_asset :view1
|
|
14
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "remove" do
|
|
19
|
+
before do
|
|
20
|
+
load_asset :view1
|
|
21
|
+
load_asset :view2
|
|
22
|
+
@view = PGAssets::PGView.ours.first
|
|
23
|
+
end
|
|
24
|
+
it "removes the view" do
|
|
25
|
+
PGAssets::PGView.ours.count.must_equal 2
|
|
26
|
+
@view.remove
|
|
27
|
+
PGAssets::PGView.ours.pluck(:viewname).include?(@view.viewname).must_equal false
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "reinstall" do
|
|
32
|
+
before do
|
|
33
|
+
load_asset :view1
|
|
34
|
+
load_asset :view2
|
|
35
|
+
@view = PGAssets::PGView.ours.first
|
|
36
|
+
@view.remove
|
|
37
|
+
end
|
|
38
|
+
it "reinstalls the view" do
|
|
39
|
+
PGAssets::PGView.ours.count.must_equal 1
|
|
40
|
+
@view.reinstall
|
|
41
|
+
PGAssets::PGView.ours.pluck(:viewname).include?(@view.viewname).must_equal true
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
describe PGAssets::Services::PGAssetManager do
|
|
4
|
+
before do
|
|
5
|
+
load_asset :view1
|
|
6
|
+
load_asset :view2
|
|
7
|
+
load_asset :matview1
|
|
8
|
+
load_asset :matview2
|
|
9
|
+
load_asset :function1
|
|
10
|
+
load_asset :function2
|
|
11
|
+
load_asset :trigger1
|
|
12
|
+
load_asset :trigger2
|
|
13
|
+
load_asset :constraint_multiple
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe ".views" do
|
|
17
|
+
it "lists the views" do
|
|
18
|
+
PGAssets::Services::PGAssetManager.views.size.must_equal 2
|
|
19
|
+
PGAssets::Services::PGAssetManager.views.first.viewname.must_equal 'view1'
|
|
20
|
+
PGAssets::Services::PGAssetManager.views.second.viewname.must_equal 'view2'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ".matviews" do
|
|
25
|
+
it "lists the materialized views" do
|
|
26
|
+
PGAssets::Services::PGAssetManager.matviews.size.must_equal 2
|
|
27
|
+
PGAssets::Services::PGAssetManager.matviews.first.matviewname.must_equal 'matview1'
|
|
28
|
+
PGAssets::Services::PGAssetManager.matviews.second.matviewname.must_equal 'matview2'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe ".functions" do
|
|
33
|
+
it "lists the functions" do
|
|
34
|
+
PGAssets::Services::PGAssetManager.functions.size.must_equal 4 # each trigger has functions
|
|
35
|
+
PGAssets::Services::PGAssetManager.functions.first.proname.must_equal 'function1'
|
|
36
|
+
PGAssets::Services::PGAssetManager.functions.second.proname.must_equal 'function2'
|
|
37
|
+
PGAssets::Services::PGAssetManager.functions.last.proname.must_equal 'womp2'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe ".triggers" do
|
|
42
|
+
it "lists the triggers" do
|
|
43
|
+
PGAssets::Services::PGAssetManager.triggers.size.must_equal 2
|
|
44
|
+
PGAssets::Services::PGAssetManager.triggers.first.tgname.must_equal 'trigger1'
|
|
45
|
+
PGAssets::Services::PGAssetManager.triggers.second.tgname.must_equal 'trigger2'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe ".constraints" do
|
|
50
|
+
it "lists the constraints" do
|
|
51
|
+
PGAssets::Services::PGAssetManager.constraints.size.must_equal 3
|
|
52
|
+
PGAssets::Services::PGAssetManager.constraints.first.conname.must_equal 'table_with_multiple_constraint_test2_key'
|
|
53
|
+
PGAssets::Services::PGAssetManager.constraints.second.conname.must_equal 'table_with_multiple_constraint_test_check'
|
|
54
|
+
PGAssets::Services::PGAssetManager.constraints.last.conname.must_equal 'table_with_multiple_constraint_test_check1'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe ".assets_dump" do
|
|
59
|
+
it "creates an asset dump" do
|
|
60
|
+
regexes = [
|
|
61
|
+
/BRO/,
|
|
62
|
+
/CREATE OR REPLACE VIEW/i,
|
|
63
|
+
/CREATE OR REPLACE FUNCTION/i,
|
|
64
|
+
/DROP TRIGGER IF EXISTS/i,
|
|
65
|
+
/CREATE TRIGGER/i,
|
|
66
|
+
/public.womp2/,
|
|
67
|
+
/view1/,
|
|
68
|
+
/view2/,
|
|
69
|
+
/function1/,
|
|
70
|
+
/function2/,
|
|
71
|
+
/trigger1/,
|
|
72
|
+
/trigger2/
|
|
73
|
+
]
|
|
74
|
+
assets_dump = PGAssets::Services::PGAssetManager.assets_dump
|
|
75
|
+
regexes.each do |regex|
|
|
76
|
+
assets_dump.must_match regex
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "orders things properly" do
|
|
81
|
+
assets_dump = PGAssets::Services::PGAssetManager.assets_dump
|
|
82
|
+
view_index = assets_dump.index('CREATE OR REPLACE VIEW')
|
|
83
|
+
function_index = assets_dump.index('CREATE OR REPLACE FUNCTION')
|
|
84
|
+
trigger_index = assets_dump.index('CREATE TRIGGER')
|
|
85
|
+
|
|
86
|
+
assert_operator view_index, :<, function_index
|
|
87
|
+
assert_operator function_index, :<, trigger_index
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe ".assets_load" do
|
|
92
|
+
before do
|
|
93
|
+
@assets = PGAssets::Services::PGAssetManager.assets_dump
|
|
94
|
+
PGAssets::Services::PGAssetManager.views.each { |v| v.remove }
|
|
95
|
+
PGAssets::Services::PGAssetManager.matviews.each { |v| v.remove }
|
|
96
|
+
PGAssets::Services::PGAssetManager.triggers.each { |t| t.remove }
|
|
97
|
+
PGAssets::Services::PGAssetManager.functions.each { |f| f.remove }
|
|
98
|
+
PGAssets::Services::PGAssetManager.constraints.each { |f| f.remove }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "loads the assets" do
|
|
102
|
+
PGAssets::Services::PGAssetManager.views.size.must_equal 0
|
|
103
|
+
PGAssets::Services::PGAssetManager.matviews.size.must_equal 0
|
|
104
|
+
PGAssets::Services::PGAssetManager.functions.size.must_equal 0
|
|
105
|
+
PGAssets::Services::PGAssetManager.triggers.size.must_equal 0
|
|
106
|
+
PGAssets::Services::PGAssetManager.constraints.size.must_equal 0
|
|
107
|
+
|
|
108
|
+
PGAssets::Services::PGAssetManager.assets_load @assets
|
|
109
|
+
|
|
110
|
+
PGAssets::Services::PGAssetManager.views.size.must_equal 2
|
|
111
|
+
PGAssets::Services::PGAssetManager.matviews.size.must_equal 2
|
|
112
|
+
PGAssets::Services::PGAssetManager.functions.size.must_equal 4
|
|
113
|
+
PGAssets::Services::PGAssetManager.triggers.size.must_equal 2
|
|
114
|
+
PGAssets::Services::PGAssetManager.constraints.size.must_equal 3
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
|
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
5
|
+
require "rails/test_help"
|
|
6
|
+
require "minitest/autorun"
|
|
7
|
+
require 'pg_assets'
|
|
8
|
+
require 'database_cleaner'
|
|
9
|
+
|
|
10
|
+
# postgres has DDL in transactions, SWEET
|
|
11
|
+
DatabaseCleaner.strategy = :transaction
|
|
12
|
+
DatabaseCleaner.clean
|
|
13
|
+
|
|
14
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
15
|
+
|
|
16
|
+
# Load support files
|
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
18
|
+
|
|
19
|
+
# This is how we load assets fro test/assets/
|
|
20
|
+
def load_asset(asset_name)
|
|
21
|
+
File.open(File.join('test', 'assets', asset_name.to_s + '.sql'), 'r') do |f|
|
|
22
|
+
ActiveRecord::Base::connection.execute f.read
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class Minitest::Spec
|
|
27
|
+
before :each do
|
|
28
|
+
DatabaseCleaner.start
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
after :each do
|
|
32
|
+
DatabaseCleaner.clean
|
|
33
|
+
end
|
|
34
|
+
end
|