Class: Rdt::Runner
- Inherits:
-
Object
- Object
- Rdt::Runner
- Defined in:
- lib/rdt/runner.rb
Class Method Summary collapse
- .check_if_all_refs_have_sql_files(dependencies) ⇒ Object
- .run(custom_schema = nil, glob_path = "app/sql/**/*.sql") ⇒ Object
- .test ⇒ Object
Class Method Details
.check_if_all_refs_have_sql_files(dependencies) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rdt/runner.rb', line 31 def check_if_all_refs_have_sql_files(dependencies) dependencies.each do |key, value| sem_arquivo = (value || []) - dependencies.keys unless sem_arquivo.empty? raise "Missing .sql model files for ref #{sem_arquivo} in model #{key}" end end end |
.run(custom_schema = nil, glob_path = "app/sql/**/*.sql") ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rdt/runner.rb', line 4 def run(custom_schema = nil, glob_path = "app/sql/**/*.sql") schema = custom_schema || Rdt.settings["schema"] || Rdt::SCHEMA ActiveRecord::Base.connection.execute "CREATE SCHEMA IF NOT EXISTS #{schema}" file_paths = Dir.glob(glob_path) models = file_paths.map { |fp| Model.new(fp, schema) } dependencies = models.map { |m| { m.name => m.refs } }.reduce({}, :merge!) check_if_all_refs_have_sql_files dependencies graph = Dagwood::DependencyGraph.new dependencies md = Mermaid.markdown_for dependencies Mermaid.generate_file md graph.order.each do |model_name| models.find { |m| m.name == model_name }.build end end |
.test ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rdt/runner.rb', line 20 def test puts "Running tests..." schema = Rdt.settings["schema"] || Rdt::SCHEMA tables = run(schema, "app/sql_test/**/*.sql") tables.each do |table| puts "TEST #{table}" raise "Table #{table} is not empty" unless ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM #{schema}.#{table}").to_a[0]["count"] == 0 end puts "All tests passed!" end |