surveyor 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/.gitignore +6 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +104 -0
  4. data/Rakefile +50 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/surveyor_controller.rb +117 -0
  7. data/app/helpers/survey_form_builder.rb +37 -0
  8. data/app/helpers/surveyor_helper.rb +66 -0
  9. data/app/models/answer.rb +21 -0
  10. data/app/models/dependency.rb +46 -0
  11. data/app/models/dependency_condition.rb +79 -0
  12. data/app/models/question.rb +54 -0
  13. data/app/models/question_group.rb +18 -0
  14. data/app/models/response.rb +47 -0
  15. data/app/models/response_set.rb +185 -0
  16. data/app/models/survey.rb +57 -0
  17. data/app/models/survey_section.rb +15 -0
  18. data/app/views/layouts/surveyor_default.html.erb +13 -0
  19. data/app/views/partials/_answer.html.haml +49 -0
  20. data/app/views/partials/_question.html.haml +73 -0
  21. data/app/views/partials/_question_group.html.haml +41 -0
  22. data/app/views/surveyor/edit.html.haml +32 -0
  23. data/app/views/surveyor/new.html.haml +17 -0
  24. data/app/views/surveyor/show.html.haml +12 -0
  25. data/config/routes.rb +10 -0
  26. data/generators/surveyor/EXTENDING_SURVEYOR +12 -0
  27. data/generators/surveyor/extend_surveyor_generator.rb +22 -0
  28. data/generators/surveyor/surveyor_generator.rb +60 -0
  29. data/generators/surveyor/templates/README +10 -0
  30. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
  31. data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
  32. data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
  33. data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
  34. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
  35. data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
  36. data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
  37. data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
  38. data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
  39. data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
  40. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
  41. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
  42. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
  43. data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
  44. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
  45. data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
  46. data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
  47. data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
  48. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
  49. data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
  50. data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
  51. data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
  52. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
  53. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
  54. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
  55. data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
  56. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
  57. data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
  58. data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
  59. data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
  60. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
  61. data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
  62. data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
  63. data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
  64. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
  65. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
  66. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
  67. data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
  68. data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
  69. data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
  70. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
  71. data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
  72. data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
  73. data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
  74. data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
  75. data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
  76. data/generators/surveyor/templates/assets/javascripts/surveyor.js +28 -0
  77. data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
  78. data/generators/surveyor/templates/assets/stylesheets/reset.css +46 -0
  79. data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +245 -0
  80. data/generators/surveyor/templates/assets/stylesheets/surveyor.css +231 -0
  81. data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
  82. data/generators/surveyor/templates/extensions/survey_extensions.rb +18 -0
  83. data/generators/surveyor/templates/extensions/surveyor_controller_extensions.rb +28 -0
  84. data/generators/surveyor/templates/extensions/surveyor_custom.html.erb +13 -0
  85. data/generators/surveyor/templates/extensions/surveyor_helper_extensions.rb +18 -0
  86. data/generators/surveyor/templates/initializers/haml.rb +8 -0
  87. data/generators/surveyor/templates/initializers/surveyor.rb +11 -0
  88. data/generators/surveyor/templates/migrate/create_answers.rb +45 -0
  89. data/generators/surveyor/templates/migrate/create_dependencies.rb +21 -0
  90. data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
  91. data/generators/surveyor/templates/migrate/create_question_groups.rb +18 -0
  92. data/generators/surveyor/templates/migrate/create_questions.rb +33 -0
  93. data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
  94. data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
  95. data/generators/surveyor/templates/migrate/create_survey_sections.rb +25 -0
  96. data/generators/surveyor/templates/migrate/create_surveys.rb +25 -0
  97. data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +201 -0
  98. data/generators/surveyor/templates/tasks/surveyor.rb +4 -0
  99. data/init.rb +1 -0
  100. data/install.rb +1 -0
  101. data/lib/surveyor.rb +7 -0
  102. data/lib/surveyor/config.rb +45 -0
  103. data/lib/tasks/surveyor_tasks.rake +33 -0
  104. data/lib/tiny_code.rb +58 -0
  105. data/lib/xml_formatter.rb +12 -0
  106. data/script/surveyor/answer.rb +84 -0
  107. data/script/surveyor/columnizer.rb +36 -0
  108. data/script/surveyor/dependency.rb +43 -0
  109. data/script/surveyor/dependency_condition.rb +74 -0
  110. data/script/surveyor/question.rb +76 -0
  111. data/script/surveyor/question_group.rb +33 -0
  112. data/script/surveyor/specs/answer_spec.rb +66 -0
  113. data/script/surveyor/specs/question_dependency_spec.rb +46 -0
  114. data/script/surveyor/specs/question_group_spec.rb +9 -0
  115. data/script/surveyor/specs/question_spec.rb +111 -0
  116. data/script/surveyor/specs/section_spec.rb +58 -0
  117. data/script/surveyor/survey.rb +108 -0
  118. data/script/surveyor/survey_parser.rb +64 -0
  119. data/script/surveyor/survey_section.rb +153 -0
  120. data/script/surveyor/whr_dsl.tmproj +244 -0
  121. data/spec/controllers/surveyor_controller_spec.rb +328 -0
  122. data/spec/factories.rb +107 -0
  123. data/spec/models/answer_spec.rb +29 -0
  124. data/spec/models/dependency_condition_spec.rb +338 -0
  125. data/spec/models/dependency_spec.rb +82 -0
  126. data/spec/models/question_group_spec.rb +11 -0
  127. data/spec/models/question_spec.rb +75 -0
  128. data/spec/models/response_set_spec.rb +153 -0
  129. data/spec/models/response_spec.rb +94 -0
  130. data/spec/models/survey_section_spec.rb +34 -0
  131. data/spec/models/survey_spec.rb +72 -0
  132. data/spec/rcov.opts +2 -0
  133. data/spec/spec.opts +4 -0
  134. data/spec/spec_helper.rb +14 -0
  135. data/surveyor.gemspec +187 -0
  136. data/uninstall.rb +1 -0
  137. metadata +211 -0
@@ -0,0 +1,107 @@
1
+ # http://github.com/thoughtbot/factory_girl/tree/master
2
+
3
+ Factory.define :survey do |s|
4
+ s.title {"Simple survey"}
5
+ s.description {"A simple survey for testing"}
6
+ s.access_code {"simple_survey"}
7
+ s.active_at {Time.now}
8
+ s.inactive_at {}
9
+ s.css_url {}
10
+ end
11
+
12
+ Factory.sequence(:survey_section_display_order){|n| n }
13
+
14
+ Factory.define :survey_section do |s|
15
+ s.association :survey # s.survey_id {}
16
+ s.title {"Demographics"}
17
+ s.description {"Asking you about your personal data"}
18
+ s.display_order {Factory.next :survey_section_display_order}
19
+ s.reference_identifier {"demographics"}
20
+ s.data_export_identifier {"demographics"}
21
+ end
22
+
23
+ Factory.sequence(:question_display_order){|n| n }
24
+
25
+ Factory.define :question do |s|
26
+ s.association :survey_section # s.survey_section_id {}
27
+ s.text {"What is your favorite color?"}
28
+ s.short_text {"favorite_color"}
29
+ s.help_text {"just write it in the box"}
30
+ s.pick {:none}
31
+ s.display_type {} # nil is default
32
+ s.display_order {Factory.next :question_display_order}
33
+ s.question_group_id {}
34
+ s.is_mandatory {false}
35
+ s.reference_identifier {|me| "q_#{me.object_id}"}
36
+ s.data_export_identifier {}
37
+ s.display_width {}
38
+ end
39
+
40
+ Factory.sequence(:answer_display_order){|n| n }
41
+
42
+ Factory.define :answer do |a|
43
+ a.association :question # a.question_id {}
44
+ a.text {"My favorite color is clear"}
45
+ a.short_text {"clear"}
46
+ a.help_text {"Clear is the absense of color"}
47
+ a.weight {}
48
+ a.response_class {"String"}
49
+ a.display_order {}
50
+ a.is_exclusive {}
51
+ a.hide_label {}
52
+ a.reference_identifier {}
53
+ a.data_export_identifier {}
54
+ a.common_data_identitier {}
55
+ a.max_value {}
56
+ a.min_value {}
57
+ a.length {}
58
+ a.decimal_precision {}
59
+ a.allow_negative {}
60
+ a.allow_blank {}
61
+ a.unit {}
62
+ a.display_length {}
63
+ end
64
+
65
+ Factory.define :dependency do |d|
66
+ # the dependent question
67
+ d.association :question # d.question_id {}
68
+ d.rule {"1"}
69
+ end
70
+
71
+ Factory.define :dependency_condition do |d|
72
+ d.association :dependency # d.dependency_id {}
73
+ d.rule_key {"1"}
74
+ # the conditional question
75
+ d.question_id {}
76
+ d.operator {"=="}
77
+ d.answer_id {}
78
+ d.datetime_value {}
79
+ d.integer_value {}
80
+ d.float_value {}
81
+ d.unit {}
82
+ d.text_value {}
83
+ d.string_value {}
84
+ d.response_other {}
85
+ end
86
+
87
+ Factory.define :response_set do |r|
88
+ r.user_id {}
89
+ r.association :survey # r.survey_id {}
90
+ r.access_code {ResponseSet.make_tiny_code}
91
+ r.started_at {Time.now}
92
+ r.completed_at {}
93
+ end
94
+
95
+ Factory.define :response do |r|
96
+ r.association :response_set # r.response_set_id {}
97
+ r.question_id {}
98
+ r.answer_id {}
99
+ r.datetime_value {}
100
+ r.integer_value {}
101
+ r.float_value {}
102
+ r.unit {}
103
+ r.text_value {}
104
+ r.string_value {}
105
+ r.response_other {}
106
+ r.response_group {}
107
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Answer, "when creating a new answer" do
4
+ before(:each) do
5
+ @answer = Factory(:answer, :text => "Red")
6
+ end
7
+
8
+ it "should be valid" do
9
+ @answer.should be_valid
10
+ end
11
+
12
+ it "should be invalid without a unique reference identifier (within the scope of its parent)" do
13
+ @answer.question_id = nil
14
+ @answer.should_not be_valid
15
+ end
16
+
17
+ it "should have 'default' renderer with nil question.pick and response_class" do
18
+ @answer.question = Factory(:question, :pick => nil)
19
+ @answer.response_class = nil
20
+ @answer.renderer.should == :default
21
+ end
22
+
23
+ it "should have a_b renderer for a question.pick and B response_class" do
24
+ @answer.question = Factory(:question, :pick => "a")
25
+ @answer.response_class = "B"
26
+ @answer.renderer.should == :a_b
27
+ end
28
+
29
+ end
@@ -0,0 +1,338 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+
4
+ describe DependencyCondition, "Class methods" do
5
+ it "should have a list of operators" do
6
+ %w(== != < > <= >=).each{|operator| DependencyCondition.operators.include?(operator).should be_true }
7
+ end
8
+ end
9
+
10
+ describe DependencyCondition, "instance" do
11
+ before(:each) do
12
+ @dependency_condition = DependencyCondition.new(:dependency_id => 1, :question_id => 45, :operator => "==", :answer_id => 23, :rule_key => "1")
13
+ end
14
+
15
+ it "should be valid" do
16
+ @dependency_condition.should be_valid
17
+ end
18
+
19
+ it "should be invalid without a parent dependency_id, question_id, answer_id" do
20
+ @dependency_condition.dependency_id = nil
21
+ @dependency_condition.should have(1).errors_on(:dependency_id)
22
+ @dependency_condition.question_id = nil
23
+ @dependency_condition.should have(1).errors_on(:question_id)
24
+ @dependency_condition.answer_id = nil
25
+ @dependency_condition.should have(1).errors_on(:answer_id)
26
+ end
27
+
28
+ it "should be invalid without an operator" do
29
+ @dependency_condition.operator = nil
30
+ @dependency_condition.should have(2).errors_on(:operator)
31
+ end
32
+
33
+ it "should be invalid without a rule_key" do
34
+ @dependency_condition.should be_valid
35
+ @dependency_condition.rule_key = nil
36
+ @dependency_condition.should_not be_valid
37
+ @dependency_condition.should have(1).errors_on(:rule_key)
38
+ end
39
+
40
+ it "should have unique rule_key within the context of a dependency" do
41
+ @dependency_condition.should be_valid
42
+ DependencyCondition.create(:dependency_id => 2, :question_id => 46, :operator => "==", :answer_id => 14, :rule_key => "2")
43
+ @dependency_condition.rule_key = "2" #rule key uniquness is scoped by dependency_id
44
+ @dependency_condition.dependency_id = 2
45
+ @dependency_condition.should_not be_valid
46
+ @dependency_condition.should have(1).errors_on(:rule_key)
47
+ end
48
+
49
+ it "should have an operator in DependencyCondition.operators" do
50
+ DependencyCondition.operators.each do |o|
51
+ @dependency_condition.operator = o
52
+ @dependency_condition.should have(0).errors_on(:operator)
53
+ end
54
+ @dependency_condition.operator = "#"
55
+ @dependency_condition.should have(1).error_on(:operator)
56
+ end
57
+
58
+ it "should evaluate within the context of a response set object" do
59
+ @response = Response.new(:question_id => 45, :response_set_id => 40, :answer_id => 23)
60
+ @response.answer = Answer.new(:question_id => 45, :response_class => "answer")
61
+ @response_set = ResponseSet.new()
62
+ @response_set.stub!(:find_response).and_return(@response)
63
+ @dependency_condition.evaluation_of(@response_set).should be_true
64
+ # inversion
65
+ @alt_response = Response.new(:question_id => 45, :response_set_id => 40, :answer_id => 55)
66
+ @alt_response.answer = Answer.new(:question_id => 45, :response_class => "answer")
67
+ @alt_resp_set = ResponseSet.new()
68
+
69
+ @alt_resp_set.stub!(:find_response).and_return(@alt_response)
70
+ @dependency_condition.evaluation_of(@alt_resp_set).should be_false
71
+
72
+ end
73
+
74
+ it "should return false if there is no response set value that corresponds to the dependency condition" do
75
+ @empty_rs = mock(ResponseSet, :find_response => nil)
76
+ @dependency_condition.evaluation_of(@empty_rs).should be_false
77
+ end
78
+
79
+ describe "when helping the dependency object determine state" do
80
+
81
+ it "returns its key as a symbol" do
82
+ @dependency_condition.symbol_key.should == @dependency_condition.rule_key.to_sym
83
+ end
84
+
85
+ it "converts to a hash for evaluation by the depedency object" do
86
+ @rs = mock(ResponseSet)
87
+ @dependency_condition.stub!(:evaluation_of).with(@rs)
88
+ @dependency_condition.to_evaluation_hash(@rs)
89
+ end
90
+
91
+ end
92
+ end
93
+
94
+ describe DependencyCondition, "evaluting the resonse_set state" do
95
+
96
+ describe "when if given a response object whether the dependency is satisfied using '=='" do
97
+ before(:each) do
98
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => "==")
99
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
100
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
101
+ @response.answer = @select_answer
102
+ @dep_c.answer = @select_answer
103
+ @dep_c.as(:answer).should == 2
104
+ @response.as(:answer).should == 2
105
+ @dep_c.as(:answer).should == @response.as(:answer)
106
+ end
107
+
108
+ it "knows checkbox/radio type response" do
109
+ @dep_c.is_satisfied_by?(@response).should be_true
110
+ @dep_c.answer_id = 12
111
+ @dep_c.is_satisfied_by?(@response).should be_false
112
+ end
113
+
114
+ it "knows string value response" do
115
+ @select_answer.response_class = "string"
116
+ @response.string_value = "hello123"
117
+ @dep_c.string_value = "hello123"
118
+ @dep_c.is_satisfied_by?(@response).should be_true
119
+ @response.string_value = "foo_abc"
120
+ @dep_c.is_satisfied_by?(@response).should be_false
121
+ end
122
+
123
+ it "knows a text value response" do
124
+ @select_answer.response_class = "text"
125
+ @response.text_value = "hello this is some text for comparison"
126
+ @dep_c.text_value = "hello this is some text for comparison"
127
+ @dep_c.is_satisfied_by?(@response).should be_true
128
+ @response.text_value = "Not the same text"
129
+ @dep_c.is_satisfied_by?(@response).should be_false
130
+ end
131
+
132
+ it "knows an integer value response" do
133
+ @select_answer.response_class = "integer"
134
+ @response.integer_value = 10045
135
+ @dep_c.integer_value = 10045
136
+ @dep_c.is_satisfied_by?(@response).should be_true
137
+ @response.integer_value = 421
138
+ @dep_c.is_satisfied_by?(@response).should be_false
139
+ end
140
+
141
+ it "knows a float value response" do
142
+ @select_answer.response_class = "float"
143
+ @response.float_value = 121.1
144
+ @dep_c.float_value = 121.1
145
+ @dep_c.is_satisfied_by?(@response).should be_true
146
+ @response.float_value = 130.123
147
+ @dep_c.is_satisfied_by?(@response).should be_false
148
+ end
149
+
150
+ end
151
+
152
+ describe "when if given a response object whether the dependency is satisfied using '!='" do
153
+ before(:each) do
154
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => "!=")
155
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
156
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
157
+ @response.answer = @select_answer
158
+ @dep_c.answer = @select_answer
159
+ @dep_c.as(:answer).should == 2
160
+ @response.as(:answer).should == 2
161
+ @dep_c.as(:answer).should == @response.as(:answer)
162
+ end
163
+
164
+ it "knows checkbox/radio type response" do
165
+ @dep_c.is_satisfied_by?(@response).should be_false
166
+ @dep_c.answer_id = 12
167
+ @dep_c.is_satisfied_by?(@response).should be_true
168
+ end
169
+
170
+ it "knows string value response" do
171
+ @select_answer.response_class = "string"
172
+ @response.string_value = "hello123"
173
+ @dep_c.string_value = "hello123"
174
+ @dep_c.is_satisfied_by?(@response).should be_false
175
+ @response.string_value = "foo_abc"
176
+ @dep_c.is_satisfied_by?(@response).should be_true
177
+ end
178
+
179
+ it "knows a text value response" do
180
+ @select_answer.response_class = "text"
181
+ @response.text_value = "hello this is some text for comparison"
182
+ @dep_c.text_value = "hello this is some text for comparison"
183
+ @dep_c.is_satisfied_by?(@response).should be_false
184
+ @response.text_value = "Not the same text"
185
+ @dep_c.is_satisfied_by?(@response).should be_true
186
+ end
187
+
188
+ it "knows an integer value response" do
189
+ @select_answer.response_class = "integer"
190
+ @response.integer_value = 10045
191
+ @dep_c.integer_value = 10045
192
+ @dep_c.is_satisfied_by?(@response).should be_false
193
+ @response.integer_value = 421
194
+ @dep_c.is_satisfied_by?(@response).should be_true
195
+ end
196
+
197
+ it "knows a float value response" do
198
+ @select_answer.response_class = "float"
199
+ @response.float_value = 121.1
200
+ @dep_c.float_value = 121.1
201
+ @dep_c.is_satisfied_by?(@response).should be_false
202
+ @response.float_value = 130.123
203
+ @dep_c.is_satisfied_by?(@response).should be_true
204
+ end
205
+
206
+ end
207
+
208
+ describe "when if given a response object whether the dependency is satisfied using '<'" do
209
+ before(:each) do
210
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => "<")
211
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
212
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
213
+ @response.answer = @select_answer
214
+ @dep_c.answer = @select_answer
215
+
216
+ end
217
+
218
+ it "knows operator on integer value response" do
219
+ @select_answer.response_class = "integer"
220
+ @response.integer_value = 50
221
+ @dep_c.integer_value = 100
222
+ @dep_c.is_satisfied_by?(@response).should be_true
223
+ @response.integer_value = 421
224
+ @dep_c.is_satisfied_by?(@response).should be_false
225
+ end
226
+
227
+ it "knows operator on float value response" do
228
+ @select_answer.response_class = "float"
229
+ @response.float_value = 5.1
230
+ @dep_c.float_value = 121.1
231
+ @dep_c.is_satisfied_by?(@response).should be_true
232
+ @response.float_value = 130.123
233
+ @dep_c.is_satisfied_by?(@response).should be_false
234
+ end
235
+
236
+ end
237
+
238
+ describe "when if given a response object whether the dependency is satisfied using '<='" do
239
+ before(:each) do
240
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => "<=")
241
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
242
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
243
+ @response.answer = @select_answer
244
+ @dep_c.answer = @select_answer
245
+
246
+ end
247
+
248
+ it "knows operator on integer value response" do
249
+ @select_answer.response_class = "integer"
250
+ @response.integer_value = 50
251
+ @dep_c.integer_value = 100
252
+ @dep_c.is_satisfied_by?(@response).should be_true
253
+ @response.integer_value = 100
254
+ @dep_c.is_satisfied_by?(@response).should be_true
255
+ @response.integer_value = 421
256
+ @dep_c.is_satisfied_by?(@response).should be_false
257
+ end
258
+
259
+ it "knows operator on float value response" do
260
+ @select_answer.response_class = "float"
261
+ @response.float_value = 5.1
262
+ @dep_c.float_value = 121.1
263
+ @dep_c.is_satisfied_by?(@response).should be_true
264
+ @response.float_value = 121.1
265
+ @dep_c.is_satisfied_by?(@response).should be_true
266
+ @response.float_value = 130.123
267
+ @dep_c.is_satisfied_by?(@response).should be_false
268
+ end
269
+
270
+ end
271
+
272
+ describe "when if given a response object whether the dependency is satisfied using '>'" do
273
+ before(:each) do
274
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => ">")
275
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
276
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
277
+ @response.answer = @select_answer
278
+ @dep_c.answer = @select_answer
279
+
280
+ end
281
+
282
+ it "knows operator on integer value response" do
283
+ @select_answer.response_class = "integer"
284
+ @response.integer_value = 50
285
+ @dep_c.integer_value = 100
286
+ @dep_c.is_satisfied_by?(@response).should be_false
287
+ @response.integer_value = 421
288
+ @dep_c.is_satisfied_by?(@response).should be_true
289
+ end
290
+
291
+ it "knows operator on float value response" do
292
+ @select_answer.response_class = "float"
293
+ @response.float_value = 5.1
294
+ @dep_c.float_value = 121.1
295
+ @dep_c.is_satisfied_by?(@response).should be_false
296
+ @response.float_value = 130.123
297
+ @dep_c.is_satisfied_by?(@response).should be_true
298
+ end
299
+
300
+ end
301
+
302
+ describe "when if given a response object whether the dependency is satisfied using '>='" do
303
+ before(:each) do
304
+ @dep_c = DependencyCondition.new(:answer_id => 2, :operator => ">=")
305
+ @select_answer = Answer.new(:question_id => 1, :response_class => "answer")
306
+ @response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
307
+ @response.answer = @select_answer
308
+ @dep_c.answer = @select_answer
309
+
310
+ end
311
+
312
+ it "knows operator on integer value response" do
313
+ @select_answer.response_class = "integer"
314
+ @response.integer_value = 50
315
+ @dep_c.integer_value = 100
316
+ @dep_c.is_satisfied_by?(@response).should be_false
317
+ @response.integer_value = 100
318
+ @dep_c.is_satisfied_by?(@response).should be_true
319
+ @response.integer_value = 421
320
+ @dep_c.is_satisfied_by?(@response).should be_true
321
+ end
322
+
323
+ it "knows operator on float value response" do
324
+ @select_answer.response_class = "float"
325
+ @response.float_value = 5.1
326
+ @dep_c.float_value = 121.1
327
+ @dep_c.is_satisfied_by?(@response).should be_false
328
+ @response.float_value = 121.1
329
+ @dep_c.is_satisfied_by?(@response).should be_true
330
+ @response.float_value = 130.123
331
+ @dep_c.is_satisfied_by?(@response).should be_true
332
+ end
333
+ end
334
+
335
+
336
+
337
+ end
338
+