Skip to content

Commit

Permalink
Late night fixing of bugs
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
viking committed May 25, 2011
1 parent 5559c53 commit 9018f76
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
9 changes: 5 additions & 4 deletions lib/coupler/models/comparison.rb
Expand Up @@ -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 += %{<span class="sup">#{self[:"#{name}_which"]}</span>}
end
# FIXME: revisit this!
#if self[:"#{name}_which"]
#resource_name += %{<span class="sup">#{self[:"#{name}_which"]}</span>}
#end
result += " (#{resource_name})"
else
lhs_rhs_value(name).inspect
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/coupler/models/transformer.rb
Expand Up @@ -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 = {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/models/test_comparison.rb
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions test/unit/models/test_transformer.rb
Expand Up @@ -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

0 comments on commit 9018f76

Please sign in to comment.