coupler 0.0.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitmodules +3 -0
- data/.rvmrc +1 -0
- data/.vimrc +40 -0
- data/Gemfile +27 -0
- data/Gemfile.lock +71 -0
- data/LICENSE +20 -0
- data/NOTES +6 -0
- data/README.rdoc +18 -0
- data/Rakefile +42 -0
- data/TODO +11 -0
- data/VERSION +1 -0
- data/bin/coupler +7 -0
- data/db/.gitignore +6 -0
- data/db/migrate/001_initial_schema.rb +166 -0
- data/db/migrate/002_stub.rb +4 -0
- data/db/migrate/003_stub.rb +4 -0
- data/db/migrate/004_create_comparisons.rb +28 -0
- data/db/migrate/005_move_database_name.rb +19 -0
- data/db/migrate/006_upgrade_comparisons.rb +34 -0
- data/db/migrate/007_add_which_to_comparisons.rb +23 -0
- data/db/migrate/008_add_result_field_to_transformations.rb +33 -0
- data/db/migrate/009_add_generated_flag_to_fields.rb +13 -0
- data/db/migrate/010_create_imports.rb +24 -0
- data/db/migrate/011_add_primary_key_type.rb +13 -0
- data/db/migrate/012_add_transformed_with_to_resources.rb +13 -0
- data/db/migrate/013_add_run_count_to_scenarios.rb +13 -0
- data/db/migrate/014_add_last_accessed_at_to_some_tables.rb +13 -0
- data/db/migrate/015_add_run_number_to_results.rb +15 -0
- data/db/migrate/016_fix_scenario_run_count.rb +27 -0
- data/db/migrate/017_rename_comparison_columns.rb +14 -0
- data/db/migrate/018_fix_scenario_linkage_type.rb +8 -0
- data/db/migrate/019_add_columns_to_imports.rb +24 -0
- data/db/migrate/020_rename_import_columns.rb +12 -0
- data/db/migrate/021_add_fields_to_connections.rb +15 -0
- data/db/migrate/022_remove_database_name_from_resources.rb +11 -0
- data/features/connections.feature +28 -0
- data/features/matchers.feature +35 -0
- data/features/projects.feature +11 -0
- data/features/resources.feature +62 -0
- data/features/scenarios.feature +45 -0
- data/features/step_definitions/coupler_steps.rb +145 -0
- data/features/step_definitions/matchers_steps.rb +26 -0
- data/features/step_definitions/resources_steps.rb +12 -0
- data/features/step_definitions/scenarios_steps.rb +7 -0
- data/features/step_definitions/transformations_steps.rb +3 -0
- data/features/support/env.rb +128 -0
- data/features/transformations.feature +22 -0
- data/features/wizard.feature +10 -0
- data/gfx/coupler-header.svg +213 -0
- data/gfx/coupler-sidebar.svg +656 -0
- data/gfx/coupler.svg +184 -0
- data/gfx/icon.svg +75 -0
- data/lib/coupler/base.rb +63 -0
- data/lib/coupler/config.rb +128 -0
- data/lib/coupler/data_uploader.rb +20 -0
- data/lib/coupler/database.rb +31 -0
- data/lib/coupler/extensions/connections.rb +57 -0
- data/lib/coupler/extensions/exceptions.rb +58 -0
- data/lib/coupler/extensions/imports.rb +43 -0
- data/lib/coupler/extensions/jobs.rb +21 -0
- data/lib/coupler/extensions/matchers.rb +64 -0
- data/lib/coupler/extensions/projects.rb +62 -0
- data/lib/coupler/extensions/resources.rb +89 -0
- data/lib/coupler/extensions/results.rb +100 -0
- data/lib/coupler/extensions/scenarios.rb +50 -0
- data/lib/coupler/extensions/transformations.rb +70 -0
- data/lib/coupler/extensions/transformers.rb +58 -0
- data/lib/coupler/extensions.rb +16 -0
- data/lib/coupler/helpers.rb +121 -0
- data/lib/coupler/import_buffer.rb +48 -0
- data/lib/coupler/logger.rb +16 -0
- data/lib/coupler/models/common_model.rb +104 -0
- data/lib/coupler/models/comparison.rb +166 -0
- data/lib/coupler/models/connection.rb +59 -0
- data/lib/coupler/models/field.rb +55 -0
- data/lib/coupler/models/import.rb +238 -0
- data/lib/coupler/models/job.rb +42 -0
- data/lib/coupler/models/jobify.rb +17 -0
- data/lib/coupler/models/matcher.rb +36 -0
- data/lib/coupler/models/project.rb +40 -0
- data/lib/coupler/models/resource.rb +287 -0
- data/lib/coupler/models/result.rb +92 -0
- data/lib/coupler/models/scenario/runner.rb +357 -0
- data/lib/coupler/models/scenario.rb +115 -0
- data/lib/coupler/models/transformation.rb +117 -0
- data/lib/coupler/models/transformer/runner.rb +28 -0
- data/lib/coupler/models/transformer.rb +110 -0
- data/lib/coupler/models.rb +30 -0
- data/lib/coupler/runner.rb +76 -0
- data/lib/coupler/scheduler.rb +56 -0
- data/lib/coupler.rb +34 -0
- data/log/.gitignore +1 -0
- data/misc/README +5 -0
- data/misc/jruby-json.license +57 -0
- data/misc/rack-flash.license +22 -0
- data/script/dbconsole.rb +5 -0
- data/src/edu/vanderbilt/coupler/Main.java +116 -0
- data/src/edu/vanderbilt/coupler/jruby.properties +1 -0
- data/tasks/annotations.rake +84 -0
- data/tasks/db.rake +120 -0
- data/tasks/environment.rake +12 -0
- data/tasks/jeweler.rake +43 -0
- data/tasks/package.rake +58 -0
- data/tasks/rdoc.rake +13 -0
- data/tasks/test.rake +63 -0
- data/tasks/vendor.rake +43 -0
- data/test/README.txt +6 -0
- data/test/config.yml +9 -0
- data/test/coupler/models/test_import.rb +221 -0
- data/test/factories.rb +91 -0
- data/test/fixtures/duplicate-keys.csv +5 -0
- data/test/fixtures/no-headers.csv +50 -0
- data/test/fixtures/people.csv +51 -0
- data/test/fixtures/varying-row-size.csv +4 -0
- data/test/helper.rb +156 -0
- data/test/integration/extensions/test_connections.rb +80 -0
- data/test/integration/extensions/test_imports.rb +94 -0
- data/test/integration/extensions/test_jobs.rb +52 -0
- data/test/integration/extensions/test_matchers.rb +134 -0
- data/test/integration/extensions/test_projects.rb +82 -0
- data/test/integration/extensions/test_resources.rb +150 -0
- data/test/integration/extensions/test_results.rb +89 -0
- data/test/integration/extensions/test_scenarios.rb +88 -0
- data/test/integration/extensions/test_transformations.rb +113 -0
- data/test/integration/extensions/test_transformers.rb +80 -0
- data/test/integration/test_field.rb +45 -0
- data/test/integration/test_import.rb +78 -0
- data/test/integration/test_running_scenarios.rb +379 -0
- data/test/integration/test_transformation.rb +56 -0
- data/test/integration/test_transforming.rb +154 -0
- data/test/table_sets.rb +76 -0
- data/test/unit/models/test_common_model.rb +130 -0
- data/test/unit/models/test_comparison.rb +619 -0
- data/test/unit/models/test_connection.rb +115 -0
- data/test/unit/models/test_field.rb +99 -0
- data/test/unit/models/test_import.rb +130 -0
- data/test/unit/models/test_job.rb +115 -0
- data/test/unit/models/test_matcher.rb +82 -0
- data/test/unit/models/test_project.rb +102 -0
- data/test/unit/models/test_resource.rb +564 -0
- data/test/unit/models/test_result.rb +90 -0
- data/test/unit/models/test_scenario.rb +199 -0
- data/test/unit/models/test_transformation.rb +193 -0
- data/test/unit/models/test_transformer.rb +188 -0
- data/test/unit/test_base.rb +60 -0
- data/test/unit/test_data_uploader.rb +27 -0
- data/test/unit/test_database.rb +23 -0
- data/test/unit/test_helpers.rb +58 -0
- data/test/unit/test_logger.rb +10 -0
- data/test/unit/test_models.rb +12 -0
- data/test/unit/test_runner.rb +76 -0
- data/test/unit/test_scheduler.rb +66 -0
- data/uploads/.gitignore +2 -0
- data/vendor/java/.gitignore +5 -0
- data/webroot/public/css/960.css +1 -0
- data/webroot/public/css/dataTables.css +1057 -0
- data/webroot/public/css/jquery-ui.css +572 -0
- data/webroot/public/css/jquery.treeview.css +68 -0
- data/webroot/public/css/reset.css +1 -0
- data/webroot/public/css/style.css +504 -0
- data/webroot/public/css/text.css +1 -0
- data/webroot/public/favicon.ico +0 -0
- data/webroot/public/images/12_col.gif +0 -0
- data/webroot/public/images/16_col.gif +0 -0
- data/webroot/public/images/add.png +0 -0
- data/webroot/public/images/ajax-loader.gif +0 -0
- data/webroot/public/images/cog.png +0 -0
- data/webroot/public/images/coupler.png +0 -0
- data/webroot/public/images/foo.png +0 -0
- data/webroot/public/images/hammer.png +0 -0
- data/webroot/public/images/header.png +0 -0
- data/webroot/public/images/home.gif +0 -0
- data/webroot/public/images/jobs.gif +0 -0
- data/webroot/public/images/sidebar-bottom.png +0 -0
- data/webroot/public/images/sidebar.png +0 -0
- data/webroot/public/images/treeview-default-line.gif +0 -0
- data/webroot/public/images/treeview-default.gif +0 -0
- data/webroot/public/images/ui-anim_basic_16x16.gif +0 -0
- data/webroot/public/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/webroot/public/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/webroot/public/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/webroot/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/webroot/public/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/webroot/public/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/webroot/public/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/webroot/public/images/ui-bg_highlight-hard_30_565356_1x100.png +0 -0
- data/webroot/public/images/ui-bg_highlight-hard_75_888588_1x100.png +0 -0
- data/webroot/public/images/ui-bg_highlight-soft_30_6e3b3a_1x100.png +0 -0
- data/webroot/public/images/ui-bg_highlight-soft_35_8e8b8e_1x100.png +0 -0
- data/webroot/public/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/webroot/public/images/ui-icons_222222_256x240.png +0 -0
- data/webroot/public/images/ui-icons_2e83ff_256x240.png +0 -0
- data/webroot/public/images/ui-icons_454545_256x240.png +0 -0
- data/webroot/public/images/ui-icons_888888_256x240.png +0 -0
- data/webroot/public/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/webroot/public/images/ui-icons_ffffff_256x240.png +0 -0
- data/webroot/public/js/ajaxupload.js +673 -0
- data/webroot/public/js/application.js +40 -0
- data/webroot/public/js/jquery-ui.combobox.js +98 -0
- data/webroot/public/js/jquery-ui.js +9867 -0
- data/webroot/public/js/jquery-ui.min.js +559 -0
- data/webroot/public/js/jquery.dataTables.min.js +587 -0
- data/webroot/public/js/jquery.min.js +154 -0
- data/webroot/public/js/jquery.timeago.js +140 -0
- data/webroot/public/js/jquery.tooltip.min.js +19 -0
- data/webroot/public/js/jquery.treeview.min.js +15 -0
- data/webroot/public/js/resource.js +11 -0
- data/webroot/public/js/results.js +56 -0
- data/webroot/public/js/transformations.js +95 -0
- data/webroot/views/connections/index.erb +5 -0
- data/webroot/views/connections/list.erb +34 -0
- data/webroot/views/connections/new.erb +55 -0
- data/webroot/views/connections/show.erb +36 -0
- data/webroot/views/imports/edit.erb +60 -0
- data/webroot/views/imports/form.erb +81 -0
- data/webroot/views/imports/new.erb +89 -0
- data/webroot/views/index.erb +12 -0
- data/webroot/views/jobs/index.erb +7 -0
- data/webroot/views/jobs/list.erb +24 -0
- data/webroot/views/layout.erb +38 -0
- data/webroot/views/matchers/form.erb +250 -0
- data/webroot/views/matchers/list.erb +32 -0
- data/webroot/views/projects/form.erb +14 -0
- data/webroot/views/projects/index.erb +96 -0
- data/webroot/views/projects/show.erb +24 -0
- data/webroot/views/resources/edit.erb +88 -0
- data/webroot/views/resources/index.erb +5 -0
- data/webroot/views/resources/list.erb +27 -0
- data/webroot/views/resources/new.erb +121 -0
- data/webroot/views/resources/show.erb +86 -0
- data/webroot/views/resources/transform.erb +2 -0
- data/webroot/views/results/csv.erb +12 -0
- data/webroot/views/results/details.erb +15 -0
- data/webroot/views/results/index.erb +2 -0
- data/webroot/views/results/list.erb +22 -0
- data/webroot/views/results/record.erb +24 -0
- data/webroot/views/results/show.erb +68 -0
- data/webroot/views/scenarios/index.erb +5 -0
- data/webroot/views/scenarios/list.erb +20 -0
- data/webroot/views/scenarios/new.erb +99 -0
- data/webroot/views/scenarios/run.erb +2 -0
- data/webroot/views/scenarios/show.erb +50 -0
- data/webroot/views/sidebar.erb +106 -0
- data/webroot/views/transformations/create.erb +115 -0
- data/webroot/views/transformations/for.erb +16 -0
- data/webroot/views/transformations/index.erb +2 -0
- data/webroot/views/transformations/list.erb +29 -0
- data/webroot/views/transformations/new.erb +126 -0
- data/webroot/views/transformations/preview.erb +46 -0
- data/webroot/views/transformers/edit.erb +6 -0
- data/webroot/views/transformers/form.erb +58 -0
- data/webroot/views/transformers/index.erb +2 -0
- data/webroot/views/transformers/list.erb +25 -0
- data/webroot/views/transformers/new.erb +5 -0
- data/webroot/views/transformers/preview.erb +23 -0
- data/webroot/views/transformers/show.erb +0 -0
- metadata +558 -0
@@ -0,0 +1,619 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Coupler
|
4
|
+
module Models
|
5
|
+
class TestComparison < Coupler::Test::UnitTest
|
6
|
+
def sequel_expr(*args)
|
7
|
+
if args.length == 1
|
8
|
+
obj = args[0]
|
9
|
+
obj.is_a?(Sequel::SQL::BooleanExpression) ? obj : Sequel::SQL::BooleanExpression.from_value_pairs(obj)
|
10
|
+
else
|
11
|
+
Sequel::SQL::BooleanExpression.new(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def new_comparison(attribs = {})
|
16
|
+
values = {
|
17
|
+
:lhs_type => "integer",
|
18
|
+
:raw_lhs_value => 1,
|
19
|
+
:rhs_type => "integer",
|
20
|
+
:raw_rhs_value => 1,
|
21
|
+
:operator => "equals",
|
22
|
+
:matcher => @matcher
|
23
|
+
}.update(attribs)
|
24
|
+
c = Comparison.new(values)
|
25
|
+
c
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
super
|
30
|
+
@matcher = stub('matcher', :id => 123, :pk => 123, :associations => {})
|
31
|
+
end
|
32
|
+
|
33
|
+
test "sequel model" do
|
34
|
+
assert_equal ::Sequel::Model, Comparison.superclass
|
35
|
+
assert_equal :comparisons, Comparison.table_name
|
36
|
+
end
|
37
|
+
|
38
|
+
test "many to one matcher" do
|
39
|
+
assert_respond_to Comparison.new, :matcher
|
40
|
+
end
|
41
|
+
|
42
|
+
#def test_serializes_lhs_and_rhs_values
|
43
|
+
#comparison = new_comparison({
|
44
|
+
#:lhs_type => "integer", :raw_lhs_value => 123,
|
45
|
+
#:rhs_type => "integer", :raw_rhs_value => 123
|
46
|
+
#}).save!
|
47
|
+
#assert_equal 123, comparison.raw_lhs_value
|
48
|
+
#assert_equal 123, comparison.raw_rhs_value
|
49
|
+
#end
|
50
|
+
|
51
|
+
test "requires values" do
|
52
|
+
comparison = new_comparison({
|
53
|
+
:raw_lhs_value => nil,
|
54
|
+
:raw_rhs_value => nil
|
55
|
+
})
|
56
|
+
comparison.expects(:validates_presence).with { |fields|
|
57
|
+
(fields - [:raw_lhs_value, :raw_rhs_value]).empty?
|
58
|
+
}.returns(false)
|
59
|
+
comparison.valid?
|
60
|
+
end
|
61
|
+
|
62
|
+
test "requires valid types" do
|
63
|
+
comparison = new_comparison({
|
64
|
+
:lhs_type => 'foo', :rhs_type => 'foo'
|
65
|
+
})
|
66
|
+
comparison.stubs(:validates_includes).at_least_once
|
67
|
+
comparison.expects(:validates_includes).with(%w{field integer string}, [:lhs_type, :rhs_type]).returns(false)
|
68
|
+
comparison.valid?
|
69
|
+
end
|
70
|
+
|
71
|
+
test "requires valid operator" do
|
72
|
+
comparison = new_comparison({
|
73
|
+
:operator => 'foo'
|
74
|
+
})
|
75
|
+
comparison.stubs(:validates_includes).at_least_once
|
76
|
+
comparison.expects(:validates_includes).with(%w{equals does_not_equal greater_than less_than}, :operator).returns(false)
|
77
|
+
comparison.valid?
|
78
|
+
end
|
79
|
+
|
80
|
+
test "requires valid lhs_which and rhs_which" do
|
81
|
+
comparison = new_comparison({
|
82
|
+
:raw_lhs_value => 1, :lhs_type => 'field', :lhs_which => 123,
|
83
|
+
:raw_rhs_value => 2, :rhs_type => 'field', :rhs_which => 123
|
84
|
+
})
|
85
|
+
comparison.stubs(:validates_includes).at_least_once
|
86
|
+
comparison.expects(:validates_includes).with([1, 2], :lhs_which).returns(false)
|
87
|
+
comparison.expects(:validates_includes).with([1, 2], :rhs_which).returns(false)
|
88
|
+
comparison.valid?
|
89
|
+
end
|
90
|
+
|
91
|
+
test "value methods return fields if type is field" do
|
92
|
+
comparison = new_comparison({
|
93
|
+
:lhs_type => "field", :raw_lhs_value => 1,
|
94
|
+
:rhs_type => "field", :raw_rhs_value => 2
|
95
|
+
}).save!
|
96
|
+
|
97
|
+
field_1 = stub('field 1')
|
98
|
+
field_2 = stub('field 2')
|
99
|
+
Field.expects(:[]).with(:id => 1).returns(field_1)
|
100
|
+
Field.expects(:[]).with(:id => 2).returns(field_2)
|
101
|
+
|
102
|
+
assert_equal field_1, comparison.lhs_value
|
103
|
+
assert_equal field_2, comparison.rhs_value
|
104
|
+
end
|
105
|
+
|
106
|
+
test "values are coerced to integer when type is integer" do
|
107
|
+
comparison = new_comparison({
|
108
|
+
:lhs_type => "integer", :raw_lhs_value => "123",
|
109
|
+
:rhs_type => "integer", :raw_rhs_value => "123"
|
110
|
+
}).save!
|
111
|
+
|
112
|
+
assert_equal 123, comparison.raw_lhs_value
|
113
|
+
assert_equal 123, comparison.raw_rhs_value
|
114
|
+
end
|
115
|
+
|
116
|
+
test "fields returns lhs field" do
|
117
|
+
comparison = new_comparison({
|
118
|
+
:lhs_type => "field", :raw_lhs_value => 1,
|
119
|
+
:rhs_type => "integer", :raw_rhs_value => 123
|
120
|
+
}).save!
|
121
|
+
|
122
|
+
field = stub("field")
|
123
|
+
Field.expects(:[]).with(:id => 1).returns(field)
|
124
|
+
assert_equal [field], comparison.fields
|
125
|
+
end
|
126
|
+
|
127
|
+
test "fields returns rhs field" do
|
128
|
+
comparison = new_comparison({
|
129
|
+
:lhs_type => "integer", :raw_lhs_value => 123,
|
130
|
+
:rhs_type => "field", :raw_rhs_value => 1,
|
131
|
+
}).save!
|
132
|
+
|
133
|
+
field = stub("field")
|
134
|
+
Field.expects(:[]).with(:id => 1).returns(field)
|
135
|
+
assert_equal [field], comparison.fields
|
136
|
+
end
|
137
|
+
|
138
|
+
test "fields returns two fields" do
|
139
|
+
comparison = new_comparison({
|
140
|
+
:lhs_type => "field", :raw_lhs_value => 1,
|
141
|
+
:rhs_type => "field", :raw_rhs_value => 2
|
142
|
+
}).save!
|
143
|
+
|
144
|
+
field_1 = stub("field 1")
|
145
|
+
field_2 = stub("field 2")
|
146
|
+
Field.expects(:[]).with(:id => 1).returns(field_1)
|
147
|
+
Field.expects(:[]).with(:id => 2).returns(field_2)
|
148
|
+
assert_equal [field_1, field_2], comparison.fields
|
149
|
+
end
|
150
|
+
|
151
|
+
test "fields returns empty array" do
|
152
|
+
comparison = new_comparison({
|
153
|
+
:lhs_type => "integer", :raw_lhs_value => 123,
|
154
|
+
:rhs_type => "integer", :raw_rhs_value => 123,
|
155
|
+
}).save!
|
156
|
+
assert_equal [], comparison.fields
|
157
|
+
end
|
158
|
+
|
159
|
+
test "operator symbol" do
|
160
|
+
comparison = Comparison.new(:operator => 'equals')
|
161
|
+
assert_equal "=", comparison.operator_symbol
|
162
|
+
comparison.operator = "does_not_equal"
|
163
|
+
assert_equal "!=", comparison.operator_symbol
|
164
|
+
comparison.operator = "greater_than"
|
165
|
+
assert_equal ">", comparison.operator_symbol
|
166
|
+
comparison.operator = "less_than"
|
167
|
+
assert_equal "<", comparison.operator_symbol
|
168
|
+
end
|
169
|
+
|
170
|
+
%w{lhs rhs}.each do |name|
|
171
|
+
test "#{name}_label" do
|
172
|
+
resource = stub("resource", :name => "foo")
|
173
|
+
field = stub("field", :name => "ssn", :resource => resource)
|
174
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
175
|
+
|
176
|
+
comparison = Comparison.new(:"#{name}_type" => 'field', :"raw_#{name}_value" => 1)
|
177
|
+
assert_equal "ssn (foo)", comparison.send("#{name}_label")
|
178
|
+
|
179
|
+
comparison.send("#{name}_which=", 1)
|
180
|
+
assert_equal %{ssn (foo<span class="sup">1</span>)}, comparison.send("#{name}_label")
|
181
|
+
|
182
|
+
comparison.send("#{name}_which=", 2)
|
183
|
+
assert_equal %{ssn (foo<span class="sup">2</span>)}, comparison.send("#{name}_label")
|
184
|
+
|
185
|
+
comparison.send("#{name}_type=", 'integer')
|
186
|
+
comparison.send("raw_#{name}_value=", 123)
|
187
|
+
assert_equal "123", comparison.send("#{name}_label")
|
188
|
+
|
189
|
+
comparison.send("#{name}_type=", 'string')
|
190
|
+
comparison.send("raw_#{name}_value=", 'foo')
|
191
|
+
assert_equal %{"foo"}, comparison.send("#{name}_label")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
test "apply field equality" do
|
196
|
+
comparison = new_comparison({
|
197
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
198
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
199
|
+
:operator => 'equals'
|
200
|
+
}).save!
|
201
|
+
|
202
|
+
field = stub("field", :name => "first_name")
|
203
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
204
|
+
dataset = mock('dataset', :opts => {})
|
205
|
+
dataset.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset)
|
206
|
+
dataset.expects(:filter).with(~{:first_name => nil}).returns(dataset)
|
207
|
+
assert_equal dataset, comparison.apply(dataset)
|
208
|
+
end
|
209
|
+
|
210
|
+
test "apply field equality to one side only" do
|
211
|
+
comparison = new_comparison({
|
212
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
213
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
214
|
+
:operator => 'equals'
|
215
|
+
}).save!
|
216
|
+
|
217
|
+
field = stub("field", :name => "first_name")
|
218
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
219
|
+
dataset_1 = mock('dataset', :opts => {})
|
220
|
+
dataset_1.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset_1)
|
221
|
+
dataset_1.expects(:filter).with(~{:first_name => nil}).returns(dataset_1)
|
222
|
+
dataset_2 = mock('dataset', :opts => {})
|
223
|
+
dataset_2.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset_2)
|
224
|
+
dataset_2.expects(:filter).with(~{:first_name => nil}).returns(dataset_2)
|
225
|
+
|
226
|
+
assert_equal dataset_1, comparison.apply(dataset_1, 0)
|
227
|
+
assert_equal dataset_2, comparison.apply(dataset_2, 1)
|
228
|
+
end
|
229
|
+
|
230
|
+
test "apply two field equality" do
|
231
|
+
comparison = new_comparison({
|
232
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
233
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 2,
|
234
|
+
:operator => 'equals'
|
235
|
+
}).save!
|
236
|
+
|
237
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
238
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
239
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
240
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
241
|
+
dataset = mock('dataset', :opts => {})
|
242
|
+
dataset.expects(:clone).with({:select => [:ssn_1, :ssn_2], :order => [:ssn_1, :ssn_2]}).returns(dataset)
|
243
|
+
dataset.expects(:filter).with(~{:ssn_1 => nil}, ~{:ssn_2 => nil}).returns(dataset)
|
244
|
+
assert_equal dataset, comparison.apply(dataset)
|
245
|
+
end
|
246
|
+
|
247
|
+
test "apply two field equality to one side only" do
|
248
|
+
comparison = new_comparison({
|
249
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
250
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 2,
|
251
|
+
:operator => 'equals'
|
252
|
+
}).save!
|
253
|
+
|
254
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
255
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
256
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
257
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
258
|
+
dataset_1 = mock('dataset', :opts => {})
|
259
|
+
dataset_1.expects(:clone).with({:select => [:ssn_1], :order => [:ssn_1]}).returns(dataset_1)
|
260
|
+
dataset_1.expects(:filter).with(~{:ssn_1 => nil}).returns(dataset_1)
|
261
|
+
dataset_2 = mock('dataset', :opts => {})
|
262
|
+
dataset_2.expects(:clone).with({:select => [:ssn_2], :order => [:ssn_2]}).returns(dataset_2)
|
263
|
+
dataset_2.expects(:filter).with(~{:ssn_2 => nil}).returns(dataset_2)
|
264
|
+
|
265
|
+
assert_equal dataset_1, comparison.apply(dataset_1, 0)
|
266
|
+
assert_equal dataset_2, comparison.apply(dataset_2, 1)
|
267
|
+
end
|
268
|
+
|
269
|
+
=begin
|
270
|
+
def test_apply_field_inequality_to_single_dataset
|
271
|
+
field = stub("field", :name => 'first_name')
|
272
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
273
|
+
comparison = new_comparison({
|
274
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
275
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
276
|
+
:operator => 'does_not_equal'
|
277
|
+
}).save!
|
278
|
+
dataset = mock('dataset', :opts => {})
|
279
|
+
dataset.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset)
|
280
|
+
dataset.expects(:filter).with(~{:first_name => nil}).returns(dataset)
|
281
|
+
assert_equal dataset, comparison.apply(dataset)
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_apply_field_inequality_to_dual_datasets
|
285
|
+
field = stub("field", :name => 'first_name')
|
286
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
287
|
+
comparison = new_comparison({
|
288
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
289
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
290
|
+
:operator => 'does_not_equal'
|
291
|
+
}).save!
|
292
|
+
dataset_1 = mock('dataset_1', :opts => {})
|
293
|
+
dataset_1.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset_1)
|
294
|
+
dataset_1.expects(:filter).with(~{:first_name => nil}).returns(dataset_1)
|
295
|
+
dataset_2 = mock('dataset_2', :opts => {})
|
296
|
+
dataset_2.expects(:clone).with({:select => [:first_name], :order => [:first_name]}).returns(dataset_2)
|
297
|
+
dataset_2.expects(:filter).with(~{:first_name => nil}).returns(dataset_2)
|
298
|
+
assert_equal [dataset_1, dataset_2], comparison.apply(dataset_1, dataset_2)
|
299
|
+
end
|
300
|
+
=end
|
301
|
+
|
302
|
+
test "apply same row field equality indifferently" do
|
303
|
+
comparison_1 = new_comparison({
|
304
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
305
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 1,
|
306
|
+
:operator => 'equals'
|
307
|
+
}).save!
|
308
|
+
comparison_2 = new_comparison({
|
309
|
+
:lhs_type => 'field', :raw_lhs_value => 2, :lhs_which => 2,
|
310
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
311
|
+
:operator => 'equals'
|
312
|
+
}).save!
|
313
|
+
|
314
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
315
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
316
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
317
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
318
|
+
dataset = mock('dataset')
|
319
|
+
|
320
|
+
dataset.expects(:filter).with(sequel_expr(:ssn_1 => :ssn_2)).returns(dataset)
|
321
|
+
assert_equal dataset, comparison_1.apply(dataset)
|
322
|
+
|
323
|
+
dataset.expects(:filter).with(sequel_expr(:ssn_2 => :ssn_1)).returns(dataset)
|
324
|
+
assert_equal dataset, comparison_2.apply(dataset)
|
325
|
+
end
|
326
|
+
|
327
|
+
test "apply same row field equality to one side only" do
|
328
|
+
comparison_1 = new_comparison({
|
329
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
330
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 1,
|
331
|
+
:operator => 'equals'
|
332
|
+
}).save!
|
333
|
+
comparison_2 = new_comparison({
|
334
|
+
:lhs_type => 'field', :raw_lhs_value => 2, :lhs_which => 2,
|
335
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
336
|
+
:operator => 'equals'
|
337
|
+
}).save!
|
338
|
+
|
339
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
340
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
341
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
342
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
343
|
+
dataset_1 = mock('dataset')
|
344
|
+
dataset_2 = mock('dataset')
|
345
|
+
|
346
|
+
dataset_1.expects(:filter).with(sequel_expr(:ssn_1 => :ssn_2)).returns(dataset_1)
|
347
|
+
assert_equal dataset_1, comparison_1.apply(dataset_1, 0)
|
348
|
+
dataset_1.expects(:filter).never
|
349
|
+
assert_equal dataset_1, comparison_2.apply(dataset_1, 0)
|
350
|
+
|
351
|
+
dataset_2.expects(:filter).never
|
352
|
+
assert_equal dataset_2, comparison_1.apply(dataset_2, 1)
|
353
|
+
dataset_2.expects(:filter).with(sequel_expr(:ssn_2 => :ssn_1)).returns(dataset_2)
|
354
|
+
assert_equal dataset_2, comparison_2.apply(dataset_2, 1)
|
355
|
+
end
|
356
|
+
|
357
|
+
#=begin
|
358
|
+
#def test_apply_field_greater_than_field
|
359
|
+
#field_1 = @resource.fields_dataset[:name => 'first_name']
|
360
|
+
#field_2 = @resource.fields_dataset[:name => 'last_name']
|
361
|
+
#comparison = new_comparison({
|
362
|
+
#:lhs_type => 'field', :raw_lhs_value => field_1.id, :lhs_which => 1,
|
363
|
+
#:rhs_type => 'field', :raw_rhs_value => field_2.id, :rhs_which => 2,
|
364
|
+
#:operator => 'greater_than'
|
365
|
+
#}).save!
|
366
|
+
#dataset = mock('dataset', :opts => {})
|
367
|
+
#dataset.expects(:clone).with({:select => [:first_name, :last_name]}).returns(dataset)
|
368
|
+
#dataset.expects(:filter).with(~{:first_name => nil}, ~{:last_name => nil}).returns(dataset)
|
369
|
+
#assert_equal dataset, comparison.apply(dataset)
|
370
|
+
#end
|
371
|
+
#=end
|
372
|
+
|
373
|
+
test "apply does not duplicate selects or orders" do
|
374
|
+
comparison = new_comparison({
|
375
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
376
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 2,
|
377
|
+
:operator => 'equals'
|
378
|
+
}).save!
|
379
|
+
|
380
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
381
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
382
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
383
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
384
|
+
dataset = mock('dataset', :opts => { :order => [:ssn_1], :select => [:foo, :ssn_1] })
|
385
|
+
dataset.expects(:clone).with({:select => [:foo, :ssn_1, :ssn_2], :order => [:ssn_1, :ssn_2]}).returns(dataset)
|
386
|
+
dataset.expects(:filter).with(~{:ssn_2 => nil}).returns(dataset)
|
387
|
+
assert_equal dataset, comparison.apply(dataset)
|
388
|
+
end
|
389
|
+
|
390
|
+
test "apply field equals non field indifferently" do
|
391
|
+
comparison_1 = new_comparison({
|
392
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
393
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
394
|
+
:operator => 'equals'
|
395
|
+
}).save!
|
396
|
+
comparison_2 = new_comparison({
|
397
|
+
:lhs_type => 'field', :raw_lhs_value => 2, :lhs_which => 2,
|
398
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
399
|
+
:operator => 'equals'
|
400
|
+
}).save!
|
401
|
+
|
402
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
403
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
404
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
405
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
406
|
+
dataset = mock('dataset')
|
407
|
+
dataset.expects(:filter).with(sequel_expr({:ssn_1 => 123})).returns(dataset)
|
408
|
+
assert_equal dataset, comparison_1.apply(dataset)
|
409
|
+
dataset.expects(:filter).with(sequel_expr({:ssn_2 => 123})).returns(dataset)
|
410
|
+
assert_equal dataset, comparison_2.apply(dataset)
|
411
|
+
end
|
412
|
+
|
413
|
+
test "apply field equals non field to one side only" do
|
414
|
+
comparison_1 = new_comparison({
|
415
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
416
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
417
|
+
:operator => 'equals'
|
418
|
+
}).save!
|
419
|
+
comparison_2 = new_comparison({
|
420
|
+
:lhs_type => 'field', :raw_lhs_value => 2, :lhs_which => 2,
|
421
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
422
|
+
:operator => 'equals'
|
423
|
+
}).save!
|
424
|
+
|
425
|
+
field_1 = stub("field 1", :name => 'ssn_1')
|
426
|
+
field_2 = stub("field 2", :name => 'ssn_2')
|
427
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
428
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
429
|
+
dataset_1 = mock('dataset 1')
|
430
|
+
dataset_2 = mock('dataset 2')
|
431
|
+
|
432
|
+
dataset_1.expects(:filter).with(sequel_expr({:ssn_1 => 123})).returns(dataset_1)
|
433
|
+
assert_equal dataset_1, comparison_1.apply(dataset_1, 0)
|
434
|
+
dataset_1.expects(:filter).never
|
435
|
+
assert_equal dataset_1, comparison_2.apply(dataset_1, 0)
|
436
|
+
|
437
|
+
dataset_2.expects(:filter).never
|
438
|
+
assert_equal dataset_2, comparison_1.apply(dataset_2, 1)
|
439
|
+
dataset_2.expects(:filter).with(sequel_expr({:ssn_2 => 123})).returns(dataset_2)
|
440
|
+
assert_equal dataset_2, comparison_2.apply(dataset_2, 1)
|
441
|
+
end
|
442
|
+
|
443
|
+
test "apply non field equals field" do
|
444
|
+
field = stub("field", :name => 'first_name')
|
445
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
446
|
+
comparison = new_comparison({
|
447
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
448
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 1,
|
449
|
+
:operator => 'equals'
|
450
|
+
}).save!
|
451
|
+
dataset = mock('dataset')
|
452
|
+
dataset.expects(:filter).with(sequel_expr({123 => :first_name})).returns(dataset)
|
453
|
+
assert_equal dataset, comparison.apply(dataset)
|
454
|
+
end
|
455
|
+
|
456
|
+
test "apply field does not equal non field" do
|
457
|
+
field = stub("field", :name => 'first_name')
|
458
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
459
|
+
comparison = new_comparison({
|
460
|
+
:lhs_type => 'field', :raw_lhs_value => 1,
|
461
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
462
|
+
:operator => 'does_not_equal'
|
463
|
+
}).save!
|
464
|
+
dataset = mock('dataset')
|
465
|
+
dataset.expects(:filter).with(sequel_expr(~{:first_name => 123})).returns(dataset)
|
466
|
+
assert_equal dataset, comparison.apply(dataset)
|
467
|
+
end
|
468
|
+
|
469
|
+
test "apply non field does not equal field" do
|
470
|
+
field = stub("field", :name => 'first_name')
|
471
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
472
|
+
comparison = new_comparison({
|
473
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
474
|
+
:rhs_type => 'field', :raw_rhs_value => 1,
|
475
|
+
:operator => 'does_not_equal'
|
476
|
+
}).save!
|
477
|
+
dataset = mock('dataset')
|
478
|
+
dataset.expects(:filter).with(sequel_expr(~{123 => :first_name})).returns(dataset)
|
479
|
+
assert_equal dataset, comparison.apply(dataset)
|
480
|
+
end
|
481
|
+
|
482
|
+
test "apply field greater than non field" do
|
483
|
+
field = stub("field", :name => 'first_name')
|
484
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
485
|
+
comparison = new_comparison({
|
486
|
+
:lhs_type => 'field', :raw_lhs_value => 1,
|
487
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
488
|
+
:operator => 'greater_than'
|
489
|
+
}).save!
|
490
|
+
dataset = mock('dataset')
|
491
|
+
dataset.expects(:filter).with(sequel_expr(:first_name > 123)).returns(dataset)
|
492
|
+
assert_equal dataset, comparison.apply(dataset)
|
493
|
+
end
|
494
|
+
|
495
|
+
test "apply non field greater than field" do
|
496
|
+
field = stub("field", :name => 'first_name')
|
497
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
498
|
+
comparison = new_comparison({
|
499
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
500
|
+
:rhs_type => 'field', :raw_rhs_value => 1,
|
501
|
+
:operator => 'greater_than'
|
502
|
+
}).save!
|
503
|
+
dataset = mock('dataset')
|
504
|
+
dataset.expects(:filter).with(sequel_expr(:'>', 123, :first_name)).returns(dataset)
|
505
|
+
assert_equal dataset, comparison.apply(dataset)
|
506
|
+
end
|
507
|
+
|
508
|
+
test "apply field less than non field" do
|
509
|
+
field = stub("field", :name => 'first_name')
|
510
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
511
|
+
comparison = new_comparison({
|
512
|
+
:lhs_type => 'field', :raw_lhs_value => 1,
|
513
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
514
|
+
:operator => 'less_than'
|
515
|
+
}).save!
|
516
|
+
dataset = mock('dataset')
|
517
|
+
dataset.expects(:filter).with(sequel_expr(:first_name < 123)).returns(dataset)
|
518
|
+
assert_equal dataset, comparison.apply(dataset)
|
519
|
+
end
|
520
|
+
|
521
|
+
test "apply non field less than field" do
|
522
|
+
field = stub("field", :name => 'first_name')
|
523
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
524
|
+
comparison = new_comparison({
|
525
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
526
|
+
:rhs_type => 'field', :raw_rhs_value => 1,
|
527
|
+
:operator => 'less_than'
|
528
|
+
}).save!
|
529
|
+
dataset = mock('dataset')
|
530
|
+
dataset.expects(:filter).with(Sequel::SQL::BooleanExpression.new(:'<', 123, :first_name)).returns(dataset)
|
531
|
+
assert_equal dataset, comparison.apply(dataset)
|
532
|
+
end
|
533
|
+
|
534
|
+
test "apply non field equal non field" do
|
535
|
+
comparison = new_comparison({
|
536
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
537
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
538
|
+
:operator => 'equals'
|
539
|
+
}).save!
|
540
|
+
dataset = mock('dataset')
|
541
|
+
dataset.expects(:filter).with(sequel_expr(123 => 123)).returns(dataset)
|
542
|
+
assert_equal dataset, comparison.apply(dataset)
|
543
|
+
end
|
544
|
+
|
545
|
+
test "apply non field equal non field regardless of side" do
|
546
|
+
comparison = new_comparison({
|
547
|
+
:lhs_type => 'integer', :raw_lhs_value => 123,
|
548
|
+
:rhs_type => 'integer', :raw_rhs_value => 123,
|
549
|
+
:operator => 'equals'
|
550
|
+
}).save!
|
551
|
+
dataset_1 = mock('dataset 1')
|
552
|
+
dataset_2 = mock('dataset 2')
|
553
|
+
|
554
|
+
dataset_1.expects(:filter).with(sequel_expr(123 => 123)).returns(dataset_1)
|
555
|
+
assert_equal dataset_1, comparison.apply(dataset_1, 0)
|
556
|
+
dataset_2.expects(:filter).with(sequel_expr(123 => 123)).returns(dataset_2)
|
557
|
+
assert_equal dataset_2, comparison.apply(dataset_2, 1)
|
558
|
+
end
|
559
|
+
|
560
|
+
test "blocking?" do
|
561
|
+
field = stub("field", :name => 'first_name') {
|
562
|
+
stubs(:[]).with(:type).returns('string')
|
563
|
+
}
|
564
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
565
|
+
comparison = new_comparison({
|
566
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
567
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
568
|
+
:operator => 'equals'
|
569
|
+
}).save!
|
570
|
+
assert !comparison.blocking?
|
571
|
+
end
|
572
|
+
|
573
|
+
test "cross_match?" do
|
574
|
+
field_1 = stub("field 1", :id => 1, :name => 'ssn_1', :resource_id => 1) {
|
575
|
+
stubs(:[]).with(:type).returns('string')
|
576
|
+
}
|
577
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
578
|
+
field_2 = stub("field 2", :id => 2, :name => 'ssn_2', :resource_id => 1) {
|
579
|
+
stubs(:[]).with(:type).returns('string')
|
580
|
+
}
|
581
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
582
|
+
comparison = new_comparison({
|
583
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
584
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 2,
|
585
|
+
:operator => 'equals'
|
586
|
+
}).save!
|
587
|
+
assert comparison.cross_match?
|
588
|
+
end
|
589
|
+
|
590
|
+
test "does not allow two fields of different types" do
|
591
|
+
field_1 = stub("field 1", :name => 'first_name') {
|
592
|
+
stubs(:[]).with(:type).returns('string')
|
593
|
+
}
|
594
|
+
Field.stubs(:[]).with(:id => 1).returns(field_1)
|
595
|
+
field_2 = stub("field 2", :name => 'age') {
|
596
|
+
stubs(:[]).with(:type).returns('integer')
|
597
|
+
}
|
598
|
+
Field.stubs(:[]).with(:id => 2).returns(field_2)
|
599
|
+
comparison = new_comparison({
|
600
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
601
|
+
:rhs_type => 'field', :raw_rhs_value => 2, :rhs_which => 2,
|
602
|
+
:operator => 'equals'
|
603
|
+
})
|
604
|
+
assert !comparison.valid?, "Comparison should have been invalid"
|
605
|
+
end
|
606
|
+
|
607
|
+
test "does not allow non-equality comparisons for fields" do
|
608
|
+
field = stub("field", :name => 'first_name') { stubs(:[]).with(:type).returns('string') }
|
609
|
+
Field.stubs(:[]).with(:id => 1).returns(field)
|
610
|
+
comparison = new_comparison({
|
611
|
+
:lhs_type => 'field', :raw_lhs_value => 1, :lhs_which => 1,
|
612
|
+
:rhs_type => 'field', :raw_rhs_value => 1, :rhs_which => 2,
|
613
|
+
:operator => 'greater_than'
|
614
|
+
})
|
615
|
+
assert !comparison.valid?, "Comparison should have been invalid"
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end
|
619
|
+
end
|