fx 0.8.0 → 0.9.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 +4 -4
- data/.github/workflows/ci.yml +2 -7
- data/CHANGELOG.md +124 -0
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +12 -1
- data/README.md +2 -0
- data/bin/standardrb +27 -0
- data/fx.gemspec +10 -15
- data/lib/fx/adapters/postgres/connection.rb +12 -0
- data/lib/fx/adapters/postgres/functions.rb +3 -3
- data/lib/fx/adapters/postgres/triggers.rb +3 -3
- data/lib/fx/adapters/postgres.rb +6 -14
- data/lib/fx/command_recorder.rb +87 -6
- data/lib/fx/configuration.rb +0 -25
- data/lib/fx/definition.rb +16 -6
- data/lib/fx/function.rb +3 -3
- data/lib/fx/schema_dumper.rb +45 -5
- data/lib/fx/statements.rb +228 -6
- data/lib/fx/trigger.rb +3 -3
- data/lib/fx/version.rb +1 -1
- data/lib/fx.rb +30 -12
- data/lib/generators/fx/function/function_generator.rb +2 -2
- data/lib/generators/fx/trigger/trigger_generator.rb +1 -5
- data/spec/acceptance/user_manages_functions_spec.rb +4 -4
- data/spec/acceptance/user_manages_triggers_spec.rb +6 -6
- data/spec/acceptance_helper.rb +2 -2
- data/spec/dummy/config/application.rb +5 -1
- data/spec/features/functions/migrations_spec.rb +3 -3
- data/spec/features/functions/revert_spec.rb +3 -3
- data/spec/features/triggers/migrations_spec.rb +4 -4
- data/spec/features/triggers/revert_spec.rb +5 -5
- data/spec/fx/adapters/postgres/functions_spec.rb +26 -30
- data/spec/fx/adapters/postgres/triggers_spec.rb +34 -38
- data/spec/fx/adapters/postgres_spec.rb +107 -109
- data/spec/fx/command_recorder_spec.rb +27 -25
- data/spec/fx/configuration_spec.rb +20 -9
- data/spec/fx/definition_spec.rb +27 -35
- data/spec/fx/function_spec.rb +45 -48
- data/spec/fx/schema_dumper_spec.rb +123 -0
- data/spec/fx/statements_spec.rb +217 -0
- data/spec/fx/trigger_spec.rb +37 -40
- data/spec/fx_spec.rb +28 -0
- data/spec/generators/fx/function/function_generator_spec.rb +3 -3
- data/spec/generators/fx/trigger/trigger_generator_spec.rb +10 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/definition_helpers.rb +2 -6
- data/spec/support/warning_helper.rb +5 -0
- metadata +21 -163
- data/lib/fx/command_recorder/arguments.rb +0 -43
- data/lib/fx/command_recorder/function.rb +0 -30
- data/lib/fx/command_recorder/trigger.rb +0 -30
- data/lib/fx/schema_dumper/function.rb +0 -38
- data/lib/fx/schema_dumper/trigger.rb +0 -29
- data/lib/fx/statements/function.rb +0 -113
- data/lib/fx/statements/trigger.rb +0 -144
- data/spec/fx/command_recorder/arguments_spec.rb +0 -41
- data/spec/fx/schema_dumper/function_spec.rb +0 -78
- data/spec/fx/schema_dumper/trigger_spec.rb +0 -40
- data/spec/fx/statements/function_spec.rb +0 -103
- data/spec/fx/statements/trigger_spec.rb +0 -132
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
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
|
-
EXECUTE FUNCTION uppercase_users_name();
|
|
30
|
-
EOS
|
|
3
|
+
RSpec.describe Fx::Adapters::Postgres::Triggers, :db do
|
|
4
|
+
describe ".all" do
|
|
5
|
+
it "returns `Trigger` objects" do
|
|
6
|
+
connection = ActiveRecord::Base.connection
|
|
7
|
+
connection.execute <<~EOS
|
|
8
|
+
CREATE TABLE users (
|
|
9
|
+
id int PRIMARY KEY,
|
|
10
|
+
name varchar(256),
|
|
11
|
+
upper_name varchar(256)
|
|
12
|
+
);
|
|
13
|
+
EOS
|
|
14
|
+
connection.execute <<~EOS
|
|
15
|
+
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
16
|
+
RETURNS trigger AS $$
|
|
17
|
+
BEGIN
|
|
18
|
+
NEW.upper_name = UPPER(NEW.name);
|
|
19
|
+
RETURN NEW;
|
|
20
|
+
END;
|
|
21
|
+
$$ LANGUAGE plpgsql;
|
|
22
|
+
EOS
|
|
23
|
+
connection.execute <<~EOS
|
|
24
|
+
CREATE TRIGGER uppercase_users_name
|
|
25
|
+
BEFORE INSERT ON users
|
|
26
|
+
FOR EACH ROW
|
|
27
|
+
EXECUTE FUNCTION uppercase_users_name();
|
|
28
|
+
EOS
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
triggers = Fx::Adapters::Postgres::Triggers.new(connection).all
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
end
|
|
32
|
+
first = triggers.first
|
|
33
|
+
expect(triggers.size).to eq(1)
|
|
34
|
+
expect(first.name).to eq("uppercase_users_name")
|
|
35
|
+
expect(first.definition).to include("BEFORE INSERT")
|
|
36
|
+
expect(first.definition).to match(/ON [public.ser|]/)
|
|
37
|
+
expect(first.definition).to include("FOR EACH ROW")
|
|
38
|
+
expect(first.definition).to include("EXECUTE FUNCTION uppercase_users_name()")
|
|
43
39
|
end
|
|
44
40
|
end
|
|
45
41
|
end
|
|
@@ -1,104 +1,82 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
describe
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
RETURNS text AS $$
|
|
12
|
-
BEGIN
|
|
13
|
-
RETURN 'test';
|
|
14
|
-
END;
|
|
15
|
-
$$ LANGUAGE plpgsql;
|
|
16
|
-
EOS
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
expect(adapter.functions.map(&:name)).to include("test")
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "#create_trigger" do
|
|
24
|
-
it "successfully creates a trigger" do
|
|
25
|
-
connection.execute <<-EOS
|
|
26
|
-
CREATE TABLE users (
|
|
27
|
-
id int PRIMARY KEY,
|
|
28
|
-
name varchar(256),
|
|
29
|
-
upper_name varchar(256)
|
|
30
|
-
);
|
|
31
|
-
EOS
|
|
32
|
-
adapter = Postgres.new
|
|
33
|
-
adapter.create_function <<-EOS
|
|
34
|
-
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
35
|
-
RETURNS trigger AS $$
|
|
3
|
+
RSpec.describe Fx::Adapters::Postgres, :db do
|
|
4
|
+
describe "#create_function" do
|
|
5
|
+
it "successfully creates a function" do
|
|
6
|
+
adapter = Fx::Adapters::Postgres.new
|
|
7
|
+
adapter.create_function(
|
|
8
|
+
<<~EOS
|
|
9
|
+
CREATE OR REPLACE FUNCTION test()
|
|
10
|
+
RETURNS text AS $$
|
|
36
11
|
BEGIN
|
|
37
|
-
|
|
38
|
-
RETURN NEW;
|
|
12
|
+
RETURN 'test';
|
|
39
13
|
END;
|
|
40
14
|
$$ LANGUAGE plpgsql;
|
|
41
15
|
EOS
|
|
42
|
-
|
|
43
|
-
<<-EOS
|
|
44
|
-
CREATE TRIGGER uppercase_users_name
|
|
45
|
-
BEFORE INSERT ON users
|
|
46
|
-
FOR EACH ROW
|
|
47
|
-
EXECUTE FUNCTION uppercase_users_name();
|
|
48
|
-
EOS
|
|
49
|
-
)
|
|
16
|
+
)
|
|
50
17
|
|
|
51
|
-
|
|
52
|
-
end
|
|
18
|
+
expect(adapter.functions.map(&:name)).to include("test")
|
|
53
19
|
end
|
|
20
|
+
end
|
|
54
21
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
22
|
+
describe "#create_trigger" do
|
|
23
|
+
it "successfully creates a trigger" do
|
|
24
|
+
connection.execute <<~EOS
|
|
25
|
+
CREATE TABLE users (
|
|
26
|
+
id int PRIMARY KEY,
|
|
27
|
+
name varchar(256),
|
|
28
|
+
upper_name varchar(256)
|
|
29
|
+
);
|
|
30
|
+
EOS
|
|
31
|
+
adapter = Fx::Adapters::Postgres.new
|
|
32
|
+
adapter.create_function <<~EOS
|
|
33
|
+
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
34
|
+
RETURNS trigger AS $$
|
|
35
|
+
BEGIN
|
|
36
|
+
NEW.upper_name = UPPER(NEW.name);
|
|
37
|
+
RETURN NEW;
|
|
38
|
+
END;
|
|
39
|
+
$$ LANGUAGE plpgsql;
|
|
40
|
+
EOS
|
|
41
|
+
adapter.create_trigger(
|
|
42
|
+
<<~EOS
|
|
43
|
+
CREATE TRIGGER uppercase_users_name
|
|
44
|
+
BEFORE INSERT ON users
|
|
45
|
+
FOR EACH ROW
|
|
46
|
+
EXECUTE FUNCTION uppercase_users_name();
|
|
47
|
+
EOS
|
|
48
|
+
)
|
|
71
49
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
expect(adapter.triggers.map(&:name)).to include("uppercase_users_name")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
75
53
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
describe "#drop_function" do
|
|
55
|
+
context "when the function has arguments" do
|
|
56
|
+
it "successfully drops a function with the entire function signature" do
|
|
57
|
+
adapter = Fx::Adapters::Postgres.new
|
|
58
|
+
adapter.create_function(
|
|
59
|
+
<<~EOS
|
|
60
|
+
CREATE FUNCTION adder(x int, y int)
|
|
61
|
+
RETURNS int AS $$
|
|
62
|
+
BEGIN
|
|
63
|
+
RETURN $1 + $2;
|
|
64
|
+
END;
|
|
65
|
+
$$ LANGUAGE plpgsql;
|
|
66
|
+
EOS
|
|
67
|
+
)
|
|
89
68
|
|
|
90
|
-
|
|
69
|
+
adapter.drop_function(:adder)
|
|
91
70
|
|
|
92
|
-
|
|
93
|
-
end
|
|
71
|
+
expect(adapter.functions.map(&:name)).not_to include("adder")
|
|
94
72
|
end
|
|
95
73
|
end
|
|
96
74
|
|
|
97
|
-
|
|
98
|
-
it "
|
|
99
|
-
adapter = Postgres.new
|
|
75
|
+
context "when the function does not have arguments" do
|
|
76
|
+
it "successfully drops a function" do
|
|
77
|
+
adapter = Fx::Adapters::Postgres.new
|
|
100
78
|
adapter.create_function(
|
|
101
|
-
|
|
79
|
+
<<~EOS
|
|
102
80
|
CREATE OR REPLACE FUNCTION test()
|
|
103
81
|
RETURNS text AS $$
|
|
104
82
|
BEGIN
|
|
@@ -108,39 +86,59 @@ module Fx::Adapters
|
|
|
108
86
|
EOS
|
|
109
87
|
)
|
|
110
88
|
|
|
111
|
-
|
|
89
|
+
adapter.drop_function(:test)
|
|
90
|
+
|
|
91
|
+
expect(adapter.functions.map(&:name)).not_to include("test")
|
|
112
92
|
end
|
|
113
93
|
end
|
|
94
|
+
end
|
|
114
95
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
EOS
|
|
124
|
-
adapter = Postgres.new
|
|
125
|
-
adapter.create_function <<-EOS
|
|
126
|
-
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
127
|
-
RETURNS trigger AS $$
|
|
96
|
+
describe "#functions" do
|
|
97
|
+
it "finds functions and builds Fx::Function objects" do
|
|
98
|
+
adapter = Fx::Adapters::Postgres.new
|
|
99
|
+
adapter.create_function(
|
|
100
|
+
<<~EOS
|
|
101
|
+
CREATE OR REPLACE FUNCTION test()
|
|
102
|
+
RETURNS text AS $$
|
|
128
103
|
BEGIN
|
|
129
|
-
|
|
130
|
-
RETURN NEW;
|
|
104
|
+
RETURN 'test';
|
|
131
105
|
END;
|
|
132
106
|
$$ LANGUAGE plpgsql;
|
|
133
107
|
EOS
|
|
134
|
-
|
|
135
|
-
CREATE TRIGGER uppercase_users_name
|
|
136
|
-
BEFORE INSERT ON users
|
|
137
|
-
FOR EACH ROW
|
|
138
|
-
EXECUTE FUNCTION uppercase_users_name()
|
|
139
|
-
EOS
|
|
140
|
-
adapter.create_trigger(sql_definition)
|
|
108
|
+
)
|
|
141
109
|
|
|
142
|
-
|
|
143
|
-
|
|
110
|
+
expect(adapter.functions.map(&:name)).to eq ["test"]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe "#triggers" do
|
|
115
|
+
it "finds triggers and builds Fx::Trigger objects" do
|
|
116
|
+
connection.execute <<~EOS
|
|
117
|
+
CREATE TABLE users (
|
|
118
|
+
id int PRIMARY KEY,
|
|
119
|
+
name varchar(256),
|
|
120
|
+
upper_name varchar(256)
|
|
121
|
+
);
|
|
122
|
+
EOS
|
|
123
|
+
adapter = Fx::Adapters::Postgres.new
|
|
124
|
+
adapter.create_function <<~EOS
|
|
125
|
+
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
|
126
|
+
RETURNS trigger AS $$
|
|
127
|
+
BEGIN
|
|
128
|
+
NEW.upper_name = UPPER(NEW.name);
|
|
129
|
+
RETURN NEW;
|
|
130
|
+
END;
|
|
131
|
+
$$ LANGUAGE plpgsql;
|
|
132
|
+
EOS
|
|
133
|
+
sql_definition = <<~EOS
|
|
134
|
+
CREATE TRIGGER uppercase_users_name
|
|
135
|
+
BEFORE INSERT ON users
|
|
136
|
+
FOR EACH ROW
|
|
137
|
+
EXECUTE FUNCTION uppercase_users_name()
|
|
138
|
+
EOS
|
|
139
|
+
adapter.create_trigger(sql_definition)
|
|
140
|
+
|
|
141
|
+
expect(adapter.triggers.map(&:name)).to eq ["uppercase_users_name"]
|
|
144
142
|
end
|
|
145
143
|
end
|
|
146
144
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Fx::CommandRecorder, :db do
|
|
3
|
+
RSpec.describe Fx::CommandRecorder, :db do
|
|
4
4
|
describe "#create_function" do
|
|
5
5
|
it "records the created function" do
|
|
6
6
|
recorder = ActiveRecord::Migration::CommandRecorder.new
|
|
7
7
|
|
|
8
8
|
recorder.create_function :test
|
|
9
9
|
|
|
10
|
-
expect(recorder.commands).to eq
|
|
10
|
+
expect(recorder.commands).to eq([[:create_function, [:test], nil]])
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "reverts to drop_function" do
|
|
@@ -15,7 +15,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
15
15
|
|
|
16
16
|
recorder.create_function :test
|
|
17
17
|
|
|
18
|
-
expect(recorder.commands).to eq
|
|
18
|
+
expect(recorder.commands).to eq([[:create_function, [:test], nil]])
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "reverts to drop_function" do
|
|
@@ -23,7 +23,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
23
23
|
|
|
24
24
|
recorder.revert { recorder.create_function :test }
|
|
25
25
|
|
|
26
|
-
expect(recorder.commands).to eq
|
|
26
|
+
expect(recorder.commands).to eq([[:drop_function, [:test]]])
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
33
33
|
|
|
34
34
|
recorder.drop_function :test
|
|
35
35
|
|
|
36
|
-
expect(recorder.commands).to eq
|
|
36
|
+
expect(recorder.commands).to eq([[:drop_function, [:test], nil]])
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "reverts to create_function with specified revert_to_version" do
|
|
@@ -43,15 +43,16 @@ describe Fx::CommandRecorder, :db do
|
|
|
43
43
|
|
|
44
44
|
recorder.revert { recorder.drop_function(*args) }
|
|
45
45
|
|
|
46
|
-
expect(recorder.commands).to eq
|
|
46
|
+
expect(recorder.commands).to eq([[:create_function, revert_args]])
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "raises when reverting without revert_to_version set" do
|
|
50
50
|
recorder = ActiveRecord::Migration::CommandRecorder.new
|
|
51
51
|
args = [:test, {another_argument: 1}]
|
|
52
52
|
|
|
53
|
-
expect
|
|
54
|
-
.
|
|
53
|
+
expect do
|
|
54
|
+
recorder.revert { recorder.drop_function(*args) }
|
|
55
|
+
end.to raise_error(ActiveRecord::IrreversibleMigration)
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
58
|
|
|
@@ -62,7 +63,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
62
63
|
|
|
63
64
|
recorder.update_function(*args)
|
|
64
65
|
|
|
65
|
-
expect(recorder.commands).to eq
|
|
66
|
+
expect(recorder.commands).to eq([[:update_function, args, nil]])
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
it "reverts to update_function with the specified revert_to_version" do
|
|
@@ -72,15 +73,16 @@ describe Fx::CommandRecorder, :db do
|
|
|
72
73
|
|
|
73
74
|
recorder.revert { recorder.update_function(*args) }
|
|
74
75
|
|
|
75
|
-
expect(recorder.commands).to eq
|
|
76
|
+
expect(recorder.commands).to eq([[:update_function, revert_args]])
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
it "raises when reverting without revert_to_version set" do
|
|
79
80
|
recorder = ActiveRecord::Migration::CommandRecorder.new
|
|
80
81
|
args = [:test, {version: 42, another_argument: 1}]
|
|
81
82
|
|
|
82
|
-
expect
|
|
83
|
-
.
|
|
83
|
+
expect do
|
|
84
|
+
recorder.revert { recorder.update_function(*args) }
|
|
85
|
+
end.to raise_error(ActiveRecord::IrreversibleMigration)
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
@@ -90,7 +92,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
90
92
|
|
|
91
93
|
recorder.create_trigger :greetings
|
|
92
94
|
|
|
93
|
-
expect(recorder.commands).to eq
|
|
95
|
+
expect(recorder.commands).to eq([[:create_trigger, [:greetings], nil]])
|
|
94
96
|
end
|
|
95
97
|
|
|
96
98
|
it "reverts to drop_trigger" do
|
|
@@ -98,9 +100,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
98
100
|
|
|
99
101
|
recorder.create_trigger :greetings
|
|
100
102
|
|
|
101
|
-
expect(recorder.commands).to eq [
|
|
102
|
-
[:create_trigger, [:greetings], nil]
|
|
103
|
-
]
|
|
103
|
+
expect(recorder.commands).to eq([[:create_trigger, [:greetings], nil]])
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "reverts to drop_trigger" do
|
|
@@ -108,7 +108,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
108
108
|
|
|
109
109
|
recorder.revert { recorder.create_trigger :greetings }
|
|
110
110
|
|
|
111
|
-
expect(recorder.commands).to eq
|
|
111
|
+
expect(recorder.commands).to eq([[:drop_trigger, [:greetings]]])
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
@@ -118,7 +118,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
118
118
|
|
|
119
119
|
recorder.drop_trigger :users
|
|
120
120
|
|
|
121
|
-
expect(recorder.commands).to eq
|
|
121
|
+
expect(recorder.commands).to eq([[:drop_trigger, [:users], nil]])
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "reverts to create_trigger with specified revert_to_version" do
|
|
@@ -128,15 +128,16 @@ describe Fx::CommandRecorder, :db do
|
|
|
128
128
|
|
|
129
129
|
recorder.revert { recorder.drop_trigger(*args) }
|
|
130
130
|
|
|
131
|
-
expect(recorder.commands).to eq
|
|
131
|
+
expect(recorder.commands).to eq([[:create_trigger, revert_args]])
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
it "raises when reverting without revert_to_version set" do
|
|
135
135
|
recorder = ActiveRecord::Migration::CommandRecorder.new
|
|
136
136
|
args = [:users, {another_argument: 1}]
|
|
137
137
|
|
|
138
|
-
expect
|
|
139
|
-
.
|
|
138
|
+
expect do
|
|
139
|
+
recorder.revert { recorder.drop_trigger(*args) }
|
|
140
|
+
end.to raise_error(ActiveRecord::IrreversibleMigration)
|
|
140
141
|
end
|
|
141
142
|
end
|
|
142
143
|
|
|
@@ -147,7 +148,7 @@ describe Fx::CommandRecorder, :db do
|
|
|
147
148
|
|
|
148
149
|
recorder.update_trigger(*args)
|
|
149
150
|
|
|
150
|
-
expect(recorder.commands).to eq
|
|
151
|
+
expect(recorder.commands).to eq([[:update_trigger, args, nil]])
|
|
151
152
|
end
|
|
152
153
|
|
|
153
154
|
it "reverts to update_trigger with the specified revert_to_version" do
|
|
@@ -157,15 +158,16 @@ describe Fx::CommandRecorder, :db do
|
|
|
157
158
|
|
|
158
159
|
recorder.revert { recorder.update_trigger(*args) }
|
|
159
160
|
|
|
160
|
-
expect(recorder.commands).to eq
|
|
161
|
+
expect(recorder.commands).to eq([[:update_trigger, revert_args]])
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
it "raises when reverting without revert_to_version set" do
|
|
164
165
|
recorder = ActiveRecord::Migration::CommandRecorder.new
|
|
165
166
|
args = [:users, {version: 42, another_argument: 1}]
|
|
166
167
|
|
|
167
|
-
expect
|
|
168
|
-
.
|
|
168
|
+
expect do
|
|
169
|
+
recorder.revert { recorder.update_trigger(*args) }
|
|
170
|
+
end.to raise_error(ActiveRecord::IrreversibleMigration)
|
|
169
171
|
end
|
|
170
172
|
end
|
|
171
173
|
end
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Fx::Configuration do
|
|
3
|
+
RSpec.describe Fx::Configuration do
|
|
4
4
|
it "defaults the database adapter to postgres" do
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
configuration = Fx::Configuration.new
|
|
6
|
+
|
|
7
|
+
expect(configuration.database).to be_a(Fx::Adapters::Postgres)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "defaults `dump_functions_at_beginning_of_schema` to false" do
|
|
11
|
+
configuration = Fx::Configuration.new
|
|
12
|
+
|
|
13
|
+
expect(configuration.dump_functions_at_beginning_of_schema).to eq(false)
|
|
7
14
|
end
|
|
8
15
|
|
|
9
16
|
it "allows the database adapter to be set" do
|
|
17
|
+
configuration = Fx::Configuration.new
|
|
10
18
|
adapter = double("Fx Adapter")
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
configuration.database = adapter
|
|
21
|
+
|
|
22
|
+
expect(configuration.database).to eq(adapter)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "allows `dump_functions_at_beginning_of_schema` to be set" do
|
|
26
|
+
configuration = Fx::Configuration.new
|
|
15
27
|
|
|
16
|
-
|
|
17
|
-
expect(Fx.database).to eq adapter
|
|
28
|
+
configuration.dump_functions_at_beginning_of_schema = true
|
|
18
29
|
|
|
19
|
-
|
|
30
|
+
expect(configuration.dump_functions_at_beginning_of_schema).to eq(true)
|
|
20
31
|
end
|
|
21
32
|
end
|