linkage 0.0.1 → 0.0.2
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.
- data/Gemfile +3 -2
- data/Gemfile.lock +25 -17
- data/Guardfile +2 -3
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/linkage/configuration.rb +55 -15
- data/lib/linkage/data.rb +171 -0
- data/lib/linkage/dataset.rb +16 -16
- data/lib/linkage/expectation.rb +6 -6
- data/lib/linkage/field.rb +5 -144
- data/lib/linkage/function.rb +108 -0
- data/lib/linkage/functions/trim.rb +22 -0
- data/lib/linkage/warnings.rb +5 -0
- data/lib/linkage.rb +3 -0
- data/linkage.gemspec +24 -4
- data/test/config.yml +5 -0
- data/test/helper.rb +27 -2
- data/test/integration/test_dual_linkage.rb +33 -0
- data/test/integration/test_self_linkage.rb +21 -0
- data/test/unit/functions/test_trim.rb +36 -0
- data/test/unit/test_configuration.rb +42 -6
- data/test/unit/test_data.rb +456 -0
- data/test/unit/test_dataset.rb +85 -22
- data/test/unit/test_expectation.rb +97 -1
- data/test/unit/test_field.rb +15 -411
- data/test/unit/test_function.rb +190 -0
- metadata +58 -39
- /data/test/unit/{test_single_threaded_runner.rb → runner/test_single_threaded.rb} +0 -0
| @@ -20,6 +20,28 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 20 20 | 
             
                assert_equal :dual, exp.kind
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 | 
            +
              test "kind when one field and one function from different datasets" do
         | 
| 24 | 
            +
                dataset_1 = mock('dataset 1')
         | 
| 25 | 
            +
                dataset_2 = mock('dataset 2')
         | 
| 26 | 
            +
                field = stub_field('field', :dataset => dataset_1)
         | 
| 27 | 
            +
                func = stub_function('function', :dataset => dataset_2, :static? => false)
         | 
| 28 | 
            +
                field.expects(:==).with(func).returns(false)
         | 
| 29 | 
            +
                dataset_1.expects(:==).with(dataset_2).returns(false)
         | 
| 30 | 
            +
                exp = Linkage::MustExpectation.new(:==, field, func)
         | 
| 31 | 
            +
                assert_equal :dual, exp.kind
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              test "kind when two functions from different datasets" do
         | 
| 35 | 
            +
                dataset_1 = mock('dataset 1')
         | 
| 36 | 
            +
                dataset_2 = mock('dataset 2')
         | 
| 37 | 
            +
                func_1 = stub_function('function 1', :dataset => dataset_1, :static? => false)
         | 
| 38 | 
            +
                func_2 = stub_function('function 2', :dataset => dataset_2, :static? => false)
         | 
| 39 | 
            +
                func_1.expects(:==).with(func_2).returns(false)
         | 
| 40 | 
            +
                dataset_1.expects(:==).with(dataset_2).returns(false)
         | 
| 41 | 
            +
                exp = Linkage::MustExpectation.new(:==, func_1, func_2)
         | 
| 42 | 
            +
                assert_equal :dual, exp.kind
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 23 45 | 
             
              test "kind when two identical fields from the same dataset" do
         | 
| 24 46 | 
             
                field_1 = stub_field('field 1')
         | 
| 25 47 | 
             
                field_2 = stub_field('field 2')
         | 
| @@ -28,6 +50,14 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 28 50 | 
             
                assert_equal :self, exp.kind
         | 
| 29 51 | 
             
              end
         | 
| 30 52 |  | 
| 53 | 
            +
              test "kind when two identical functions from the same dataset" do
         | 
| 54 | 
            +
                func_1 = stub_function('function 1')
         | 
| 55 | 
            +
                func_2 = stub_function('function 2')
         | 
| 56 | 
            +
                func_1.expects(:==).with(func_2).returns(true)
         | 
| 57 | 
            +
                exp = Linkage::MustExpectation.new(:==, func_1, func_2)
         | 
| 58 | 
            +
                assert_equal :self, exp.kind
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 31 61 | 
             
              test "kind when two different fields from the same dataset" do
         | 
| 32 62 | 
             
                dataset_1 = mock('dataset 1')
         | 
| 33 63 | 
             
                dataset_2 = mock('dataset 2')
         | 
| @@ -39,6 +69,17 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 39 69 | 
             
                assert_equal :cross, exp.kind
         | 
| 40 70 | 
             
              end
         | 
| 41 71 |  | 
| 72 | 
            +
              test "kind when two different functions from the same dataset" do
         | 
| 73 | 
            +
                dataset_1 = mock('dataset 1')
         | 
| 74 | 
            +
                dataset_2 = mock('dataset 2')
         | 
| 75 | 
            +
                func_1 = stub_function('function 1', :dataset => dataset_1)
         | 
| 76 | 
            +
                func_2 = stub_function('function 2', :dataset => dataset_2)
         | 
| 77 | 
            +
                func_1.expects(:==).with(func_2).returns(false)
         | 
| 78 | 
            +
                dataset_1.expects(:==).with(dataset_2).returns(true)
         | 
| 79 | 
            +
                exp = Linkage::MustExpectation.new(:==, func_1, func_2)
         | 
| 80 | 
            +
                assert_equal :cross, exp.kind
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 42 83 | 
             
              test "manually set kind with two different fields from the same dataset" do
         | 
| 43 84 | 
             
                dataset = mock('dataset 1')
         | 
| 44 85 | 
             
                field_1 = stub_field('field 1', :dataset => dataset)
         | 
| @@ -71,6 +112,30 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 71 112 | 
             
                exp.apply_to(dataset_2)
         | 
| 72 113 | 
             
              end
         | 
| 73 114 |  | 
| 115 | 
            +
              test "apply a two-function dual expectation to two datasets" do
         | 
| 116 | 
            +
                dataset_1 = stub('dataset 1')
         | 
| 117 | 
            +
                dataset_2 = stub('dataset 2')
         | 
| 118 | 
            +
                func_1 = stub_function('function 1', :name => :foo, :dataset => dataset_1) do
         | 
| 119 | 
            +
                  stubs(:belongs_to?).with(dataset_1).returns(true)
         | 
| 120 | 
            +
                  stubs(:belongs_to?).with(dataset_2).returns(false)
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
                func_2 = stub_function('function 2', :name => :bar, :dataset => dataset_2) do
         | 
| 123 | 
            +
                  stubs(:belongs_to?).with(dataset_2).returns(true)
         | 
| 124 | 
            +
                  stubs(:belongs_to?).with(dataset_1).returns(false)
         | 
| 125 | 
            +
                end
         | 
| 126 | 
            +
                merged_field = stub_field('merged field', :name => :foo_bar)
         | 
| 127 | 
            +
                func_1.stubs(:merge).with(func_2).returns(merged_field)
         | 
| 128 | 
            +
                exp = Linkage::MustExpectation.new(:==, func_1, func_2)
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                dataset_1.expects(:add_order).with(func_1)
         | 
| 131 | 
            +
                dataset_1.expects(:add_select).with(func_1, :foo_bar)
         | 
| 132 | 
            +
                exp.apply_to(dataset_1)
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                dataset_2.expects(:add_order).with(func_2)
         | 
| 135 | 
            +
                dataset_2.expects(:add_select).with(func_2, :foo_bar)
         | 
| 136 | 
            +
                exp.apply_to(dataset_2)
         | 
| 137 | 
            +
              end
         | 
| 138 | 
            +
             | 
| 74 139 | 
             
              test "apply a two-field dual expectation to two datasets with an alias" do
         | 
| 75 140 | 
             
                dataset_1 = stub('dataset 1')
         | 
| 76 141 | 
             
                dataset_2 = stub('dataset 2')
         | 
| @@ -142,6 +207,20 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 142 207 | 
             
                exp.apply_to(dataset)
         | 
| 143 208 | 
             
              end
         | 
| 144 209 |  | 
| 210 | 
            +
              test "apply a two-function self expectation" do
         | 
| 211 | 
            +
                dataset = stub('dataset')
         | 
| 212 | 
            +
                func = stub_function('function', :name => :foo, :dataset => dataset) do
         | 
| 213 | 
            +
                  expects(:belongs_to?).with(dataset).twice.returns(true)
         | 
| 214 | 
            +
                end
         | 
| 215 | 
            +
                exp = Linkage::MustExpectation.new(:==, func, func)
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                # Twice is okay, since add_order/add_select will take care of
         | 
| 218 | 
            +
                # duplicates.
         | 
| 219 | 
            +
                dataset.expects(:add_order).twice.with(func)
         | 
| 220 | 
            +
                dataset.expects(:add_select).twice.with(func, :foo)
         | 
| 221 | 
            +
                exp.apply_to(dataset)
         | 
| 222 | 
            +
              end
         | 
| 223 | 
            +
             | 
| 145 224 | 
             
              test "apply a two-field self expectation like a cross" do
         | 
| 146 225 | 
             
                dataset_1 = stub('dataset 1')
         | 
| 147 226 | 
             
                dataset_2 = stub('dataset 2')
         | 
| @@ -174,12 +253,19 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 174 253 | 
             
                assert_equal :foo_bar, exp.name
         | 
| 175 254 | 
             
              end
         | 
| 176 255 |  | 
| 177 | 
            -
              test "expectation with static value" do
         | 
| 256 | 
            +
              test "expectation with static value is of type 'filter'" do
         | 
| 178 257 | 
             
                field = stub_field('field')
         | 
| 179 258 | 
             
                exp = Linkage::MustExpectation.new(:==, field, 123)
         | 
| 180 259 | 
             
                assert_equal :filter, exp.kind
         | 
| 181 260 | 
             
              end
         | 
| 182 261 |  | 
| 262 | 
            +
              test "expectation with static function is of type 'filter'" do
         | 
| 263 | 
            +
                field = stub_field('field')
         | 
| 264 | 
            +
                func = stub_function('func', :static? => true)
         | 
| 265 | 
            +
                exp = Linkage::MustExpectation.new(:==, field, func)
         | 
| 266 | 
            +
                assert_equal :filter, exp.kind
         | 
| 267 | 
            +
              end
         | 
| 268 | 
            +
             | 
| 183 269 | 
             
              test "apply filter expectation" do
         | 
| 184 270 | 
             
                dataset_1 = stub('dataset 1')
         | 
| 185 271 | 
             
                dataset_2 = stub('dataset 2')
         | 
| @@ -291,4 +377,14 @@ class UnitTests::TestExpectation < Test::Unit::TestCase | |
| 291 377 | 
             
                field.expects(:belongs_to?).with(dataset_2).returns(false)
         | 
| 292 378 | 
             
                exp.apply_to(dataset_2)
         | 
| 293 379 | 
             
              end
         | 
| 380 | 
            +
             | 
| 381 | 
            +
              test "allows a dynamic function filter" do
         | 
| 382 | 
            +
                func = stub_function("foo", :static? => false)
         | 
| 383 | 
            +
                exp = Linkage::MustNotExpectation.new(:==, func, 123)
         | 
| 384 | 
            +
              end
         | 
| 385 | 
            +
             | 
| 386 | 
            +
              test "does not allow a static function filter" do
         | 
| 387 | 
            +
                func = stub_function("foo", :static? => true)
         | 
| 388 | 
            +
                assert_raises(ArgumentError) { Linkage::MustNotExpectation.new(:==, func, 123) }
         | 
| 389 | 
            +
              end
         | 
| 294 390 | 
             
            end
         | 
    
        data/test/unit/test_field.rb
    CHANGED
    
    | @@ -7,6 +7,10 @@ class UnitTests::TestField < Test::Unit::TestCase | |
| 7 7 | 
             
                f
         | 
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| 10 | 
            +
              test "subclass of data" do
         | 
| 11 | 
            +
                assert_equal Linkage::Data, Linkage::Field.superclass
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 10 14 | 
             
              test "initialize with schema info" do
         | 
| 11 15 | 
             
                schema = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
         | 
| 12 16 | 
             
                field = Linkage::Field.new(:id, schema)
         | 
| @@ -21,420 +25,15 @@ class UnitTests::TestField < Test::Unit::TestCase | |
| 21 25 | 
             
                assert_equal info, field.ruby_type
         | 
| 22 26 | 
             
              end
         | 
| 23 27 |  | 
| 24 | 
            -
              test " | 
| 25 | 
            -
                 | 
| 26 | 
            -
                 | 
| 27 | 
            -
                 | 
| 28 | 
            -
             | 
| 29 | 
            -
                result_field = field_1.merge(field_2)
         | 
| 30 | 
            -
                assert_equal(:id, result_field.name)
         | 
| 31 | 
            -
                assert_equal(expected_type, result_field.ruby_type)
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                result_field = field_2.merge(field_1)
         | 
| 34 | 
            -
                assert_equal(:id, result_field.name)
         | 
| 35 | 
            -
                assert_equal(expected_type, result_field.ruby_type)
         | 
| 36 | 
            -
              end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
              test "merge fields with different names" do
         | 
| 39 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 40 | 
            -
                field_2 = Linkage::Field.new(:bar, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                result_field = field_1.merge(field_2)
         | 
| 43 | 
            -
                assert_equal(:foo_bar, result_field.name)
         | 
| 44 | 
            -
                result_field = field_2.merge(field_1)
         | 
| 45 | 
            -
                assert_equal(:bar_foo, result_field.name)
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              test "merge two boolean fields" do
         | 
| 49 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 50 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 51 | 
            -
                expected_type = {:type => TrueClass}
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                result_field = field_1.merge(field_2)
         | 
| 54 | 
            -
                assert_equal(:foo, result_field.name)
         | 
| 55 | 
            -
                assert_equal(expected_type, result_field.ruby_type)
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                result_field = field_2.merge(field_1)
         | 
| 58 | 
            -
                assert_equal(:foo, result_field.name)
         | 
| 59 | 
            -
                assert_equal(expected_type, result_field.ruby_type)
         | 
| 60 | 
            -
              end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
              test "merge a boolean field and an integer field" do
         | 
| 63 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 64 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 65 | 
            -
                expected_type = {:type => Integer}
         | 
| 66 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 67 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 68 | 
            -
              end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              test "merge a boolean field and a bignum field" do
         | 
| 71 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 72 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 73 | 
            -
                expected_type = {:type => Bignum}
         | 
| 74 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 75 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 76 | 
            -
              end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
              test "merge a boolean field and a float field" do
         | 
| 79 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 80 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 81 | 
            -
                expected_type = {:type => Float}
         | 
| 82 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 83 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 84 | 
            -
              end
         | 
| 85 | 
            -
             | 
| 86 | 
            -
              test "merge a boolean field and a decimal field" do
         | 
| 87 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 88 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 89 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 90 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 91 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 92 | 
            -
              end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
              test "merge a boolean field and a decimal field with size" do
         | 
| 95 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 96 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 97 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
         | 
| 98 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 99 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 100 | 
            -
              end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
              test "merge a boolean field and a string field" do
         | 
| 103 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 104 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 105 | 
            -
                expected_type = {:type => String, :opts => {:size => 10}}
         | 
| 106 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 107 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 108 | 
            -
              end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
              test "merge a boolean field and a text field" do
         | 
| 111 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 112 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 113 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 114 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 115 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 116 | 
            -
              end
         | 
| 117 | 
            -
             | 
| 118 | 
            -
              test "merge a boolean field and a fixed string field" do
         | 
| 119 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil})
         | 
| 120 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"boolean", :type=>:boolean, :ruby_default=>nil})
         | 
| 121 | 
            -
                expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
         | 
| 122 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 123 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 124 | 
            -
              end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
              test "merge two integer fields" do
         | 
| 127 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 128 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 129 | 
            -
                expected_type = {:type => Integer}
         | 
| 130 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 131 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 132 | 
            -
              end
         | 
| 133 | 
            -
             | 
| 134 | 
            -
              test "merge an integer field and a bignum field" do
         | 
| 135 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 136 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 137 | 
            -
                expected_type = {:type => Bignum}
         | 
| 138 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 139 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 140 | 
            -
              end
         | 
| 141 | 
            -
             | 
| 142 | 
            -
              test "merge an integer field and a float field" do
         | 
| 143 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 144 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 145 | 
            -
                expected_type = {:type => Float}
         | 
| 146 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 147 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 148 | 
            -
              end
         | 
| 149 | 
            -
             | 
| 150 | 
            -
              test "merge an integer field and a decimal field" do
         | 
| 151 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 152 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 153 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 154 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 155 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 156 | 
            -
              end
         | 
| 157 | 
            -
             | 
| 158 | 
            -
              test "merge an integer field and a decimal field with size" do
         | 
| 159 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 160 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 161 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
         | 
| 162 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 163 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 164 | 
            -
              end
         | 
| 165 | 
            -
             | 
| 166 | 
            -
              test "merge an integer field and a string field" do
         | 
| 167 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 168 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 169 | 
            -
                expected_type = {:type => String, :opts => {:size => 10}}
         | 
| 170 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 171 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 172 | 
            -
              end
         | 
| 173 | 
            -
             | 
| 174 | 
            -
              test "merge an integer field and a text field" do
         | 
| 175 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 176 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 177 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 178 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 179 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 180 | 
            -
              end
         | 
| 181 | 
            -
             | 
| 182 | 
            -
              test "merge an integer field and a fixed string field" do
         | 
| 183 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil})
         | 
| 184 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 185 | 
            -
                expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
         | 
| 186 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 187 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 188 | 
            -
              end
         | 
| 189 | 
            -
             | 
| 190 | 
            -
              test "merge two bignum fields" do
         | 
| 191 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 192 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 193 | 
            -
                expected_type = {:type => Bignum}
         | 
| 194 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 195 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 196 | 
            -
              end
         | 
| 197 | 
            -
             | 
| 198 | 
            -
              test "merge an bignum field and a decimal field" do
         | 
| 199 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 200 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 201 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 202 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 203 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 204 | 
            -
              end
         | 
| 205 | 
            -
             | 
| 206 | 
            -
              test "merge an bignum field and a decimal field with size" do
         | 
| 207 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 208 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 209 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
         | 
| 210 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 211 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 212 | 
            -
              end
         | 
| 213 | 
            -
             | 
| 214 | 
            -
              test "merge an bignum field and a string field" do
         | 
| 215 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 216 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 217 | 
            -
                expected_type = {:type => String, :opts => {:size => 10}}
         | 
| 218 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 219 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 220 | 
            -
              end
         | 
| 221 | 
            -
             | 
| 222 | 
            -
              test "merge an bignum field and a text field" do
         | 
| 223 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 224 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 225 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 226 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 227 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 228 | 
            -
              end
         | 
| 229 | 
            -
             | 
| 230 | 
            -
              test "merge an bignum field and a fixed string field" do
         | 
| 231 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil})
         | 
| 232 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 233 | 
            -
                expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
         | 
| 234 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 235 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 236 | 
            -
              end
         | 
| 237 | 
            -
             | 
| 238 | 
            -
              test "merge two float fields" do
         | 
| 239 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 240 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 241 | 
            -
                expected_type = {:type => Float}
         | 
| 242 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 243 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 244 | 
            -
              end
         | 
| 245 | 
            -
             | 
| 246 | 
            -
              test "merge a float field and a bignum field" do
         | 
| 247 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"bigint", :type=>:bigint, :ruby_default=>nil})
         | 
| 248 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 249 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 250 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 251 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 252 | 
            -
              end
         | 
| 253 | 
            -
             | 
| 254 | 
            -
              test "merge a float field and a decimal field" do
         | 
| 255 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 256 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 257 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 258 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 259 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 260 | 
            -
              end
         | 
| 261 | 
            -
             | 
| 262 | 
            -
              test "merge a float field and a decimal field with size" do
         | 
| 263 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 264 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 265 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
         | 
| 266 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 267 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 268 | 
            -
              end
         | 
| 269 | 
            -
             | 
| 270 | 
            -
              test "merge a float field and a string field" do
         | 
| 271 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 272 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 273 | 
            -
                expected_type = {:type => String, :opts => {:size => 10}}
         | 
| 274 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 275 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 276 | 
            -
              end
         | 
| 277 | 
            -
             | 
| 278 | 
            -
              test "merge a float field and a text field" do
         | 
| 279 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 280 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 281 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 282 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 283 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 284 | 
            -
              end
         | 
| 285 | 
            -
             | 
| 286 | 
            -
              test "merge a float field and a fixed string field" do
         | 
| 287 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil})
         | 
| 288 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"float", :type=>:float, :ruby_default=>nil})
         | 
| 289 | 
            -
                expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
         | 
| 290 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 291 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 292 | 
            -
              end
         | 
| 293 | 
            -
             | 
| 294 | 
            -
              test "merge two decimal fields" do
         | 
| 295 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 296 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 297 | 
            -
                expected_type = {:type => BigDecimal}
         | 
| 298 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 299 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 300 | 
            -
              end
         | 
| 301 | 
            -
             | 
| 302 | 
            -
              test "merge two decimal fields, one with size" do
         | 
| 303 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 304 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 305 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [10, 2]}}
         | 
| 306 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 307 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 308 | 
            -
              end
         | 
| 309 | 
            -
             | 
| 310 | 
            -
              test "merge two decimal fields, both with size" do
         | 
| 311 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 312 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,1)", :type=>:decimal, :ruby_default=>nil})
         | 
| 313 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [12, 2]}}
         | 
| 314 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 315 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 316 | 
            -
              end
         | 
| 317 | 
            -
             | 
| 318 | 
            -
              test "merge two decimal fields, both with size, one without scale" do
         | 
| 319 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(10)", :type=>:decimal, :ruby_default=>nil})
         | 
| 320 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,1)", :type=>:decimal, :ruby_default=>nil})
         | 
| 321 | 
            -
                expected_type = {:type => BigDecimal, :opts => {:size => [12, 1]}}
         | 
| 322 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 323 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 324 | 
            -
              end
         | 
| 325 | 
            -
             | 
| 326 | 
            -
              test "merge a decimal field and a string field" do
         | 
| 327 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 328 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 329 | 
            -
                expected_type = {:type => String, :opts => {:size => 10}}
         | 
| 330 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 331 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 332 | 
            -
              end
         | 
| 333 | 
            -
             | 
| 334 | 
            -
              test "merge a decimal field with size and a string field" do
         | 
| 335 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(10)", :type=>:string, :ruby_default=>nil})
         | 
| 336 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 337 | 
            -
                expected_type = {:type => String, :opts => {:size => 13}}
         | 
| 338 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 339 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 340 | 
            -
              end
         | 
| 341 | 
            -
             | 
| 342 | 
            -
              test "merge a decimal field and a text field" do
         | 
| 343 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 344 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 345 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 346 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 347 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 348 | 
            -
              end
         | 
| 349 | 
            -
             | 
| 350 | 
            -
              test "merge a decimal field with size and a text field" do
         | 
| 351 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"text", :type=>:text, :ruby_default=>nil})
         | 
| 352 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal(12,2)", :type=>:decimal, :ruby_default=>nil})
         | 
| 353 | 
            -
                expected_type = {:type => String, :opts => {:text => true}}
         | 
| 354 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 355 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 356 | 
            -
              end
         | 
| 357 | 
            -
             | 
| 358 | 
            -
              test "merge a decimal field and a fixed string field" do
         | 
| 359 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"char(10)", :type=>:string, :ruby_default=>nil})
         | 
| 360 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"decimal", :type=>:decimal, :ruby_default=>nil})
         | 
| 361 | 
            -
                expected_type = {:type => String, :opts => {:size => 10, :fixed => true}}
         | 
| 362 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 363 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 364 | 
            -
              end
         | 
| 365 | 
            -
             | 
| 366 | 
            -
              test "merge two string fields" do
         | 
| 367 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil})
         | 
| 368 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil})
         | 
| 369 | 
            -
                expected_type = {:type => String, :opts => {:size => 20}}
         | 
| 370 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 371 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 372 | 
            -
              end
         | 
| 373 | 
            -
             | 
| 374 | 
            -
              test "merge two string fields with different sizes" do
         | 
| 375 | 
            -
                field_1 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(15)", :type=>:string, :ruby_default=>nil})
         | 
| 376 | 
            -
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"varchar(20)", :type=>:string, :ruby_default=>nil})
         | 
| 377 | 
            -
                expected_type = {:type => String, :opts => {:size => 20}}
         | 
| 378 | 
            -
                assert_equal(expected_type, field_1.merge(field_2).ruby_type)
         | 
| 379 | 
            -
                assert_equal(expected_type, field_2.merge(field_1).ruby_type)
         | 
| 380 | 
            -
              end
         | 
| 381 | 
            -
             | 
| 382 | 
            -
              test "merge two fields and specify name" do
         | 
| 383 | 
            -
                field_1 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 384 | 
            -
                field_2 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 385 | 
            -
             | 
| 386 | 
            -
                result_field = field_1.merge(field_2, 'foo')
         | 
| 387 | 
            -
                assert_equal :foo, result_field.name
         | 
| 388 | 
            -
             | 
| 389 | 
            -
                result_field = field_2.merge(field_1, 'foo')
         | 
| 390 | 
            -
                assert_equal :foo, result_field.name
         | 
| 391 | 
            -
              end
         | 
| 392 | 
            -
             | 
| 393 | 
            -
              test "== returns true when fields have the same name and are from the same dataset" do
         | 
| 394 | 
            -
                dataset_1 = stub('dataset')
         | 
| 395 | 
            -
                field_1 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 396 | 
            -
                field_1.dataset = dataset_1
         | 
| 397 | 
            -
                dataset_2 = stub('dataset clone')
         | 
| 398 | 
            -
                field_2 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 399 | 
            -
                field_2.dataset = dataset_2
         | 
| 400 | 
            -
             | 
| 401 | 
            -
                dataset_1.expects(:==).with(dataset_2).returns(true)
         | 
| 402 | 
            -
                assert_equal field_1, field_2
         | 
| 403 | 
            -
              end
         | 
| 404 | 
            -
             | 
| 405 | 
            -
              test "== returns false when fields have the same name but are from different datasets" do
         | 
| 406 | 
            -
                dataset_1 = stub('dataset 1')
         | 
| 407 | 
            -
                field_1 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 408 | 
            -
                field_1.dataset = dataset_1
         | 
| 409 | 
            -
                dataset_2 = stub('dataset 2')
         | 
| 410 | 
            -
                field_2 = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 411 | 
            -
                field_2.dataset = dataset_2
         | 
| 412 | 
            -
             | 
| 413 | 
            -
                dataset_1.expects(:==).with(dataset_2).returns(false)
         | 
| 414 | 
            -
                assert_not_equal field_1, field_2
         | 
| 415 | 
            -
              end
         | 
| 416 | 
            -
             | 
| 417 | 
            -
              test "belongs_to? dataset" do
         | 
| 418 | 
            -
                dataset = stub('dataset 1', :id => 1)
         | 
| 419 | 
            -
                field = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 420 | 
            -
                field.dataset = dataset
         | 
| 421 | 
            -
                assert field.belongs_to?(dataset)
         | 
| 422 | 
            -
              end
         | 
| 423 | 
            -
             | 
| 424 | 
            -
              test "belongs_to? dataset with same id" do
         | 
| 425 | 
            -
                dataset_1 = stub('dataset 1', :id => 1)
         | 
| 426 | 
            -
                dataset_2 = stub('dataset 2', :id => 1)
         | 
| 427 | 
            -
                field = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 428 | 
            -
                field.dataset = dataset_1
         | 
| 429 | 
            -
                assert field.belongs_to?(dataset_2)
         | 
| 28 | 
            +
              test "static? is always false" do
         | 
| 29 | 
            +
                schema = {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil}
         | 
| 30 | 
            +
                field = Linkage::Field.new(:id, schema)
         | 
| 31 | 
            +
                assert !field.static?
         | 
| 430 32 | 
             
              end
         | 
| 431 33 |  | 
| 432 | 
            -
              test " | 
| 433 | 
            -
                dataset_1 = stub('dataset 1', :id => 1)
         | 
| 434 | 
            -
                dataset_2 = stub('dataset 2', :id => 2)
         | 
| 34 | 
            +
              test "ruby_type for integer" do
         | 
| 435 35 | 
             
                field = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 436 | 
            -
                field. | 
| 437 | 
            -
                assert !field.belongs_to?(dataset_2)
         | 
| 36 | 
            +
                assert_equal({:type => Integer}, field.ruby_type)
         | 
| 438 37 | 
             
              end
         | 
| 439 38 |  | 
| 440 39 | 
             
              test "primary_key? returns true if primary key" do
         | 
| @@ -444,4 +43,9 @@ class UnitTests::TestField < Test::Unit::TestCase | |
| 444 43 | 
             
                field_2 = Linkage::Field.new(:foo, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 445 44 | 
             
                assert !field_2.primary_key?
         | 
| 446 45 | 
             
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              test "to_expr returns name" do
         | 
| 48 | 
            +
                field = Linkage::Field.new(:id, {:allow_null=>true, :default=>nil, :primary_key=>true, :db_type=>"integer", :type=>:integer, :ruby_default=>nil})
         | 
| 49 | 
            +
                assert_equal :id, field.to_expr
         | 
| 50 | 
            +
              end
         | 
| 447 51 | 
             
            end
         |