fx 0.7.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 +53 -0
- data/.gitignore +0 -1
- data/.rspec +1 -1
- data/.standard.yml +3 -0
- data/CHANGELOG.md +124 -0
- data/CONTRIBUTING.md +13 -4
- data/Gemfile +13 -2
- data/README.md +4 -2
- data/Rakefile +2 -1
- data/bin/setup +0 -4
- data/bin/standardrb +27 -0
- data/fx.gemspec +20 -27
- 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 +7 -7
- 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 +8 -8
- data/lib/generators/fx/trigger/trigger_generator.rb +6 -10
- data/spec/acceptance/user_manages_functions_spec.rb +5 -5
- data/spec/acceptance/user_manages_triggers_spec.rb +8 -8
- data/spec/acceptance_helper.rb +6 -4
- data/spec/dummy/Rakefile +4 -4
- data/spec/dummy/bin/bundle +2 -2
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/config/application.rb +6 -0
- data/spec/dummy/config/database.yml +2 -0
- data/spec/dummy/config.ru +1 -1
- data/spec/features/functions/migrations_spec.rb +4 -4
- data/spec/features/functions/revert_spec.rb +7 -7
- data/spec/features/triggers/migrations_spec.rb +6 -6
- data/spec/features/triggers/revert_spec.rb +13 -13
- 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 +41 -39
- data/spec/fx/configuration_spec.rb +20 -9
- data/spec/fx/definition_spec.rb +30 -38
- 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 +6 -6
- data/spec/generators/fx/trigger/trigger_generator_spec.rb +10 -10
- data/spec/spec_helper.rb +5 -0
- data/spec/support/definition_helpers.rb +5 -9
- data/spec/support/generator_setup.rb +1 -1
- data/spec/support/migration_helpers.rb +1 -1
- data/spec/support/warning_helper.rb +5 -0
- metadata +24 -213
- data/.hound.yml +0 -2
- data/.rubocop.yml +0 -648
- data/.travis.yml +0 -60
- data/Appraisals +0 -45
- data/bin/appraisal +0 -17
- data/gemfiles/rails42.gemfile +0 -10
- data/gemfiles/rails50.gemfile +0 -8
- data/gemfiles/rails51.gemfile +0 -8
- data/gemfiles/rails52.gemfile +0 -8
- data/gemfiles/rails60.gemfile +0 -8
- data/gemfiles/rails61.gemfile +0 -8
- data/gemfiles/rails_edge.gemfile +0 -8
- 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 -115
- data/lib/fx/statements/trigger.rb +0 -146
- data/spec/fx/command_recorder/arguments_spec.rb +0 -41
- data/spec/fx/schema_dumper/function_spec.rb +0 -80
- 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,40 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Fx::SchemaDumper::Trigger, :db do
|
4
|
-
it "dumps a create_trigger for a trigger in the database" do
|
5
|
-
connection.execute <<-EOS
|
6
|
-
CREATE TABLE users (
|
7
|
-
id int PRIMARY KEY,
|
8
|
-
name varchar(256),
|
9
|
-
upper_name varchar(256)
|
10
|
-
);
|
11
|
-
EOS
|
12
|
-
Fx.database.create_function <<-EOS
|
13
|
-
CREATE OR REPLACE FUNCTION uppercase_users_name()
|
14
|
-
RETURNS trigger AS $$
|
15
|
-
BEGIN
|
16
|
-
NEW.upper_name = UPPER(NEW.name);
|
17
|
-
RETURN NEW;
|
18
|
-
END;
|
19
|
-
$$ LANGUAGE plpgsql;
|
20
|
-
EOS
|
21
|
-
sql_definition = <<-EOS
|
22
|
-
CREATE TRIGGER uppercase_users_name
|
23
|
-
BEFORE INSERT ON users
|
24
|
-
FOR EACH ROW
|
25
|
-
EXECUTE PROCEDURE uppercase_users_name();
|
26
|
-
EOS
|
27
|
-
connection.create_trigger(
|
28
|
-
:uppercase_users_name,
|
29
|
-
sql_definition: sql_definition,
|
30
|
-
)
|
31
|
-
stream = StringIO.new
|
32
|
-
|
33
|
-
ActiveRecord::SchemaDumper.dump(connection, stream)
|
34
|
-
|
35
|
-
output = stream.string
|
36
|
-
expect(output).to include "create_trigger :uppercase_users_name"
|
37
|
-
expect(output).to include "sql_definition: <<-SQL"
|
38
|
-
expect(output).to include "EXECUTE PROCEDURE uppercase_users_name()"
|
39
|
-
end
|
40
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "fx/statements/function"
|
3
|
-
|
4
|
-
describe Fx::Statements::Function, :db do
|
5
|
-
describe "#create_function" do
|
6
|
-
it "creates a function from a file" do
|
7
|
-
database = stubbed_database
|
8
|
-
definition = stubbed_definition
|
9
|
-
|
10
|
-
connection.create_function(:test)
|
11
|
-
|
12
|
-
expect(database).to have_received(:create_function).
|
13
|
-
with(definition.to_sql)
|
14
|
-
expect(Fx::Definition).to have_received(:new).
|
15
|
-
with(name: :test, version: 1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "allows creating a function with a specific version" do
|
19
|
-
database = stubbed_database
|
20
|
-
definition = stubbed_definition
|
21
|
-
|
22
|
-
connection.create_function(:test, version: 2)
|
23
|
-
|
24
|
-
expect(database).to have_received(:create_function).
|
25
|
-
with(definition.to_sql)
|
26
|
-
expect(Fx::Definition).to have_received(:new).
|
27
|
-
with(name: :test, version: 2)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "raises an error if both arguments are nil" do
|
31
|
-
expect {
|
32
|
-
connection.create_function(
|
33
|
-
:whatever,
|
34
|
-
version: nil,
|
35
|
-
sql_definition: nil,
|
36
|
-
)
|
37
|
-
}.to raise_error(
|
38
|
-
ArgumentError,
|
39
|
-
/version or sql_definition must be specified/,
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#drop_function" do
|
45
|
-
it "drops the function" do
|
46
|
-
database = stubbed_database
|
47
|
-
|
48
|
-
connection.drop_function(:test)
|
49
|
-
|
50
|
-
expect(database).to have_received(:drop_function).with(:test)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#update_function" do
|
55
|
-
it "updates the function" do
|
56
|
-
database = stubbed_database
|
57
|
-
definition = stubbed_definition
|
58
|
-
|
59
|
-
connection.update_function(:test, version: 3)
|
60
|
-
|
61
|
-
expect(database).to have_received(:update_function).
|
62
|
-
with(:test, definition.to_sql)
|
63
|
-
expect(Fx::Definition).to have_received(:new).
|
64
|
-
with(name: :test, version: 3)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "updates a function from a text definition" do
|
68
|
-
database = stubbed_database
|
69
|
-
|
70
|
-
connection.update_function(:test, sql_definition: "a definition")
|
71
|
-
|
72
|
-
expect(database).to have_received(:update_function).with(
|
73
|
-
:test,
|
74
|
-
"a definition",
|
75
|
-
)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "raises an error if not supplied a version" do
|
79
|
-
expect {
|
80
|
-
connection.update_function(
|
81
|
-
:whatever,
|
82
|
-
version: nil,
|
83
|
-
sql_definition: nil,
|
84
|
-
)
|
85
|
-
}.to raise_error(
|
86
|
-
ArgumentError,
|
87
|
-
/version or sql_definition must be specified/,
|
88
|
-
)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def stubbed_database
|
93
|
-
instance_spy("StubbedDatabase").tap do |stubbed_database|
|
94
|
-
allow(Fx).to receive(:database).and_return(stubbed_database)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def stubbed_definition
|
99
|
-
instance_double("Fx::Definition", to_sql: nil).tap do |stubbed_definition|
|
100
|
-
allow(Fx::Definition).to receive(:new).and_return(stubbed_definition)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "fx/statements/trigger"
|
3
|
-
|
4
|
-
describe Fx::Statements::Trigger, :db do
|
5
|
-
describe "#create_trigger" do
|
6
|
-
it "creates a trigger from a file" do
|
7
|
-
database = stubbed_database
|
8
|
-
definition = stubbed_definition
|
9
|
-
|
10
|
-
connection.create_trigger(:test)
|
11
|
-
|
12
|
-
expect(database).to have_received(:create_trigger).
|
13
|
-
with(definition.to_sql)
|
14
|
-
expect(Fx::Definition).to have_received(:new).
|
15
|
-
with(name: :test, version: 1, type: "trigger")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "allows creating a trigger with a specific version" do
|
19
|
-
database = stubbed_database
|
20
|
-
definition = stubbed_definition
|
21
|
-
|
22
|
-
connection.create_trigger(:test, version: 2)
|
23
|
-
|
24
|
-
expect(database).to have_received(:create_trigger).
|
25
|
-
with(definition.to_sql)
|
26
|
-
expect(Fx::Definition).to have_received(:new).
|
27
|
-
with(name: :test, version: 2, type: "trigger")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "raises an error if both arguments are set" do
|
31
|
-
stubbed_database
|
32
|
-
|
33
|
-
expect {
|
34
|
-
connection.create_trigger(
|
35
|
-
:whatever,
|
36
|
-
version: 1,
|
37
|
-
sql_definition: "a definition",
|
38
|
-
)
|
39
|
-
}.to raise_error(
|
40
|
-
ArgumentError,
|
41
|
-
/cannot both be set/,
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#drop_trigger" do
|
47
|
-
it "drops the trigger" do
|
48
|
-
database = stubbed_database
|
49
|
-
|
50
|
-
connection.drop_trigger(:test, on: :users)
|
51
|
-
|
52
|
-
expect(database).to have_received(:drop_trigger).
|
53
|
-
with(:test, on: :users)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#update_trigger" do
|
58
|
-
it "updates the trigger" do
|
59
|
-
database = stubbed_database
|
60
|
-
definition = stubbed_definition
|
61
|
-
|
62
|
-
connection.update_trigger(:test, on: :users, version: 3)
|
63
|
-
|
64
|
-
expect(database).to have_received(:update_trigger).with(
|
65
|
-
:test,
|
66
|
-
on: :users,
|
67
|
-
sql_definition: definition.to_sql,
|
68
|
-
)
|
69
|
-
expect(Fx::Definition).to have_received(:new).with(
|
70
|
-
name: :test,
|
71
|
-
version: 3,
|
72
|
-
type: "trigger",
|
73
|
-
)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "updates a trigger from a text definition" do
|
77
|
-
database = stubbed_database
|
78
|
-
|
79
|
-
connection.update_trigger(
|
80
|
-
:test,
|
81
|
-
on: :users,
|
82
|
-
sql_definition: "a definition",
|
83
|
-
)
|
84
|
-
|
85
|
-
expect(database).to have_received(:update_trigger).with(
|
86
|
-
:test,
|
87
|
-
on: :users,
|
88
|
-
sql_definition: "a definition",
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "raises an error if not supplied a version" do
|
93
|
-
expect {
|
94
|
-
connection.update_trigger(
|
95
|
-
:whatever,
|
96
|
-
version: nil,
|
97
|
-
sql_definition: nil,
|
98
|
-
)
|
99
|
-
}.to raise_error(
|
100
|
-
ArgumentError,
|
101
|
-
/version or sql_definition must be specified/,
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "raises an error if both arguments are set" do
|
106
|
-
stubbed_database
|
107
|
-
|
108
|
-
expect {
|
109
|
-
connection.update_trigger(
|
110
|
-
:whatever,
|
111
|
-
version: 1,
|
112
|
-
sql_definition: "a definition",
|
113
|
-
)
|
114
|
-
}.to raise_error(
|
115
|
-
ArgumentError,
|
116
|
-
/cannot both be set/,
|
117
|
-
)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def stubbed_database
|
122
|
-
instance_spy("StubbedDatabase").tap do |stubbed_database|
|
123
|
-
allow(Fx).to receive(:database).and_return(stubbed_database)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def stubbed_definition
|
128
|
-
instance_double("Fx::Definition", to_sql: nil).tap do |stubbed_definition|
|
129
|
-
allow(Fx::Definition).to receive(:new).and_return(stubbed_definition)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|