• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sleede / fab-manager / #106

pending completion
#106

push

coveralls-ruby

sylvainbx
Merge branch 'dev' for release 6.0.0

704 of 704 new or added lines in 168 files covered. (100.0%)

7919 of 13474 relevant lines covered (58.77%)

15.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.05
/lib/tasks/db.rake
1
# frozen_string_literal: false
2

3
namespace :db do
1✔
4
  # Usage example:
5
  #     RAILS_ENV=test rails db:to_fixtures[chained_elements]
6
  desc 'Convert development DB to Rails test fixtures'
1✔
7
  task :to_fixtures, [:table] => :environment do |_task, args|
1✔
8
    tables_to_skip = %w[ar_internal_metadata delayed_jobs schema_info schema_migrations].freeze
×
9

10
    begin
11
      ActiveRecord::Base.establish_connection
×
12
      ActiveRecord::Base.connection.tables.each do |table_name|
×
13
        next if tables_to_skip.include?(table_name)
×
14
        next if args.table && args.table != table_name
×
15

16
        counter = '000'
×
17
        file_path = Rails.root.join("test/fixtures/#{table_name}.yml")
×
18
        File.open(file_path, File::WRONLY | File::CREAT) do |file|
×
19
          rows = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}")
×
20
          data = rows.each_with_object({}) do |record, hash|
×
21
            suffix = record['id'].presence || counter.succ!
×
22
            # FIXME, this is broken with jsonb columns: it records a String but a Hash must be saved
23
            hash["#{table_name.singularize}#{suffix}"] = yamlize(record, rows.column_types)
×
24
          end
25
          puts "Writing table '#{table_name}' to '#{file_path}'"
×
26
          file.write(data.to_yaml)
×
27
        end
28
      end
29
    ensure
30
      ActiveRecord::Base.connection&.close
×
31
    end
32
  end
33

34
  def yamlize(record, column_types)
1✔
35
    record.each_with_object({}) do |(key, value), hash|
×
36
      hash[key] = column_types.include?(key) && column_types[key].type == :jsonb ? JSON.parse(value) : value
×
37
    end
38
  end
39
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc