From 9018f7657802d79fc4d4fc0a6ddb2a0b5bc8ff0c Mon Sep 17 00:00:00 2001 From: Jeremy Stephens Date: Wed, 25 May 2011 01:36:19 -0500 Subject: [PATCH] Late night fixing of bugs - Sequel or H2 or something double escapes text fields, which was screwing up transformers. Serialized it seems to have fixed it - Comparison bug - Discovered some nasty dual-linkage bugs --- lib/coupler/models/comparison.rb | 9 +++++---- lib/coupler/models/transformer.rb | 2 +- test/unit/models/test_comparison.rb | 12 ++++++------ test/unit/models/test_transformer.rb | 10 ++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/coupler/models/comparison.rb b/lib/coupler/models/comparison.rb index 0fc51a7..7feacbb 100644 --- a/lib/coupler/models/comparison.rb +++ b/lib/coupler/models/comparison.rb @@ -31,9 +31,10 @@ def lhs_rhs_label(name) field = lhs_rhs_value(name) result = field.name resource_name = field.resource.name - if self[:"#{name}_which"] - resource_name += %{#{self[:"#{name}_which"]}} - end + # FIXME: revisit this! + #if self[:"#{name}_which"] + #resource_name += %{#{self[:"#{name}_which"]}} + #end result += " (#{resource_name})" else lhs_rhs_value(name).inspect @@ -147,7 +148,7 @@ def validate validates_includes [1, 2], :rhs_which if rhs_type == 'field' if lhs_type == 'field' && rhs_type == 'field' && (lhs_field = lhs_value) && (rhs_field = rhs_value) - if lhs_field[:type] != rhs_field[:type] + if lhs_field[:final_type] != rhs_field[:final_type] errors.add(:base, "Comparing fields of different types is currently disallowed.") end if lhs_which != rhs_which && operator != 'equals' diff --git a/lib/coupler/models/transformer.rb b/lib/coupler/models/transformer.rb index 6307499..f982370 100644 --- a/lib/coupler/models/transformer.rb +++ b/lib/coupler/models/transformer.rb @@ -3,7 +3,7 @@ module Models class Transformer < Sequel::Model include CommonModel - plugin :serialization, :marshal, :allowed_types + plugin :serialization, :marshal, :allowed_types, :code TYPES = %w{string integer datetime} EXAMPLES = { diff --git a/test/unit/models/test_comparison.rb b/test/unit/models/test_comparison.rb index b01be76..bbda166 100644 --- a/test/unit/models/test_comparison.rb +++ b/test/unit/models/test_comparison.rb @@ -559,7 +559,7 @@ def test_apply_field_inequality_to_dual_datasets test "blocking?" do field = stub("field", :name => 'first_name') { - stubs(:[]).with(:type).returns('string') + stubs(:[]).with(:final_type).returns('string') } Field.stubs(:[]).with(:id => 1).returns(field) comparison = new_comparison({ @@ -572,11 +572,11 @@ def test_apply_field_inequality_to_dual_datasets test "cross_match?" do field_1 = stub("field 1", :id => 1, :name => 'ssn_1', :resource_id => 1) { - stubs(:[]).with(:type).returns('string') + stubs(:[]).with(:final_type).returns('string') } Field.stubs(:[]).with(:id => 1).returns(field_1) field_2 = stub("field 2", :id => 2, :name => 'ssn_2', :resource_id => 1) { - stubs(:[]).with(:type).returns('string') + stubs(:[]).with(:final_type).returns('string') } Field.stubs(:[]).with(:id => 2).returns(field_2) comparison = new_comparison({ @@ -589,11 +589,11 @@ def test_apply_field_inequality_to_dual_datasets test "does not allow two fields of different types" do field_1 = stub("field 1", :name => 'first_name') { - stubs(:[]).with(:type).returns('string') + stubs(:[]).with(:final_type).returns('string') } Field.stubs(:[]).with(:id => 1).returns(field_1) field_2 = stub("field 2", :name => 'age') { - stubs(:[]).with(:type).returns('integer') + stubs(:[]).with(:final_type).returns('integer') } Field.stubs(:[]).with(:id => 2).returns(field_2) comparison = new_comparison({ @@ -605,7 +605,7 @@ def test_apply_field_inequality_to_dual_datasets end test "does not allow non-equality comparisons for fields" do - field = stub("field", :name => 'first_name') { stubs(:[]).with(:type).returns('string') } + field = stub("field", :name => 'first_name') { stubs(:[]).with(:final_type).returns('string') } Field.stubs(:[]).with(:id => 1).returns(field) comparison = new_comparison({ :lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1, diff --git a/test/unit/models/test_transformer.rb b/test/unit/models/test_transformer.rb index 3f54402..cf524ff 100644 --- a/test/unit/models/test_transformer.rb +++ b/test/unit/models/test_transformer.rb @@ -183,6 +183,16 @@ def new_transformer(attribs = {}) #def test_should_handle_empty_values #pend #end + + test "doesn't escape backslashes too much" do + code = %{value =~ /\d/ ? "YES" : "NO"} + transformer = new_transformer({ + :allowed_types => %w{string}, + :result_type => 'string', :code => code + }).save! + t = Transformer[:id => transformer.id] + assert_equal code, t.code + end end end end