File: multi_db_rake_test.rb

package info (click to toggle)
rails 2%3A7.2.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,348 kB
  • sloc: ruby: 349,797; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (60 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (2)
1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require "isolation/abstract_unit"
require "env_helpers"

module ApplicationTests
  class MultiDbRakeTest < ActiveSupport::TestCase
    include ActiveSupport::Testing::Isolation, EnvHelpers

    def setup
      build_app(multi_db: true)
      @output = rails("generate", "scaffold", "Pet", "name:string", "--database=animals")
    end

    def teardown
      teardown_app
    end

    def test_generate_scaffold_creates_abstract_model
      assert_match %r{app/models/pet\.rb}, @output
      assert_match %r{app/models/animals_record\.rb}, @output
    end

    def test_destroy_scaffold_doesnt_remove_abstract_model
      output = rails("destroy", "scaffold", "Pet", "--database=animals")

      assert_match %r{app/models/pet\.rb}, output
      assert_no_match %r{app/models/animals_record\.rb}, output
    end

    def test_creates_a_directory_for_migrations
      assert_match %r{db/animals_migrate/}, @output
    end

    def test_migrations_paths_takes_first
      app_file "config/database.yml", <<-YAML
        default: &default
          adapter: sqlite3
          pool: 5
          timeout: 5000
          variables:
            statement_timeout: 1000
        development:
          primary:
            <<: *default
            database: storage/development.sqlite3
          animals:
            <<: *default
            database: storage/development_animals.sqlite3
            migrations_paths:
              - db/animals_migrate
              - db/common
      YAML

      output = rails("generate", "scaffold", "Dog", "name:string", "--database=animals")
      assert_match %r{db/animals_migrate/}, output
      assert_no_match %r{db/common/}, output
    end
  end
end