surveyor 0.22.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +83 -0
- data/Gemfile.rails_version +7 -1
- data/README.md +114 -16
- data/Rakefile +15 -9
- data/app/inputs/quiet_input.rb +5 -0
- data/app/inputs/surveyor_check_boxes_input.rb +35 -0
- data/app/inputs/surveyor_radio_input.rb +18 -0
- data/app/views/partials/_answer.html.haml +4 -4
- data/app/views/partials/_question.html.haml +7 -7
- data/app/views/partials/_question_group.html.haml +9 -8
- data/app/views/surveyor/export.json.rabl +28 -25
- data/app/views/surveyor/new.html.haml +8 -5
- data/app/views/surveyor/show.json.rabl +3 -2
- data/ci-exec.sh +13 -7
- data/cucumber.yml +3 -3
- data/doc/REPRESENTATIONS.md +34 -0
- data/doc/api_id_schema.json +7 -0
- data/doc/response_set_schema.json +54 -0
- data/doc/surveyor question combinations.png +0 -0
- data/doc/surveyor_timestamp_schema.json +9 -0
- data/features/ajax_submissions.feature +140 -0
- data/features/export_to_json.feature +182 -34
- data/features/no_duplicates.feature +110 -0
- data/features/show_survey.feature +1 -1
- data/features/step_definitions/parser_steps.rb +25 -2
- data/features/step_definitions/surveyor_steps.rb +145 -20
- data/features/step_definitions/ui_steps.rb +3 -0
- data/features/support/database_cleaner.rb +16 -0
- data/features/support/env.rb +21 -17
- data/features/support/simultaneous_ajax.rb +101 -0
- data/features/support/single_quit_selenium_driver.rb +23 -0
- data/features/support/slow_updates.rb +18 -0
- data/features/surveyor.feature +174 -44
- data/features/surveyor_dependencies.feature +80 -39
- data/features/surveyor_parser.feature +114 -20
- data/features/z_redcap_parser.feature +0 -1
- data/lib/{generators/surveyor/templates/public → assets}/images/surveyor/next.gif +0 -0
- data/lib/{generators/surveyor/templates/public → assets}/images/surveyor/prev.gif +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/lib/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-icons_ef8c08_256x240.png +0 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/surveyor → assets/images}/ui-icons_ffffff_256x240.png +0 -0
- data/lib/{generators/surveyor/templates/public → assets}/javascripts/surveyor/jquery-ui-timepicker-addon.js +23 -23
- data/lib/{generators/surveyor/templates/public → assets}/javascripts/surveyor/jquery-ui.js +125 -125
- data/lib/assets/javascripts/surveyor/jquery.selectToUISlider.js +240 -0
- data/lib/{generators/surveyor/templates/public → assets}/javascripts/surveyor/jquery.surveyor.js +52 -57
- data/lib/{generators/surveyor/templates/public → assets}/javascripts/surveyor/jquery.tools.min.js +7 -7
- data/lib/{generators/surveyor/templates/public → assets}/stylesheets/surveyor/dateinput.css +13 -13
- data/lib/{generators/surveyor/templates/public → assets}/stylesheets/surveyor/jquery-ui-timepicker-addon.css +0 -0
- data/lib/{generators/surveyor/templates/public → assets}/stylesheets/surveyor/jquery-ui.custom.css +17 -17
- data/lib/{generators/surveyor/templates/public → assets}/stylesheets/surveyor/reset.css +1 -1
- data/lib/{generators/surveyor/templates/public → assets}/stylesheets/surveyor/results.css +0 -0
- data/lib/assets/stylesheets/surveyor/ui.slider.extras.css +110 -0
- data/lib/{generators/surveyor/templates/public/stylesheets/sass → assets/stylesheets}/surveyor.sass +15 -7
- data/lib/generators/surveyor/custom_generator.rb +3 -2
- data/lib/generators/surveyor/install_generator.rb +59 -17
- data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +5 -0
- data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +9 -0
- data/lib/generators/surveyor/templates/app/controllers/surveyor_controller.rb +2 -1
- data/lib/generators/surveyor/templates/app/views/layouts/surveyor_custom.html.erb +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_es.yml +1 -0
- data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_id_to_question_groups.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_api_ids_to_response_sets_and_responses.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_correct_answer_id_to_questions.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_default_value_to_answers.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_order_to_surveys.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_display_type_to_answers.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_response_sets.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_index_to_surveys.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_section_id_to_responses.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_index_on_access_code_and_version_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/add_unique_indicies.rb +3 -2
- data/lib/generators/surveyor/templates/db/migrate/add_version_to_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/api_ids_must_be_unique.rb +23 -0
- data/lib/generators/surveyor/templates/db/migrate/create_answers.rb +6 -5
- data/lib/generators/surveyor/templates/db/migrate/create_dependencies.rb +2 -1
- data/lib/generators/surveyor/templates/db/migrate/create_dependency_conditions.rb +2 -1
- data/lib/generators/surveyor/templates/db/migrate/create_question_groups.rb +5 -4
- data/lib/generators/surveyor/templates/db/migrate/create_questions.rb +4 -3
- data/lib/generators/surveyor/templates/db/migrate/create_response_sets.rb +1 -0
- data/lib/generators/surveyor/templates/db/migrate/create_responses.rb +10 -9
- data/lib/generators/surveyor/templates/db/migrate/create_survey_sections.rb +5 -4
- data/lib/generators/surveyor/templates/db/migrate/create_surveys.rb +4 -3
- data/lib/generators/surveyor/templates/db/migrate/create_validation_conditions.rb +5 -4
- data/lib/generators/surveyor/templates/db/migrate/create_validations.rb +3 -2
- data/lib/generators/surveyor/templates/db/migrate/drop_unique_index_on_access_code_in_surveys.rb +10 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb +22 -0
- data/lib/generators/surveyor/templates/db/migrate/update_blank_versions_on_surveys.rb +13 -0
- data/lib/generators/surveyor/templates/surveys/date_survey.rb +1 -0
- data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +54 -24
- data/lib/generators/surveyor/templates/surveys/quiz.rb +1 -0
- data/lib/generators/surveyor/templates/{public/stylesheets/sass → vendor/assets/stylesheets}/custom.sass +1 -1
- data/lib/surveyor/common.rb +16 -31
- data/lib/surveyor/engine.rb +2 -4
- data/lib/surveyor/helpers/asset_pipeline.rb +13 -0
- data/lib/surveyor/helpers/formtastic_custom_input.rb +17 -0
- data/lib/surveyor/helpers/surveyor_helper_methods.rb +10 -8
- data/lib/surveyor/models/answer_methods.rb +3 -0
- data/lib/surveyor/models/dependency_condition_methods.rb +27 -28
- data/lib/surveyor/models/dependency_methods.rb +3 -0
- data/lib/surveyor/models/question_group_methods.rb +3 -0
- data/lib/surveyor/models/question_methods.rb +10 -7
- data/lib/surveyor/models/response_methods.rb +16 -0
- data/lib/surveyor/models/response_set_methods.rb +71 -64
- data/lib/surveyor/models/survey_methods.rb +19 -28
- data/lib/surveyor/models/survey_section_methods.rb +3 -0
- data/lib/surveyor/models/validation_condition_methods.rb +4 -2
- data/lib/surveyor/models/validation_methods.rb +3 -0
- data/lib/surveyor/parser.rb +198 -148
- data/lib/surveyor/redcap_parser.rb +120 -80
- data/lib/surveyor/surveyor_controller_methods.rb +86 -37
- data/lib/surveyor/version.rb +2 -2
- data/lib/surveyor.rb +5 -6
- data/lib/tasks/surveyor_tasks.rake +19 -7
- data/spec/controllers/surveyor_controller_spec.rb +166 -92
- data/spec/factories.rb +33 -32
- data/spec/helpers/formtastic_custom_input_spec.rb +16 -0
- data/spec/lib/common_spec.rb +0 -39
- data/spec/lib/redcap_parser_spec.rb +24 -24
- data/spec/models/answer_spec.rb +12 -0
- data/spec/models/dependency_condition_spec.rb +279 -323
- data/spec/models/dependency_spec.rb +10 -0
- data/spec/models/question_group_spec.rb +12 -0
- data/spec/models/question_spec.rb +12 -0
- data/spec/models/response_set_spec.rb +189 -139
- data/spec/models/response_spec.rb +60 -0
- data/spec/models/survey_section_spec.rb +9 -0
- data/spec/models/survey_spec.rb +72 -9
- data/spec/models/validation_condition_spec.rb +9 -1
- data/spec/models/validation_spec.rb +10 -0
- data/spec/spec_helper.rb +25 -6
- data/surveyor.gemspec +5 -4
- metadata +332 -291
- data/features/step_definitions/common_steps.rb +0 -3
- data/lib/formtastic/surveyor_builder.rb +0 -82
- data/lib/generators/surveyor/templates/public/javascripts/surveyor/jquery.blockUI.js +0 -499
@@ -12,7 +12,7 @@ describe DependencyCondition do
|
|
12
12
|
before(:each) do
|
13
13
|
@dependency_condition = DependencyCondition.new(
|
14
14
|
:dependency_id => 1, :question_id => 45, :operator => "==",
|
15
|
-
:answer_id => 23, :rule_key => "
|
15
|
+
:answer_id => 23, :rule_key => "A")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should be valid" do
|
@@ -43,8 +43,8 @@ describe DependencyCondition do
|
|
43
43
|
@dependency_condition.should be_valid
|
44
44
|
DependencyCondition.create(
|
45
45
|
:dependency_id => 2, :question_id => 46, :operator => "==",
|
46
|
-
:answer_id => 14, :rule_key => "
|
47
|
-
@dependency_condition.rule_key = "
|
46
|
+
:answer_id => 14, :rule_key => "B")
|
47
|
+
@dependency_condition.rule_key = "B" # rule key uniquness is scoped by dependency_id
|
48
48
|
@dependency_condition.dependency_id = 2
|
49
49
|
@dependency_condition.should_not be_valid
|
50
50
|
@dependency_condition.should have(1).errors_on(:rule_key)
|
@@ -59,378 +59,334 @@ describe DependencyCondition do
|
|
59
59
|
@dependency_condition.should have(1).error_on(:operator)
|
60
60
|
end
|
61
61
|
|
62
|
-
it "should
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@
|
70
|
-
tap { |a| a.id = 55 }
|
71
|
-
|
72
|
-
@dependency_condition.is_met?([@alt_response]).should be_false
|
62
|
+
it "should protect timestamps" do
|
63
|
+
saved_attrs = @dependency_condition.attributes
|
64
|
+
if defined? ActiveModel::MassAssignmentSecurity::Error
|
65
|
+
lambda {@dependency_condition.update_attributes(:created_at => 3.days.ago, :updated_at => 3.hours.ago)}.should raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
66
|
+
else
|
67
|
+
@dependency_condition.attributes = {:created_at => 3.days.ago, :updated_at => 3.hours.ago} # automatically protected by Rails
|
68
|
+
end
|
69
|
+
@dependency_condition.attributes.should == saved_attrs
|
73
70
|
end
|
74
71
|
|
75
|
-
it "converts to a hash for evaluation by the dependency object" do
|
76
|
-
@response = Response.new(:question_id => 45, :response_set_id => 40, :answer_id => 23)
|
77
|
-
@rs = mock(ResponseSet, :responses => [@response])
|
78
|
-
@dependency_condition.stub!(:is_met?).and_return(true)
|
79
|
-
@dependency_condition.to_hash(@rs)
|
80
|
-
end
|
81
72
|
end
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
Factory(:dependency_condition, :rule_key => "A", :question => @question)
|
89
|
-
@rs = Factory(:response_set)
|
90
|
-
@response =
|
91
|
-
Factory(:response, :question => @question, :answer => @answer, :response_set => @rs)
|
92
|
-
@rs.responses << @response
|
93
|
-
@rs.save!
|
94
|
-
end
|
95
|
-
|
96
|
-
it "converts unmet condition to {:A => false}" do
|
97
|
-
@dependency_condition.stub!(:is_met?).and_return(false)
|
98
|
-
@dependency_condition.to_hash(@rs).should == {:A => false}
|
99
|
-
end
|
100
|
-
|
101
|
-
it "converts met condition to {:A => true}" do
|
102
|
-
@dependency_condition.stub!(:is_met?).and_return(true)
|
103
|
-
@dependency_condition.to_hash(@rs).should == {:A => true}
|
104
|
-
end
|
105
|
-
|
106
|
-
it "converts unanswered condition to {:A => false}" do
|
107
|
-
question = Factory(:question)
|
108
|
-
dependency_condition =
|
109
|
-
Factory(:dependency_condition, :rule_key => "A", :question => @question)
|
110
|
-
rs = Factory(:response_set)
|
111
|
-
dependency_condition.to_hash(rs).should == {:A => false}
|
112
|
-
end
|
74
|
+
it "returns true for != with no responses" do
|
75
|
+
question = Factory(:question)
|
76
|
+
dependency_condition = Factory(:dependency_condition, :rule_key => "C", :question => question)
|
77
|
+
rs = Factory(:response_set)
|
78
|
+
dependency_condition.to_hash(rs).should == {:C => false}
|
113
79
|
end
|
114
80
|
|
115
|
-
describe "
|
81
|
+
describe "evaluate '==' operator" do
|
116
82
|
before(:each) do
|
117
|
-
@
|
118
|
-
|
119
|
-
@
|
120
|
-
@
|
121
|
-
@
|
122
|
-
@
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
@
|
136
|
-
@
|
137
|
-
@
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@
|
145
|
-
@
|
146
|
-
@
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
@
|
154
|
-
@
|
155
|
-
@
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@
|
163
|
-
@
|
164
|
-
@
|
165
|
-
@dep_c.is_met?([@response]).should be_true
|
166
|
-
@response.float_value = 130.123
|
167
|
-
@dep_c.is_met?([@response]).should be_false
|
83
|
+
@a = Factory(:answer)
|
84
|
+
@b = Factory(:answer, :question => @a.question)
|
85
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
86
|
+
@rs = @r.response_set
|
87
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "==", :rule_key => "D")
|
88
|
+
@dc.as(:answer).should == @r.as(:answer)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "with checkbox/radio type response" do
|
92
|
+
@dc.to_hash(@rs).should == {:D => true}
|
93
|
+
@dc.answer = @b
|
94
|
+
@dc.to_hash(@rs).should == {:D => false}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "with string value response" do
|
98
|
+
@a.update_attributes(:response_class => "string")
|
99
|
+
@r.update_attributes(:string_value => "hello123")
|
100
|
+
@dc.string_value = "hello123"
|
101
|
+
@dc.to_hash(@rs).should == {:D => true}
|
102
|
+
@r.update_attributes(:string_value => "foo_abc")
|
103
|
+
@dc.to_hash(@rs).should == {:D => false}
|
104
|
+
end
|
105
|
+
|
106
|
+
it "with a text value response" do
|
107
|
+
@a.update_attributes(:response_class => "text")
|
108
|
+
@r.update_attributes(:text_value => "hello this is some text for comparison")
|
109
|
+
@dc.text_value = "hello this is some text for comparison"
|
110
|
+
@dc.to_hash(@rs).should == {:D => true}
|
111
|
+
@r.update_attributes(:text_value => "Not the same text")
|
112
|
+
@dc.to_hash(@rs).should == {:D => false}
|
113
|
+
end
|
114
|
+
|
115
|
+
it "with an integer value response" do
|
116
|
+
@a.update_attributes(:response_class => "integer")
|
117
|
+
@r.update_attributes(:integer_value => 10045)
|
118
|
+
@dc.integer_value = 10045
|
119
|
+
@dc.to_hash(@rs).should == {:D => true}
|
120
|
+
@r.update_attributes(:integer_value => 421)
|
121
|
+
@dc.to_hash(@rs).should == {:D => false}
|
122
|
+
end
|
123
|
+
|
124
|
+
it "with a float value response" do
|
125
|
+
@a.update_attributes(:response_class => "float")
|
126
|
+
@r.update_attributes(:float_value => 121.1)
|
127
|
+
@dc.float_value = 121.1
|
128
|
+
@dc.to_hash(@rs).should == {:D => true}
|
129
|
+
@r.update_attributes(:float_value => 130.123)
|
130
|
+
@dc.to_hash(@rs).should == {:D => false}
|
168
131
|
end
|
169
132
|
end
|
170
133
|
|
171
|
-
describe "
|
134
|
+
describe "evaluate '!=' operator" do
|
172
135
|
before(:each) do
|
173
|
-
@
|
174
|
-
|
175
|
-
@
|
176
|
-
@
|
177
|
-
@
|
178
|
-
@
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
@
|
192
|
-
@
|
193
|
-
@
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@
|
201
|
-
@
|
202
|
-
@
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
@
|
210
|
-
@
|
211
|
-
@
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
@
|
219
|
-
@
|
220
|
-
@
|
221
|
-
@dep_c.is_met?([@response]).should be_false
|
222
|
-
@response.float_value = 130.123
|
223
|
-
@dep_c.is_met?([@response]).should be_true
|
136
|
+
@a = Factory(:answer)
|
137
|
+
@b = Factory(:answer, :question => @a.question)
|
138
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
139
|
+
@rs = @r.response_set
|
140
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "!=", :rule_key => "E")
|
141
|
+
@dc.as(:answer).should == @r.as(:answer)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "with checkbox/radio type response" do
|
145
|
+
@dc.to_hash(@rs).should == {:E => false}
|
146
|
+
@dc.answer_id = @a.id.to_i+1
|
147
|
+
@dc.to_hash(@rs).should == {:E => true}
|
148
|
+
end
|
149
|
+
|
150
|
+
it "with string value response" do
|
151
|
+
@a.update_attributes(:response_class => "string")
|
152
|
+
@r.update_attributes(:string_value => "hello123")
|
153
|
+
@dc.string_value = "hello123"
|
154
|
+
@dc.to_hash(@rs).should == {:E => false}
|
155
|
+
@r.update_attributes(:string_value => "foo_abc")
|
156
|
+
@dc.to_hash(@rs).should == {:E => true}
|
157
|
+
end
|
158
|
+
|
159
|
+
it "with a text value response" do
|
160
|
+
@a.update_attributes(:response_class => "text")
|
161
|
+
@r.update_attributes(:text_value => "hello this is some text for comparison")
|
162
|
+
@dc.text_value = "hello this is some text for comparison"
|
163
|
+
@dc.to_hash(@rs).should == {:E => false}
|
164
|
+
@r.update_attributes(:text_value => "Not the same text")
|
165
|
+
@dc.to_hash(@rs).should == {:E => true}
|
166
|
+
end
|
167
|
+
|
168
|
+
it "with an integer value response" do
|
169
|
+
@a.update_attributes(:response_class => "integer")
|
170
|
+
@r.update_attributes(:integer_value => 10045)
|
171
|
+
@dc.integer_value = 10045
|
172
|
+
@dc.to_hash(@rs).should == {:E => false}
|
173
|
+
@r.update_attributes(:integer_value => 421)
|
174
|
+
@dc.to_hash(@rs).should == {:E => true}
|
175
|
+
end
|
176
|
+
|
177
|
+
it "with a float value response" do
|
178
|
+
@a.update_attributes(:response_class => "float")
|
179
|
+
@r.update_attributes(:float_value => 121.1)
|
180
|
+
@dc.float_value = 121.1
|
181
|
+
@dc.to_hash(@rs).should == {:E => false}
|
182
|
+
@r.update_attributes(:float_value => 130.123)
|
183
|
+
@dc.to_hash(@rs).should == {:E => true}
|
224
184
|
end
|
225
185
|
end
|
226
186
|
|
227
|
-
describe "
|
187
|
+
describe "evaluate the '<' operator" do
|
228
188
|
before(:each) do
|
229
|
-
@
|
230
|
-
@
|
231
|
-
@
|
232
|
-
@
|
233
|
-
@
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
@
|
239
|
-
@
|
240
|
-
@
|
241
|
-
@
|
242
|
-
@
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
@
|
248
|
-
@
|
249
|
-
@
|
250
|
-
@
|
251
|
-
@
|
189
|
+
@a = Factory(:answer)
|
190
|
+
@b = Factory(:answer, :question => @a.question)
|
191
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
192
|
+
@rs = @r.response_set
|
193
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "<", :rule_key => "F")
|
194
|
+
@dc.as(:answer).should == @r.as(:answer)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "with an integer value response" do
|
198
|
+
@a.update_attributes(:response_class => "integer")
|
199
|
+
@r.update_attributes(:integer_value => 50)
|
200
|
+
@dc.integer_value = 100
|
201
|
+
@dc.to_hash(@rs).should == {:F => true}
|
202
|
+
@r.update_attributes(:integer_value => 421)
|
203
|
+
@dc.to_hash(@rs).should == {:F => false}
|
204
|
+
end
|
205
|
+
|
206
|
+
it "with a float value response" do
|
207
|
+
@a.update_attributes(:response_class => "float")
|
208
|
+
@r.update_attributes(:float_value => 5.1)
|
209
|
+
@dc.float_value = 121.1
|
210
|
+
@dc.to_hash(@rs).should == {:F => true}
|
211
|
+
@r.update_attributes(:float_value => 130.123)
|
212
|
+
@dc.to_hash(@rs).should == {:F => false}
|
252
213
|
end
|
253
214
|
end
|
254
215
|
|
255
|
-
describe "
|
216
|
+
describe "evaluate the '<=' operator" do
|
256
217
|
before(:each) do
|
257
|
-
@
|
258
|
-
@
|
259
|
-
@
|
260
|
-
@
|
261
|
-
@
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
@
|
267
|
-
@
|
268
|
-
@
|
269
|
-
@
|
270
|
-
@
|
271
|
-
@
|
272
|
-
@
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
@
|
278
|
-
@
|
279
|
-
@
|
280
|
-
@
|
281
|
-
@
|
282
|
-
@
|
283
|
-
@
|
218
|
+
@a = Factory(:answer)
|
219
|
+
@b = Factory(:answer, :question => @a.question)
|
220
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
221
|
+
@rs = @r.response_set
|
222
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "<=", :rule_key => "G")
|
223
|
+
@dc.as(:answer).should == @r.as(:answer)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "with an integer value response" do
|
227
|
+
@a.update_attributes(:response_class => "integer")
|
228
|
+
@r.update_attributes(:integer_value => 50)
|
229
|
+
@dc.integer_value = 100
|
230
|
+
@dc.to_hash(@rs).should == {:G => true}
|
231
|
+
@r.update_attributes(:integer_value => 100)
|
232
|
+
@dc.to_hash(@rs).should == {:G => true}
|
233
|
+
@r.update_attributes(:integer_value => 421)
|
234
|
+
@dc.to_hash(@rs).should == {:G => false}
|
235
|
+
end
|
236
|
+
|
237
|
+
it "with a float value response" do
|
238
|
+
@a.update_attributes(:response_class => "float")
|
239
|
+
@r.update_attributes(:float_value => 5.1)
|
240
|
+
@dc.float_value = 121.1
|
241
|
+
@dc.to_hash(@rs).should == {:G => true}
|
242
|
+
@r.update_attributes(:float_value => 121.1)
|
243
|
+
@dc.to_hash(@rs).should == {:G => true}
|
244
|
+
@r.update_attributes(:float_value => 130.123)
|
245
|
+
@dc.to_hash(@rs).should == {:G => false}
|
284
246
|
end
|
285
247
|
|
286
248
|
end
|
287
249
|
|
288
|
-
describe "
|
250
|
+
describe "evaluate the '>' operator" do
|
289
251
|
before(:each) do
|
290
|
-
@
|
291
|
-
@
|
292
|
-
@
|
293
|
-
@
|
294
|
-
@
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
@
|
300
|
-
@
|
301
|
-
@
|
302
|
-
@
|
303
|
-
@
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
@
|
309
|
-
@
|
310
|
-
@
|
311
|
-
@
|
312
|
-
@
|
252
|
+
@a = Factory(:answer)
|
253
|
+
@b = Factory(:answer, :question => @a.question)
|
254
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
255
|
+
@rs = @r.response_set
|
256
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => ">", :rule_key => "H")
|
257
|
+
@dc.as(:answer).should == @r.as(:answer)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "with an integer value response" do
|
261
|
+
@a.update_attributes(:response_class => "integer")
|
262
|
+
@r.update_attributes(:integer_value => 50)
|
263
|
+
@dc.integer_value = 100
|
264
|
+
@dc.to_hash(@rs).should == {:H => false}
|
265
|
+
@r.update_attributes(:integer_value => 421)
|
266
|
+
@dc.to_hash(@rs).should == {:H => true}
|
267
|
+
end
|
268
|
+
|
269
|
+
it "with a float value response" do
|
270
|
+
@a.update_attributes(:response_class => "float")
|
271
|
+
@r.update_attributes(:float_value => 5.1)
|
272
|
+
@dc.float_value = 121.1
|
273
|
+
@dc.to_hash(@rs).should == {:H => false}
|
274
|
+
@r.update_attributes(:float_value => 130.123)
|
275
|
+
@dc.to_hash(@rs).should == {:H => true}
|
313
276
|
end
|
314
277
|
end
|
315
278
|
|
316
|
-
describe "
|
279
|
+
describe "evaluate the '>=' operator" do
|
317
280
|
before(:each) do
|
318
|
-
@
|
319
|
-
@
|
320
|
-
@
|
321
|
-
@
|
322
|
-
@
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
@
|
328
|
-
@
|
329
|
-
@
|
330
|
-
@
|
331
|
-
@
|
332
|
-
@
|
333
|
-
@
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
@
|
339
|
-
@
|
340
|
-
@
|
341
|
-
@
|
342
|
-
@
|
343
|
-
@
|
344
|
-
@
|
281
|
+
@a = Factory(:answer)
|
282
|
+
@b = Factory(:answer, :question => @a.question)
|
283
|
+
@r = Factory(:response, :question => @a.question, :answer => @a)
|
284
|
+
@rs = @r.response_set
|
285
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => ">=", :rule_key => "I")
|
286
|
+
@dc.as(:answer).should == @r.as(:answer)
|
287
|
+
end
|
288
|
+
|
289
|
+
it "with an integer value response" do
|
290
|
+
@a.update_attributes(:response_class => "integer")
|
291
|
+
@r.update_attributes(:integer_value => 50)
|
292
|
+
@dc.integer_value = 100
|
293
|
+
@dc.to_hash(@rs).should == {:I => false}
|
294
|
+
@r.update_attributes(:integer_value => 100)
|
295
|
+
@dc.to_hash(@rs).should == {:I => true}
|
296
|
+
@r.update_attributes(:integer_value => 421)
|
297
|
+
@dc.to_hash(@rs).should == {:I => true}
|
298
|
+
end
|
299
|
+
|
300
|
+
it "with a float value response" do
|
301
|
+
@a.update_attributes(:response_class => "float")
|
302
|
+
@r.update_attributes(:float_value => 5.1)
|
303
|
+
@dc.float_value = 121.1
|
304
|
+
@dc.to_hash(@rs).should == {:I => false}
|
305
|
+
@r.update_attributes(:float_value => 121.1)
|
306
|
+
@dc.to_hash(@rs).should == {:I => true}
|
307
|
+
@r.update_attributes(:float_value => 130.123)
|
308
|
+
@dc.to_hash(@rs).should == {:I => true}
|
345
309
|
end
|
346
310
|
end
|
347
311
|
|
348
|
-
describe "
|
312
|
+
describe "evaluating with response_class string" do
|
349
313
|
it "should compare answer ids when the string_value is nil" do
|
350
|
-
a = Factory(:answer, :response_class => "string")
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
dc.
|
314
|
+
@a = Factory(:answer, :response_class => "string")
|
315
|
+
@b = Factory(:answer, :question => @a.question)
|
316
|
+
@r = Factory(:response, :question => @a.question, :answer => @a, :string_value => "")
|
317
|
+
@rs = @r.response_set
|
318
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "==", :rule_key => "J")
|
319
|
+
@dc.to_hash(@rs).should == {:J => true}
|
356
320
|
end
|
357
321
|
|
358
322
|
it "should compare strings when the string_value is not nil, even if it is blank" do
|
359
|
-
a = Factory(:answer, :response_class => "string")
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
:question_id => a.question.id, :answer_id => a.id, :operator => "==", :string_value => "")
|
370
|
-
r2 = Factory(:response,
|
371
|
-
:question_id => a.question.id, :answer_id => a.id, :string_value => "")
|
372
|
-
r2.should_receive(:as).with("string").and_return("")
|
373
|
-
dc2.is_met?([r2]).should be_true
|
323
|
+
@a = Factory(:answer, :response_class => "string")
|
324
|
+
@b = Factory(:answer, :question => @a.question)
|
325
|
+
@r = Factory(:response, :question => @a.question, :answer => @a, :string_value => "foo")
|
326
|
+
@rs = @r.response_set
|
327
|
+
@dc = Factory(:dependency_condition, :question => @a.question, :answer => @a, :operator => "==", :rule_key => "K", :string_value => "foo")
|
328
|
+
@dc.to_hash(@rs).should == {:K => true}
|
329
|
+
|
330
|
+
@r.update_attributes(:string_value => "")
|
331
|
+
@dc.string_value = ""
|
332
|
+
@dc.to_hash(@rs).should == {:K => true}
|
374
333
|
end
|
375
334
|
end
|
376
335
|
|
377
|
-
describe "
|
336
|
+
describe "evaluate 'count' operator" do
|
378
337
|
before(:each) do
|
379
|
-
@
|
380
|
-
|
381
|
-
@
|
382
|
-
@select_answers = []
|
338
|
+
@q = Factory(:question)
|
339
|
+
@dc = DependencyCondition.new(:operator => "count>2", :rule_key => "M", :question => @q)
|
340
|
+
@as = []
|
383
341
|
3.times do
|
384
|
-
@
|
385
|
-
:response_class => "answer")
|
342
|
+
@as << Factory(:answer, :question => @q, :response_class => "answer")
|
386
343
|
end
|
387
|
-
@
|
388
|
-
@
|
389
|
-
|
390
|
-
:response_set_id => 159)
|
344
|
+
@rs = Factory(:response_set)
|
345
|
+
@as.slice(0,2).each do |a|
|
346
|
+
Factory(:response, :question => @q, :answer => a, :response_set => @rs)
|
391
347
|
end
|
348
|
+
@rs.save
|
392
349
|
end
|
393
350
|
|
394
|
-
it "
|
395
|
-
@
|
396
|
-
@
|
397
|
-
|
398
|
-
|
399
|
-
@dep_c.is_met?(@responses).should be_true
|
351
|
+
it "with operator with >" do
|
352
|
+
@dc.to_hash(@rs).should == {:M => false}
|
353
|
+
Factory(:response, :question => @q, :answer => @as.last, :response_set => @rs)
|
354
|
+
@rs.reload.responses.count.should == 3
|
355
|
+
@dc.to_hash(@rs.reload).should == {:M => true}
|
400
356
|
end
|
401
357
|
|
402
|
-
it "
|
403
|
-
@
|
404
|
-
@
|
405
|
-
@
|
406
|
-
@
|
358
|
+
it "with operator with <" do
|
359
|
+
@dc.operator = "count<2"
|
360
|
+
@dc.to_hash(@rs).should == {:M => false}
|
361
|
+
@dc.operator = "count<3"
|
362
|
+
@dc.to_hash(@rs).should == {:M => true}
|
407
363
|
end
|
408
364
|
|
409
|
-
it "
|
410
|
-
@
|
411
|
-
@
|
412
|
-
@
|
413
|
-
@
|
414
|
-
@
|
415
|
-
@
|
365
|
+
it "with operator with <=" do
|
366
|
+
@dc.operator = "count<=1"
|
367
|
+
@dc.to_hash(@rs).should == {:M => false}
|
368
|
+
@dc.operator = "count<=2"
|
369
|
+
@dc.to_hash(@rs).should == {:M => true}
|
370
|
+
@dc.operator = "count<=3"
|
371
|
+
@dc.to_hash(@rs).should == {:M => true}
|
416
372
|
end
|
417
373
|
|
418
|
-
it "
|
419
|
-
@
|
420
|
-
@
|
421
|
-
@
|
422
|
-
@
|
423
|
-
@
|
424
|
-
@
|
374
|
+
it "with operator with >=" do
|
375
|
+
@dc.operator = "count>=1"
|
376
|
+
@dc.to_hash(@rs).should == {:M => true}
|
377
|
+
@dc.operator = "count>=2"
|
378
|
+
@dc.to_hash(@rs).should == {:M => true}
|
379
|
+
@dc.operator = "count>=3"
|
380
|
+
@dc.to_hash(@rs).should == {:M => false}
|
425
381
|
end
|
426
382
|
|
427
|
-
it "
|
428
|
-
@
|
429
|
-
@
|
430
|
-
@
|
431
|
-
@
|
432
|
-
@
|
433
|
-
@
|
383
|
+
it "with operator with !=" do
|
384
|
+
@dc.operator = "count!=1"
|
385
|
+
@dc.to_hash(@rs).should == {:M => true}
|
386
|
+
@dc.operator = "count!=2"
|
387
|
+
@dc.to_hash(@rs).should == {:M => false}
|
388
|
+
@dc.operator = "count!=3"
|
389
|
+
@dc.to_hash(@rs).should == {:M => true}
|
434
390
|
end
|
435
391
|
end
|
436
392
|
end
|