aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/connection_specification/resolver_test.rb
blob: 52de0efe7fcfb4e6a5233071b434ba852ee4d30c (plain) (blame)
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
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 current_adapter?(:MysqlAdapter, :Mysql2Adapter)
          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 current_adapter?(:MysqlAdapter, :Mysql2Adapter)
          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 current_adapter?(:MysqlAdapter, :Mysql2Adapter)
          spec = resolve 'mysql://foo:123?encoding=utf8'
          assert_equal({
            :adapter  => "mysql",
            :port     => 123,
            :host     => "foo",
            :encoding => "utf8" }, spec)
        end

        def test_encoded_password
          skip "only if mysql is available" unless current_adapter?(:MysqlAdapter, :Mysql2Adapter)
          password = 'am@z1ng_p@ssw0rd#!'
          encoded_password = URI.encode_www_form_component(password)
          spec = resolve "mysql://foo:#{encoded_password}@localhost/bar"
          assert_equal password, spec[:password]
        end
      end
    end
  end
end