aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/test/cases/connection_specification/resolver_test.rb
blob: 434d2b7ba5cfd23c7d52f1373d71b27baea5ddc2 (plain) (tree)
1
2
3
4
5
6
7
8


                      
                           


                                                 
                                            


                               
                                                                         
                                                    
                        
                                 




                                        
                                                                         
                                                        
                        
                                 





                                        
                                                                         
                                                        
                        
                                 







                                        
require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class ConnectionSpecification
      class ResolverTest < ActiveRecord::TestCase
        def resolve(spec)
          Resolver.new(spec, {}).spec.config
        end

        def test_url_host_no_db
          skip "only if mysql is available" unless defined?(MysqlAdapter)
          spec = resolve 'mysql://foo?encoding=utf8'
          assert_equal({
            :adapter  => "mysql",
            :host     => "foo",
            :encoding => "utf8" }, spec)
        end

        def test_url_host_db
          skip "only if mysql is available" unless defined?(MysqlAdapter)
          spec = resolve 'mysql://foo/bar?encoding=utf8'
          assert_equal({
            :adapter  => "mysql",
            :database => "bar",
            :host     => "foo",
            :encoding => "utf8" }, spec)
        end

        def test_url_port
          skip "only if mysql is available" unless defined?(MysqlAdapter)
          spec = resolve 'mysql://foo:123?encoding=utf8'
          assert_equal({
            :adapter  => "mysql",
            :port     => 123,
            :host     => "foo",
            :encoding => "utf8" }, spec)
        end
      end
    end
  end
end