squcumber-postgres 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/squcumber-postgres/mock/database.rb +24 -3
 - data/spec/squcumber-postgres/mock/database_spec.rb +133 -0
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c74c69c04c7b06dc21cf98c9fc940036cd29fe30034295ea81e7dbf11af2a33b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: edef6b6fb8b544916e05bbfa97d2057f6b5540234a38662304f73090f22e4a88
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5c54f1a70bc5f7d949e58686dedf27586372d353e8c032f99ddef7bb1f06c8cbff9cf0380cb78d06be75f693dc3ba97b540a73246d2f2d5970df7a39a015998f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: bfeddaac3fc25e521fedc2eb3560843b7942c0dc1730a9782230f827c9d975678b91e8a30ac64716c95785428987e772849767106670e4a8a56b87a43b36d223
         
     | 
| 
         @@ -117,10 +117,31 @@ module Squcumber 
     | 
|
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                    def _get_column_definitions(table_definition)
         
     | 
| 
       119 
119 
     | 
    
         
             
                      table_definition.map do |definition|
         
     | 
| 
       120 
     | 
    
         
            -
                         
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
                        schema_column_type = ''
         
     | 
| 
      
 121 
     | 
    
         
            +
                        is_array = false
         
     | 
| 
      
 122 
     | 
    
         
            +
                        if definition['data_type'].eql?('ARRAY')
         
     | 
| 
      
 123 
     | 
    
         
            +
                            is_array = true
         
     | 
| 
      
 124 
     | 
    
         
            +
                            schema_column_type = definition['udt_name'].gsub(/^\_/, '')
         
     | 
| 
      
 125 
     | 
    
         
            +
                        else
         
     | 
| 
      
 126 
     | 
    
         
            +
                            schema_column_type = definition['data_type']
         
     | 
| 
       122 
127 
     | 
    
         
             
                        end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                        # Deal with (var)chars
         
     | 
| 
      
 130 
     | 
    
         
            +
                        if definition['character_maximum_length']
         
     | 
| 
      
 131 
     | 
    
         
            +
                            schema_column_type = schema_column_type + "(#{definition['character_maximum_length'].to_s})"
         
     | 
| 
      
 132 
     | 
    
         
            +
                        end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                        # Deal with decimals
         
     | 
| 
      
 135 
     | 
    
         
            +
                        if definition['udt_name'].eql?('numeric') and definition['numeric_precision'] and definition['numeric_scale']
         
     | 
| 
      
 136 
     | 
    
         
            +
                            schema_column_type = schema_column_type + "(#{definition['numeric_precision'].to_s},#{definition['numeric_scale'].to_s})"
         
     | 
| 
      
 137 
     | 
    
         
            +
                        end
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                        # Deal with arrays
         
     | 
| 
      
 140 
     | 
    
         
            +
                        if is_array
         
     | 
| 
      
 141 
     | 
    
         
            +
                            schema_column_type = schema_column_type + '[]'
         
     | 
| 
      
 142 
     | 
    
         
            +
                        end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                        "#{definition['column_name']} #{schema_column_type} default null"
         
     | 
| 
       124 
145 
     | 
    
         
             
                      end
         
     | 
| 
       125 
146 
     | 
    
         
             
                    end
         
     | 
| 
       126 
147 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -335,6 +335,139 @@ module Squcumber::Postgres::Mock 
     | 
|
| 
       335 
335 
     | 
    
         
             
                  end
         
     | 
| 
       336 
336 
     | 
    
         
             
                end
         
     | 
| 
       337 
337 
     | 
    
         | 
| 
      
 338 
     | 
    
         
            +
                describe '#_get_column_definitions' do
         
     | 
| 
      
 339 
     | 
    
         
            +
                  let(:column_definition_integer) do
         
     | 
| 
      
 340 
     | 
    
         
            +
                    {
         
     | 
| 
      
 341 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 342 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 343 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 344 
     | 
    
         
            +
                      'udt_name' => 'int4',
         
     | 
| 
      
 345 
     | 
    
         
            +
                      'data_type' => 'integer',
         
     | 
| 
      
 346 
     | 
    
         
            +
                      'character_maximum_length' => nil,
         
     | 
| 
      
 347 
     | 
    
         
            +
                      'numeric_precision' => 32,
         
     | 
| 
      
 348 
     | 
    
         
            +
                      'numeric_scale' => 0
         
     | 
| 
      
 349 
     | 
    
         
            +
                    }
         
     | 
| 
      
 350 
     | 
    
         
            +
                  end
         
     | 
| 
      
 351 
     | 
    
         
            +
                  let(:column_definition_varchar) do
         
     | 
| 
      
 352 
     | 
    
         
            +
                    {
         
     | 
| 
      
 353 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 354 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 355 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 356 
     | 
    
         
            +
                      'udt_name' => 'varchar',
         
     | 
| 
      
 357 
     | 
    
         
            +
                      'data_type' => 'character varying',
         
     | 
| 
      
 358 
     | 
    
         
            +
                      'character_maximum_length' => 255,
         
     | 
| 
      
 359 
     | 
    
         
            +
                      'numeric_precision' => nil,
         
     | 
| 
      
 360 
     | 
    
         
            +
                      'numeric_scale' => nil
         
     | 
| 
      
 361 
     | 
    
         
            +
                    }
         
     | 
| 
      
 362 
     | 
    
         
            +
                  end
         
     | 
| 
      
 363 
     | 
    
         
            +
                  let(:column_definition_varchar_array) do
         
     | 
| 
      
 364 
     | 
    
         
            +
                    {
         
     | 
| 
      
 365 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 366 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 367 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 368 
     | 
    
         
            +
                      'udt_name' => '_varchar',
         
     | 
| 
      
 369 
     | 
    
         
            +
                      'data_type' => 'ARRAY',
         
     | 
| 
      
 370 
     | 
    
         
            +
                      'character_maximum_length' => nil,
         
     | 
| 
      
 371 
     | 
    
         
            +
                      'numeric_precision' => nil,
         
     | 
| 
      
 372 
     | 
    
         
            +
                      'numeric_scale' => nil
         
     | 
| 
      
 373 
     | 
    
         
            +
                    }
         
     | 
| 
      
 374 
     | 
    
         
            +
                  end
         
     | 
| 
      
 375 
     | 
    
         
            +
                  let(:column_definition_char) do
         
     | 
| 
      
 376 
     | 
    
         
            +
                    {
         
     | 
| 
      
 377 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 378 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 379 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 380 
     | 
    
         
            +
                      'udt_name' => '_bpchar',
         
     | 
| 
      
 381 
     | 
    
         
            +
                      'data_type' => 'character',
         
     | 
| 
      
 382 
     | 
    
         
            +
                      'character_maximum_length' => 50,
         
     | 
| 
      
 383 
     | 
    
         
            +
                      'numeric_precision' => nil,
         
     | 
| 
      
 384 
     | 
    
         
            +
                      'numeric_scale' => nil
         
     | 
| 
      
 385 
     | 
    
         
            +
                    }
         
     | 
| 
      
 386 
     | 
    
         
            +
                  end
         
     | 
| 
      
 387 
     | 
    
         
            +
                  let(:column_definition_jsonb) do
         
     | 
| 
      
 388 
     | 
    
         
            +
                    {
         
     | 
| 
      
 389 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 390 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 391 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 392 
     | 
    
         
            +
                      'udt_name' => 'jsonb',
         
     | 
| 
      
 393 
     | 
    
         
            +
                      'data_type' => 'jsonb',
         
     | 
| 
      
 394 
     | 
    
         
            +
                      'character_maximum_length' => nil,
         
     | 
| 
      
 395 
     | 
    
         
            +
                      'numeric_precision' => nil,
         
     | 
| 
      
 396 
     | 
    
         
            +
                      'numeric_scale' => nil
         
     | 
| 
      
 397 
     | 
    
         
            +
                    }
         
     | 
| 
      
 398 
     | 
    
         
            +
                  end
         
     | 
| 
      
 399 
     | 
    
         
            +
                  let(:column_definition_timestamp) do
         
     | 
| 
      
 400 
     | 
    
         
            +
                    {
         
     | 
| 
      
 401 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 402 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 403 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 404 
     | 
    
         
            +
                      'udt_name' => 'timestamp',
         
     | 
| 
      
 405 
     | 
    
         
            +
                      'data_type' => 'timestamp without time zone',
         
     | 
| 
      
 406 
     | 
    
         
            +
                      'character_maximum_length' => nil,
         
     | 
| 
      
 407 
     | 
    
         
            +
                      'numeric_precision' => nil,
         
     | 
| 
      
 408 
     | 
    
         
            +
                      'numeric_scale' => nil
         
     | 
| 
      
 409 
     | 
    
         
            +
                    }
         
     | 
| 
      
 410 
     | 
    
         
            +
                  end
         
     | 
| 
      
 411 
     | 
    
         
            +
                  let(:column_definition_numeric) do
         
     | 
| 
      
 412 
     | 
    
         
            +
                    {
         
     | 
| 
      
 413 
     | 
    
         
            +
                      'table_schema' => 'some_schema',
         
     | 
| 
      
 414 
     | 
    
         
            +
                      'table_name' => 'some_table',
         
     | 
| 
      
 415 
     | 
    
         
            +
                      'column_name' => 'some_column',
         
     | 
| 
      
 416 
     | 
    
         
            +
                      'udt_name' => 'numeric',
         
     | 
| 
      
 417 
     | 
    
         
            +
                      'data_type' => 'numeric',
         
     | 
| 
      
 418 
     | 
    
         
            +
                      'character_maximum_length' => nil,
         
     | 
| 
      
 419 
     | 
    
         
            +
                      'numeric_precision' => 6,
         
     | 
| 
      
 420 
     | 
    
         
            +
                      'numeric_scale' => 2
         
     | 
| 
      
 421 
     | 
    
         
            +
                    }
         
     | 
| 
      
 422 
     | 
    
         
            +
                  end
         
     | 
| 
      
 423 
     | 
    
         
            +
             
     | 
| 
      
 424 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 425 
     | 
    
         
            +
                    @dummy = described_class.new(production_database)
         
     | 
| 
      
 426 
     | 
    
         
            +
                  end
         
     | 
| 
      
 427 
     | 
    
         
            +
             
     | 
| 
      
 428 
     | 
    
         
            +
                  it 'parses integer columns correctly' do
         
     | 
| 
      
 429 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_integer])).to match([
         
     | 
| 
      
 430 
     | 
    
         
            +
                      'some_column integer default null'
         
     | 
| 
      
 431 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 432 
     | 
    
         
            +
                  end
         
     | 
| 
      
 433 
     | 
    
         
            +
             
     | 
| 
      
 434 
     | 
    
         
            +
                  it 'parses varchar columns correctly' do
         
     | 
| 
      
 435 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_varchar])).to match([
         
     | 
| 
      
 436 
     | 
    
         
            +
                      'some_column character varying(255) default null'
         
     | 
| 
      
 437 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 438 
     | 
    
         
            +
                  end
         
     | 
| 
      
 439 
     | 
    
         
            +
             
     | 
| 
      
 440 
     | 
    
         
            +
                  it 'parses array varchar columns correctly' do
         
     | 
| 
      
 441 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_varchar_array])).to match([
         
     | 
| 
      
 442 
     | 
    
         
            +
                      'some_column varchar[] default null'
         
     | 
| 
      
 443 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 444 
     | 
    
         
            +
                  end
         
     | 
| 
      
 445 
     | 
    
         
            +
             
     | 
| 
      
 446 
     | 
    
         
            +
                  it 'parses char columns correctly' do
         
     | 
| 
      
 447 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_char])).to match([
         
     | 
| 
      
 448 
     | 
    
         
            +
                      'some_column character(50) default null'
         
     | 
| 
      
 449 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 450 
     | 
    
         
            +
                  end
         
     | 
| 
      
 451 
     | 
    
         
            +
             
     | 
| 
      
 452 
     | 
    
         
            +
                  it 'parses jsonb columns correctly' do
         
     | 
| 
      
 453 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_jsonb])).to match([
         
     | 
| 
      
 454 
     | 
    
         
            +
                      'some_column jsonb default null'
         
     | 
| 
      
 455 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 456 
     | 
    
         
            +
                  end
         
     | 
| 
      
 457 
     | 
    
         
            +
             
     | 
| 
      
 458 
     | 
    
         
            +
                  it 'parses timestamp columns correctly' do
         
     | 
| 
      
 459 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_timestamp])).to match([
         
     | 
| 
      
 460 
     | 
    
         
            +
                      'some_column timestamp without time zone default null'
         
     | 
| 
      
 461 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 462 
     | 
    
         
            +
                  end
         
     | 
| 
      
 463 
     | 
    
         
            +
             
     | 
| 
      
 464 
     | 
    
         
            +
                  it 'parses numeric columns correctly' do
         
     | 
| 
      
 465 
     | 
    
         
            +
                    expect(@dummy.send(:_get_column_definitions, [column_definition_numeric])).to match([
         
     | 
| 
      
 466 
     | 
    
         
            +
                      'some_column numeric(6,2) default null'
         
     | 
| 
      
 467 
     | 
    
         
            +
                    ])
         
     | 
| 
      
 468 
     | 
    
         
            +
                  end
         
     | 
| 
      
 469 
     | 
    
         
            +
                end
         
     | 
| 
      
 470 
     | 
    
         
            +
             
     | 
| 
       338 
471 
     | 
    
         
             
                describe '#_get_create_table_statement' do
         
     | 
| 
       339 
472 
     | 
    
         
             
                  let(:schema) { 'some_schema' }
         
     | 
| 
       340 
473 
     | 
    
         
             
                  let(:table) { 'some_table' }
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: squcumber-postgres
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Stefanie Grunwald
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-09-05 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: pg
         
     |