surveyor 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +26 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.rails_version +13 -0
  4. data/README.md +40 -22
  5. data/Rakefile +92 -29
  6. data/app/helpers/survey_form_builder.rb +37 -0
  7. data/app/helpers/surveyor_helper.rb +9 -9
  8. data/app/views/partials/_answer.html.haml +1 -1
  9. data/app/views/partials/_question.html.haml +3 -3
  10. data/app/views/partials/_question_group.html.haml +2 -2
  11. data/app/views/partials/_section.html.haml +1 -1
  12. data/app/views/surveyor/edit.html.haml +11 -3
  13. data/app/views/surveyor/new.html.haml +8 -1
  14. data/ci-exec.sh +50 -0
  15. data/config/routes.rb +9 -13
  16. data/cucumber.yml +10 -0
  17. data/doc/question types.png +0 -0
  18. data/features/redcap_parser.feature +1 -1
  19. data/features/step_definitions/common_setps.rb +3 -0
  20. data/features/step_definitions/parser_steps.rb +8 -1
  21. data/features/step_definitions/surveyor_steps.rb +33 -9
  22. data/features/step_definitions/web_steps.rb +85 -165
  23. data/features/support/env.rb +40 -46
  24. data/features/support/paths.rb +4 -4
  25. data/features/support/selectors.rb +39 -0
  26. data/features/surveyor.feature +63 -13
  27. data/features/surveyor_dependencies.feature +289 -0
  28. data/features/surveyor_parser.feature +29 -20
  29. data/lib/formtastic/surveyor_builder.rb +9 -9
  30. data/lib/generators/surveyor/custom_generator.rb +17 -0
  31. data/lib/generators/surveyor/install_generator.rb +50 -0
  32. data/{generators/extend_surveyor/templates/extensions → lib/generators/surveyor/templates/app/controllers}/surveyor_controller.rb +0 -0
  33. data/{generators/extend_surveyor/templates/extensions → lib/generators/surveyor/templates/app/views/layouts}/surveyor_custom.html.erb +0 -0
  34. data/{generators/surveyor/templates → lib/generators/surveyor/templates/config}/locales/surveyor_en.yml +0 -0
  35. data/{generators/surveyor/templates → lib/generators/surveyor/templates/config}/locales/surveyor_es.yml +0 -0
  36. data/{generators/surveyor/templates → lib/generators/surveyor/templates/config}/locales/surveyor_he.yml +0 -0
  37. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_api_ids.rb +0 -0
  38. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_correct_answer_id_to_questions.rb +0 -0
  39. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_default_value_to_answers.rb +0 -0
  40. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_display_order_to_surveys.rb +0 -0
  41. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_display_type_to_answers.rb +0 -0
  42. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_index_to_response_sets.rb +0 -0
  43. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_index_to_surveys.rb +0 -0
  44. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_section_id_to_responses.rb +0 -0
  45. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/add_unique_indicies.rb +0 -0
  46. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_answers.rb +0 -0
  47. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_dependencies.rb +0 -0
  48. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_dependency_conditions.rb +0 -0
  49. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_question_groups.rb +0 -0
  50. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_questions.rb +0 -0
  51. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_response_sets.rb +0 -0
  52. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_responses.rb +0 -0
  53. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_survey_sections.rb +0 -0
  54. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_surveys.rb +0 -0
  55. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_validation_conditions.rb +0 -0
  56. data/{generators/surveyor/templates → lib/generators/surveyor/templates/db}/migrate/create_validations.rb +0 -0
  57. data/{generators/surveyor/templates/assets/images → lib/generators/surveyor/templates/public/images/surveyor}/next.gif +0 -0
  58. data/{generators/surveyor/templates/assets/images → lib/generators/surveyor/templates/public/images/surveyor}/prev.gif +0 -0
  59. data/lib/generators/surveyor/templates/public/javascripts/surveyor/jquery.blockUI.js +499 -0
  60. data/{generators/surveyor/templates/assets/javascripts → lib/generators/surveyor/templates/public/javascripts/surveyor}/jquery.surveyor.js +47 -4
  61. data/{generators/surveyor/templates/assets/javascripts → lib/generators/surveyor/templates/public/javascripts/surveyor}/jquery.tools.min.js +0 -0
  62. data/{generators/surveyor/templates/assets → lib/generators/surveyor/templates/public}/stylesheets/sass/custom.sass +0 -0
  63. data/{generators/surveyor/templates/assets → lib/generators/surveyor/templates/public}/stylesheets/sass/surveyor.sass +2 -2
  64. data/{generators/surveyor/templates/assets/stylesheets → lib/generators/surveyor/templates/public/stylesheets/surveyor}/dateinput.css +0 -0
  65. data/{generators/surveyor/templates/assets/stylesheets → lib/generators/surveyor/templates/public/stylesheets/surveyor}/reset.css +0 -0
  66. data/{generators/surveyor/templates/assets/stylesheets → lib/generators/surveyor/templates/public/stylesheets/surveyor}/results.css +0 -0
  67. data/{generators/extend_surveyor/templates/EXTENDING_SURVEYOR → lib/generators/surveyor/templates/surveys/EXTENDING_SURVEYOR.md} +0 -0
  68. data/{generators → lib/generators}/surveyor/templates/surveys/kitchen_sink_survey.rb +0 -0
  69. data/{generators → lib/generators}/surveyor/templates/surveys/quiz.rb +0 -0
  70. data/lib/surveyor.rb +7 -0
  71. data/lib/surveyor/engine.rb +12 -0
  72. data/lib/surveyor/models/answer_methods.rb +0 -1
  73. data/lib/surveyor/models/dependency_condition_methods.rb +1 -3
  74. data/lib/surveyor/models/question_methods.rb +0 -1
  75. data/lib/surveyor/models/response_methods.rb +2 -2
  76. data/lib/surveyor/models/response_set_methods.rb +30 -14
  77. data/lib/surveyor/models/survey_methods.rb +2 -1
  78. data/lib/surveyor/models/survey_section_methods.rb +1 -2
  79. data/lib/surveyor/parser.rb +9 -7
  80. data/lib/surveyor/redcap_parser.rb +10 -7
  81. data/lib/surveyor/surveyor_controller_methods.rb +45 -11
  82. data/lib/surveyor/version.rb +3 -0
  83. data/lib/tasks/surveyor_tasks.rake +2 -2
  84. data/rails/init.rb +0 -1
  85. data/spec/controllers/surveyor_controller_spec.rb +81 -35
  86. data/spec/helpers/surveyor_helper_spec.rb +7 -1
  87. data/spec/models/dependency_condition_spec.rb +76 -63
  88. data/spec/models/response_set_spec.rb +52 -47
  89. data/spec/models/response_spec.rb +19 -16
  90. data/spec/spec_helper.rb +21 -44
  91. data/surveyor.gemspec +25 -176
  92. metadata +302 -77
  93. data/CHANGELOG +0 -335
  94. data/VERSION +0 -1
  95. data/ci-env.sh +0 -29
  96. data/generators/extend_surveyor/extend_surveyor_generator.rb +0 -21
  97. data/generators/surveyor/surveyor_generator.rb +0 -69
  98. data/generators/surveyor/templates/README +0 -10
  99. data/generators/surveyor/templates/tasks/surveyor.rb +0 -4
  100. data/hudson.rakefile +0 -33
  101. data/init_testbed.rakefile +0 -55
  102. data/testbed/Gemfile +0 -13
@@ -28,46 +28,47 @@ describe ResponseSet do
28
28
  end
29
29
 
30
30
  it "should save new responses from radio buttons, ignoring blanks" do
31
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks(@radio_response_attributes))
31
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable(@radio_response_attributes))
32
32
  @response_set.responses.should have(2).items
33
33
  @response_set.responses.detect{|r| r.question_id == 2}.answer_id.should == 6
34
34
  end
35
35
 
36
36
  it "should save new responses from other types, ignoring blanks" do
37
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks(@other_response_attributes))
37
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable(@other_response_attributes))
38
38
  @response_set.responses.should have(1).items
39
39
  @response_set.responses.detect{|r| r.question_id == 7}.text_value.should == "Brian is tired"
40
40
  end
41
41
 
42
42
  it "should ignore data if corresponding radio button is not selected" do
43
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks(@radio_response_attributes))
43
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable(@radio_response_attributes))
44
44
  @response_set.responses.select{|r| r.question_id == 2}.should have(1).item
45
45
  @response_set.responses.detect{|r| r.question_id == 2}.string_value.should == nil
46
46
  end
47
47
 
48
48
  it "should preserve response ids in checkboxes when adding another checkbox" do
49
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks(@checkbox_response_attributes))
49
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable(@checkbox_response_attributes))
50
50
  @response_set.responses.should have(2).items
51
51
  initial_response_ids = @response_set.responses.map(&:id)
52
52
  # adding a checkbox
53
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks({"1"=>{"question_id"=>"9", "answer_id"=>"13"}}))
53
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable({"1"=>{"question_id"=>"9", "answer_id"=>"13"}}))
54
54
  @response_set.responses.should have(3).items
55
55
  (@response_set.responses.map(&:id) - initial_response_ids).size.should == 1
56
56
  end
57
-
57
+
58
58
  it "should preserve response ids in checkboxes when removing another checkbox" do
59
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks(@checkbox_response_attributes))
59
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable(@checkbox_response_attributes))
60
60
  @response_set.responses.should have(2).items
61
61
  initial_response_ids = @response_set.responses.map(&:id)
62
62
  # removing a checkbox, reload the response set
63
- @response_set.update_attributes(:responses_attributes => ResponseSet.reject_or_destroy_blanks({"1"=>{"question_id"=>"9", "answer_id"=>"", "id" => initial_response_ids.first}}))
63
+ @response_set.update_attributes(:responses_attributes => ResponseSet.to_savable({"1"=>{"question_id"=>"9", "answer_id"=>"", "id" => initial_response_ids.first}}))
64
64
  @response_set.reload.responses.should have(1).items
65
65
  (initial_response_ids - @response_set.responses.map(&:id)).size.should == 1
66
66
  end
67
67
  it "should clean up a blank or empty hash" do
68
- ResponseSet.reject_or_destroy_blanks(nil).should == {}
69
- ResponseSet.reject_or_destroy_blanks({}).should == {}
68
+ ResponseSet.to_savable(nil).should == []
69
+ ResponseSet.to_savable({}).should == []
70
70
  end
71
+
71
72
  it "should clean up responses_attributes before passing to nested_attributes" do
72
73
  hash_of_hashes = {
73
74
  "11" => {"question_id" => "1", "answer_id" => [""]}, # new checkbox, blank
@@ -92,39 +93,42 @@ describe ResponseSet do
92
93
  "30" => {"id" => "110", "question_id" => "18", "answer_id" => "271", "string_value" => "moo"}, # existing radio with string value, changed
93
94
  "31" => {"id" => "111", "question_id" => "19", "answer_id" => "281", "string_value" => "mar"} # existing radio with string value, unchanged
94
95
  }
95
- ResponseSet.reject_or_destroy_blanks(hash_of_hashes).should == {
96
+
97
+ Set.new(ResponseSet.to_savable(hash_of_hashes)).should == Set.new([
96
98
  # "11" => {"question_id" => "1", "answer_id" => [""]}, # new checkbox, blank
97
- "12" => {"question_id" => "2", "answer_id" => ["", "124"]}, # new checkbox, checked
98
- "13" => {"id" => "101", "question_id" => "3", "answer_id" => [""], "_destroy" => "true"}, # existing checkbox, unchecked
99
- "14" => {"id" => "102", "question_id" => "4", "answer_id" => ["", "147"]}, # existing checkbox, left alone
99
+ {"question_id"=>"2", "answer_id"=>["", "124"]}, # new checkbox, checked
100
+ {"question_id"=>"3", "id"=>"101", "_destroy"=>"1"}, # existing checkbox, unchecked
101
+ {"question_id"=>"4", "id"=>"102", "answer_id"=>["", "147"]}, # existing checkbox, left alone
100
102
  # "15" => {"question_id" => "5", "answer_id" => ""}, # new radio, blank
101
- "16" => {"question_id" => "6", "answer_id" => "161"}, # new radio, selected
102
- "17" => {"id" => "103", "question_id" => "7", "answer_id" => "171"}, # existing radio, changed
103
- "18" => {"id" => "104", "question_id" => "8", "answer_id" => "181"}, # existing radio, unchanged
103
+ {"question_id"=>"6", "answer_id"=>"161"}, # new radio, selected
104
+ {"question_id"=>"7", "id"=>"103", "answer_id"=>"171"}, # existing radio, changed
105
+ {"question_id"=>"8", "id"=>"104", "answer_id"=>"181"}, # existing radio, unchanged
104
106
  # "19" => {"question_id" => "9", "answer_id" => "191", "string_value" => ""}, # new string, blank
105
- "20" => {"question_id" => "10", "answer_id" => "201", "string_value" => "hi"}, # new string, filled
106
- "21" => {"id" => "105", "question_id" => "11", "answer_id" => "211", "string_value" => "", "_destroy" => "true"}, # existing string, cleared
107
- "22" => {"id" => "106", "question_id" => "12", "answer_id" => "221", "string_value" => "ho"}, # existing string, changed
108
- "23" => {"id" => "107", "question_id" => "13", "answer_id" => "231", "string_value" => "hi"}, # existing string, unchanged
107
+ {"question_id"=>"10", "string_value"=>"hi", "answer_id"=>"201"}, # new string, filled
108
+ {"question_id"=>"11", "string_value"=>"", "id"=>"105", "_destroy"=>"1"}, # existing string, cleared
109
+ {"question_id"=>"12", "id"=>"106", "string_value"=>"ho", "answer_id"=>"221"}, # existing string, changed
110
+ {"question_id"=>"13", "id"=>"107", "string_value"=>"hi", "answer_id"=>"231"}, # existing string, unchanged
109
111
  # "24" => {"question_id" => "14", "answer_id" => [""], "string_value" => "foo"}, # new checkbox with string value, blank
110
- "25" => {"question_id" => "15", "answer_id" => ["", "241"], "string_value" => "bar"}, # new checkbox with string value, checked
111
- "26" => {"id" => "108", "question_id" => "14", "answer_id" => [""], "string_value" => "moo", "_destroy" => "true"}, # existing checkbox with string value, unchecked
112
- "27" => {"id" => "109", "question_id" => "15", "answer_id" => ["", "251"], "string_value" => "mar"}, # existing checkbox with string value, left alone
112
+ {"question_id"=>"15", "string_value"=>"bar", "answer_id"=>["", "241"]}, # new checkbox with string value, checked
113
+ {"question_id"=>"14", "string_value"=>"moo", "id"=>"108", "_destroy"=>"1"}, # existing checkbox with string value, unchecked
114
+ {"question_id"=>"15", "id"=>"109", "string_value"=>"mar", "answer_id"=>["", "251"]},# existing checkbox with string value, left alone
113
115
  # "28" => {"question_id" => "16", "answer_id" => "", "string_value" => "foo"}, # new radio with string value, blank
114
- "29" => {"question_id" => "17", "answer_id" => "261", "string_value" => "bar"}, # new radio with string value, selected
115
- "30" => {"id" => "110", "question_id" => "18", "answer_id" => "271", "string_value" => "moo"}, # existing radio with string value, changed
116
- "31" => {"id" => "111", "question_id" => "19", "answer_id" => "281", "string_value" => "mar"} # existing radio with string value, unchanged
117
- }
116
+ {"question_id"=>"17", "string_value"=>"bar", "answer_id"=>"261"}, # new radio with string value, selected
117
+ {"question_id"=>"18", "id"=>"110", "string_value"=>"moo", "answer_id"=>"271"}, # existing radio with string value, changed
118
+ {"question_id"=>"19", "id"=>"111", "string_value"=>"mar", "answer_id"=>"281"} # existing radio with string value, unchanged
119
+ ])
118
120
  end
121
+
119
122
  it "should clean up radio and string responses_attributes before passing to nested_attributes" do
120
123
  @qone = Factory(:question, :pick => "one")
121
124
  hash_of_hashes = {
122
- "32" => {"question_id" => @qone.id, "answer_id" => "291", "string_value" => ""} # new radio with blank string value, selected
123
- }
124
- ResponseSet.reject_or_destroy_blanks(hash_of_hashes).should == {
125
125
  "32" => {"question_id" => @qone.id, "answer_id" => "291", "string_value" => ""} # new radio with blank string value, selected
126
126
  }
127
+ ResponseSet.to_savable(hash_of_hashes).should == [
128
+ {"question_id" => @qone.id, "answer_id" => "291", "string_value" => ""} # new radio with blank string value, selected
129
+ ]
127
130
  end
131
+
128
132
  it "should clean up responses for lookups to get ids after saving via ajax" do
129
133
  hash_of_hashes = {"1"=>{"question_id"=>"2", "answer_id"=>"1"},
130
134
  "2"=>{"question_id"=>"3", "answer_id"=>["", "6"]},
@@ -134,7 +138,7 @@ describe ResponseSet do
134
138
  "19"=>{"question_id"=>"15", "datetime_value"=>"", "answer_id"=>"23", "id" => "1"},
135
139
  "47"=>{"question_id"=>"38", "answer_id"=>"220", "integer_value"=>"2", "id" => "2"},
136
140
  "61"=>{"question_id"=>"44", "response_group"=>"0", "answer_id"=>"241", "integer_value"=>"12"}}
137
- ResponseSet.trim_for_lookups(hash_of_hashes).should ==
141
+ ResponseSet.trim_for_lookups(hash_of_hashes).should ==
138
142
  { "1"=>{"question_id"=>"2", "answer_id"=>"1"},
139
143
  "2"=>{"question_id"=>"3", "answer_id"=>["", "6"]},
140
144
  "9"=>{"question_id"=>"6", "answer_id"=>"13"},
@@ -145,12 +149,13 @@ describe ResponseSet do
145
149
  "61"=>{"question_id"=>"44", "response_group"=>"0", "answer_id"=>"241"}
146
150
  }
147
151
  end
152
+
148
153
  it "should remove responses" do
149
154
  r = @response_set.responses.create(:question_id => 1, :answer_id => 2)
150
155
  r.id.should_not be nil
151
156
  @response_set.should have(1).responses
152
- ResponseSet.reject_or_destroy_blanks({"2"=>{"question_id"=>"1", "id"=> r.id, "answer_id"=>[""]}}).should == {"2"=>{"question_id"=>"1", "id"=> r.id, "_destroy"=> "true", "answer_id"=>[""]}}
153
- @response_set.update_attributes(:responses_attributes => {"2"=>{"question_id"=>"1", "id"=> r.id, "_destroy"=> "true", "answer_id"=>[""]}}).should be_true
157
+ ResponseSet.to_savable({"2"=>{"question_id"=>"1", "id"=> r.id, "answer_id"=>[""]}}).should == [{"question_id"=>"1", "id"=> r.id, "_destroy"=> "1" }]
158
+ @response_set.update_attributes(:responses_attributes => [{"question_id"=>"1", "id"=> r.id, "_destroy"=> "1"}]).should be_true
154
159
  @response_set.reload.should have(0).responses
155
160
  end
156
161
  end
@@ -177,7 +182,7 @@ describe ResponseSet, "with dependencies" do
177
182
  @response_set.responses << Factory(:response, :question_id => @do_you_like_pie.id, :answer_id => @do_you_like_pie.answers.first.id, :response_set_id => @response_set.id)
178
183
  @response_set.responses << Factory(:response, :string_value => "pecan pie", :question_id => @what_flavor.id, :answer_id => @what_flavor.answers.first.id, :response_set_id => @response_set.id)
179
184
  end
180
-
185
+
181
186
  it "should list unanswered dependencies to show at the top of the next page (javascript turned off)" do
182
187
  @response_set.unanswered_dependencies.should == [@what_bakery]
183
188
  end
@@ -187,18 +192,18 @@ describe ResponseSet, "with dependencies" do
187
192
  it "should list group as dependency" do
188
193
  # Question Group
189
194
  crust_group = Factory(:question_group, :text => "Favorite Crusts")
190
-
195
+
191
196
  # Question
192
197
  what_crust = Factory(:question, :text => "What is your favorite curst type?", :survey_section => @section)
193
198
  crust_group.questions << what_crust
194
199
 
195
200
  # Answers
196
201
  what_crust.answers << Factory(:answer, :response_class => :string, :question_id => what_crust.id)
197
-
202
+
198
203
  # Dependency
199
204
  crust_group_dep = Factory(:dependency, :rule => "C", :question_group_id => crust_group.id, :question => nil)
200
205
  Factory(:dependency_condition, :rule_key => "C", :question_id => @do_you_like_pie.id, :operator => "==", :answer_id => @do_you_like_pie.answers.first.id, :dependency_id => crust_group_dep.id)
201
-
206
+
202
207
  @response_set.unanswered_dependencies.should == [@what_bakery, crust_group]
203
208
  end
204
209
  end
@@ -208,7 +213,7 @@ describe ResponseSet, "dependency_conditions" do
208
213
  # Questions
209
214
  @like_pie = Factory(:question, :text => "Do you like pie?", :survey_section => @section)
210
215
  @like_jam = Factory(:question, :text => "Do you like jam?", :survey_section => @section)
211
- @what_is_wrong_with_you = Factory(:question, :text => "What's wrong with you?", :survey_section => @section)
216
+ @what_is_wrong_with_you = Factory(:question, :text => "What's wrong with you?", :survey_section => @section)
212
217
  # Answers
213
218
  @like_pie.answers << Factory(:answer, :text => "yes", :question_id => @like_pie.id)
214
219
  @like_pie.answers << Factory(:answer, :text => "no", :question_id => @like_pie.id)
@@ -227,7 +232,7 @@ describe ResponseSet, "dependency_conditions" do
227
232
  dependency_conditions.size.should == 2
228
233
  dependency_conditions.should include(@dep_a)
229
234
  dependency_conditions.should include(@dep_b)
230
-
235
+
231
236
  end
232
237
  it "should list all dependencies for passed question_id" do
233
238
  # Questions
@@ -239,9 +244,9 @@ describe ResponseSet, "dependency_conditions" do
239
244
  what_flavor.answers << Factory(:answer, :response_class => :string, :question_id => what_flavor.id)
240
245
  # Dependency
241
246
  flavor_dependency = Factory(:dependency, :rule => "C", :question_id => what_flavor.id)
242
- flavor_dependency_condition = Factory(:dependency_condition, :rule_key => "A", :question_id => like_ice_cream.id, :operator => "==",
247
+ flavor_dependency_condition = Factory(:dependency_condition, :rule_key => "A", :question_id => like_ice_cream.id, :operator => "==",
243
248
  :answer_id => like_ice_cream.answers.first.id, :dependency_id => flavor_dependency.id)
244
- # Responses
249
+ # Responses
245
250
  dependency_conditions = @response_set.send(:dependencies, like_ice_cream.id).should == [flavor_dependency]
246
251
  end
247
252
  end
@@ -257,11 +262,11 @@ describe ResponseSet, "as a quiz" do
257
262
  q = Factory(:question, :survey_section => @section)
258
263
  a = Factory(:answer, :question => q, :response_class => "answer")
259
264
  x = Factory(:answer, :question => q, :response_class => "answer")
260
- q.correct_answer_id = (quiz == "quiz" ? a.id : nil)
265
+ q.correct_answer = (quiz == "quiz" ? a : nil)
261
266
  @response_set.responses << Factory(:response, :question => q, :answer => (correct == "correct" ? a : x))
262
267
  end
263
268
  end
264
-
269
+
265
270
  it "should report correctness if it is a quiz" do
266
271
  generate_responses(3, "quiz", "correct")
267
272
  @response_set.correct?.should be_true
@@ -333,8 +338,8 @@ describe ResponseSet, "with mandatory, dependent questions" do
333
338
  d = Factory(:dependency, :question => q)
334
339
  dc = Factory(:dependency_condition, :dependency => d, :question_id => dq.id, :answer_id => da.id)
335
340
  end
336
- @response_set.responses << Factory(:response, :question => dq, :answer => (triggered == "triggered" ? da : dx))
337
- @response_set.responses << Factory(:response, :question => q, :answer => a)
341
+ @response_set.responses << Factory(:response, :response_set => @response_set, :question => dq, :answer => (triggered == "triggered" ? da : dx))
342
+ @response_set.responses << Factory(:response, :response_set => @response_set, :question => q, :answer => a)
338
343
  end
339
344
  end
340
345
  it "should report progress without mandatory questions" do
@@ -371,6 +376,6 @@ describe ResponseSet, "exporting csv" do
371
376
  csv.is_a?(String).should be_true
372
377
  csv.should match "question.short_text"
373
378
  csv.should match "What flavor?"
374
- csv.should match /pecan pie/
379
+ csv.should match /pecan pie/
375
380
  end
376
381
  end
@@ -22,20 +22,22 @@ describe Response, "when saving a response" do
22
22
  @response.question.correct_answer_id.should be_nil
23
23
  @response.correct?.should be_true
24
24
  end
25
+
25
26
  it "should be correct if the answer's response class != answer" do
26
27
  @response.answer.response_class.should_not == "answer"
27
28
  @response.correct?.should be_true
28
- end
29
+ end
30
+
29
31
  it "should be (in)correct if answer_id is (not) equal to question's correct_answer_id" do
30
32
  @answer = Factory(:answer, :response_class => "answer")
31
- @question = Factory(:question, :correct_answer_id => @answer.id)
33
+ @question = Factory(:question, :correct_answer => @answer)
32
34
  @response = Factory(:response, :question => @question, :answer => @answer)
33
35
  @response.correct?.should be_true
34
- @response.answer_id = 143
36
+ @response.answer = Factory(:answer, :response_class => "answer").tap { |a| a.id = 143 }
35
37
  @response.correct?.should be_false
36
38
  end
37
- describe "returns the response as the type requested" do
38
39
 
40
+ describe "returns the response as the type requested" do
39
41
  it "returns 'string'" do
40
42
  @response.string_value = "blah"
41
43
  @response.as("string").should == "blah"
@@ -70,9 +72,7 @@ describe Response, "when saving a response" do
70
72
  resp.as(:answer).should == nil
71
73
  resp.as(:stuff).should == nil
72
74
  end
73
-
74
75
  end
75
-
76
76
  end
77
77
 
78
78
  describe Response, "applicable_attributes" do
@@ -81,30 +81,33 @@ describe Response, "applicable_attributes" do
81
81
  @odoyle = Factory(:answer, :text => "Odoyle", :response_class => "answer")
82
82
  @other = Factory(:answer, :text => "Other", :response_class => "string")
83
83
  end
84
-
84
+
85
85
  it "should have string_value if response_type is string" do
86
86
  good = {"question_id" => @who.id, "answer_id" => @other.id, "string_value" => "Frank"}
87
87
  Response.applicable_attributes(good).should == good
88
88
  end
89
-
89
+
90
90
  it "should not have string_value if response_type is answer" do
91
91
  bad = {"question_id"=>@who.id, "answer_id"=>@odoyle.id, "string_value"=>"Frank"}
92
- Response.applicable_attributes(bad).should == {"question_id" => @who.id, "answer_id"=> @odoyle.id}
92
+ Response.applicable_attributes(bad).
93
+ should == {"question_id" => @who.id, "answer_id"=> @odoyle.id}
93
94
  end
94
-
95
+
95
96
  it "should have string_value if response_type is string and answer_id is an array (in the case of checkboxes)" do
96
97
  good = {"question_id"=>@who.id, "answer_id"=>["", @odoyle.id], "string_value"=>"Frank"}
97
- Response.applicable_attributes(good).should == {"question_id" => @who.id, "answer_id"=> ["", @odoyle.id]}
98
+ Response.applicable_attributes(good).
99
+ should == {"question_id" => @who.id, "answer_id"=> ["", @odoyle.id]}
98
100
  end
99
-
101
+
100
102
  it "should have ignore attribute if missing answer_id" do
101
103
  ignore = {"question_id"=>@who.id, "answer_id"=>"", "string_value"=>"Frank"}
102
- Response.applicable_attributes(ignore).should == {"question_id"=>@who.id, "answer_id"=>"", "string_value"=>"Frank"}
104
+ Response.applicable_attributes(ignore).
105
+ should == {"question_id"=>@who.id, "answer_id"=>"", "string_value"=>"Frank"}
103
106
  end
104
-
107
+
105
108
  it "should have ignore attribute if missing answer_id is an array" do
106
109
  ignore = {"question_id"=>@who.id, "answer_id"=>[""], "string_value"=>"Frank"}
107
- Response.applicable_attributes(ignore).should == {"question_id"=>@who.id, "answer_id"=>[""], "string_value"=>"Frank"}
110
+ Response.applicable_attributes(ignore).
111
+ should == {"question_id"=>@who.id, "answer_id"=>[""], "string_value"=>"Frank"}
108
112
  end
109
-
110
113
  end
data/spec/spec_helper.rb CHANGED
@@ -1,55 +1,32 @@
1
- # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
- # from the project root directory.
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
3
2
  ENV["RAILS_ENV"] ||= 'test'
4
- require File.expand_path(File.join(File.dirname(__FILE__),'..','testbed','config','environment'))
5
- require 'spec/autorun'
6
- require 'spec/rails'
3
+ begin
4
+ require File.expand_path("../../testbed/config/environment", __FILE__)
5
+ rescue LoadError => e
6
+ fail "Could not load the testbed app. Have you generated it?\n#{e.class}: #{e}"
7
+ end
8
+ require 'rspec/rails'
7
9
  require 'factories'
8
10
 
9
- # Uncomment the next line to use webrat's matchers
10
- #require 'webrat/integrations/rspec-rails'
11
-
12
- # Requires supporting files with custom matchers and macros, etc,
13
- # in ./support/ and its subdirectories.
14
- Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
15
-
16
- Spec::Runner.configure do |config|
17
- # If you're not using ActiveRecord you should remove these
18
- # lines, delete config/database.yml and disable :active_record
19
- # in your config/boot.rb
20
- config.use_transactional_fixtures = true
21
- config.use_instantiated_fixtures = false
22
- config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
11
+ # Requires supporting ruby files with custom matchers and macros, etc,
12
+ # in spec/support/ and its subdirectories.
13
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
23
14
 
24
- # == Fixtures
25
- #
26
- # You can declare fixtures for each example_group like this:
27
- # describe "...." do
28
- # fixtures :table_a, :table_b
29
- #
30
- # Alternatively, if you prefer to declare them only once, you can
31
- # do so right here. Just uncomment the next line and replace the fixture
32
- # names with your fixtures.
33
- #
34
- # config.global_fixtures = :table_a, :table_b
35
- #
36
- # If you declare global fixtures, be aware that they will be declared
37
- # for all of your examples, even those that don't use them.
38
- #
39
- # You can also declare which fixtures to use (for example fixtures for test/fixtures):
40
- #
41
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
42
- #
15
+ RSpec.configure do |config|
43
16
  # == Mock Framework
44
17
  #
45
- # RSpec uses its own mocking framework by default. If you prefer to
46
- # use mocha, flexmock or RR, uncomment the appropriate line:
18
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
47
19
  #
48
20
  # config.mock_with :mocha
49
21
  # config.mock_with :flexmock
50
22
  # config.mock_with :rr
51
- #
52
- # == Notes
53
- #
54
- # For more information take a look at Spec::Runner::Configuration and Spec::Runner
23
+ config.mock_with :rspec
24
+
25
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
26
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
27
+
28
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
29
+ # examples within a transaction, remove the following line or assign false
30
+ # instead of true.
31
+ config.use_transactional_fixtures = true
55
32
  end
data/surveyor.gemspec CHANGED
@@ -1,190 +1,39 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "surveyor/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{surveyor}
8
- s.version = "0.20.0"
7
+ s.version = Surveyor::VERSION
9
8
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
9
  s.authors = ["Brian Chamberlain", "Mark Yoon"]
12
- s.date = %q{2011-07-11}
13
10
  s.email = %q{yoon@northwestern.edu}
14
- s.extra_rdoc_files = [
15
- "README.md"
16
- ]
17
- s.files = [
18
- "CHANGELOG",
19
- "MIT-LICENSE",
20
- "README.md",
21
- "Rakefile",
22
- "VERSION",
23
- "app/controllers/results_controller.rb",
24
- "app/controllers/surveyor_controller.rb",
25
- "app/helpers/results_helper.rb",
26
- "app/helpers/surveyor_helper.rb",
27
- "app/models/answer.rb",
28
- "app/models/dependency.rb",
29
- "app/models/dependency_condition.rb",
30
- "app/models/question.rb",
31
- "app/models/question_group.rb",
32
- "app/models/response.rb",
33
- "app/models/response_set.rb",
34
- "app/models/survey.rb",
35
- "app/models/survey_section.rb",
36
- "app/models/survey_section_sweeper.rb",
37
- "app/models/validation.rb",
38
- "app/models/validation_condition.rb",
39
- "app/views/layouts/results.html.erb",
40
- "app/views/layouts/surveyor_default.html.erb",
41
- "app/views/partials/_answer.html.haml",
42
- "app/views/partials/_dependents.html.haml",
43
- "app/views/partials/_question.html.haml",
44
- "app/views/partials/_question_group.html.haml",
45
- "app/views/partials/_section.html.haml",
46
- "app/views/partials/_section_menu.html.haml",
47
- "app/views/results/index.html.erb",
48
- "app/views/results/show.html.erb",
49
- "app/views/surveyor/edit.html.haml",
50
- "app/views/surveyor/new.html.haml",
51
- "app/views/surveyor/show.html.haml",
52
- "ci-env.sh",
53
- "config/routes.rb",
54
- "doc/surveyor_models.png",
55
- "doc/surveyor_models2.png",
56
- "features/redcap_parser.feature",
57
- "features/step_definitions/parser_steps.rb",
58
- "features/step_definitions/surveyor_steps.rb",
59
- "features/step_definitions/web_steps.rb",
60
- "features/support/REDCapDemoDatabase_DataDictionary.csv",
61
- "features/support/env.rb",
62
- "features/support/paths.rb",
63
- "features/support/redcap_new_headers.csv",
64
- "features/support/redcap_siblings.csv",
65
- "features/support/redcap_whitespace.csv",
66
- "features/surveyor.feature",
67
- "features/surveyor_parser.feature",
68
- "generators/extend_surveyor/extend_surveyor_generator.rb",
69
- "generators/extend_surveyor/templates/EXTENDING_SURVEYOR",
70
- "generators/extend_surveyor/templates/extensions/surveyor_controller.rb",
71
- "generators/extend_surveyor/templates/extensions/surveyor_custom.html.erb",
72
- "generators/surveyor/surveyor_generator.rb",
73
- "generators/surveyor/templates/README",
74
- "generators/surveyor/templates/assets/images/next.gif",
75
- "generators/surveyor/templates/assets/images/prev.gif",
76
- "generators/surveyor/templates/assets/javascripts/jquery.surveyor.js",
77
- "generators/surveyor/templates/assets/javascripts/jquery.tools.min.js",
78
- "generators/surveyor/templates/assets/stylesheets/dateinput.css",
79
- "generators/surveyor/templates/assets/stylesheets/reset.css",
80
- "generators/surveyor/templates/assets/stylesheets/results.css",
81
- "generators/surveyor/templates/assets/stylesheets/sass/custom.sass",
82
- "generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass",
83
- "generators/surveyor/templates/locales/surveyor_en.yml",
84
- "generators/surveyor/templates/locales/surveyor_es.yml",
85
- "generators/surveyor/templates/locales/surveyor_he.yml",
86
- "generators/surveyor/templates/migrate/add_api_ids.rb",
87
- "generators/surveyor/templates/migrate/add_correct_answer_id_to_questions.rb",
88
- "generators/surveyor/templates/migrate/add_default_value_to_answers.rb",
89
- "generators/surveyor/templates/migrate/add_display_order_to_surveys.rb",
90
- "generators/surveyor/templates/migrate/add_display_type_to_answers.rb",
91
- "generators/surveyor/templates/migrate/add_index_to_response_sets.rb",
92
- "generators/surveyor/templates/migrate/add_index_to_surveys.rb",
93
- "generators/surveyor/templates/migrate/add_section_id_to_responses.rb",
94
- "generators/surveyor/templates/migrate/add_unique_indicies.rb",
95
- "generators/surveyor/templates/migrate/create_answers.rb",
96
- "generators/surveyor/templates/migrate/create_dependencies.rb",
97
- "generators/surveyor/templates/migrate/create_dependency_conditions.rb",
98
- "generators/surveyor/templates/migrate/create_question_groups.rb",
99
- "generators/surveyor/templates/migrate/create_questions.rb",
100
- "generators/surveyor/templates/migrate/create_response_sets.rb",
101
- "generators/surveyor/templates/migrate/create_responses.rb",
102
- "generators/surveyor/templates/migrate/create_survey_sections.rb",
103
- "generators/surveyor/templates/migrate/create_surveys.rb",
104
- "generators/surveyor/templates/migrate/create_validation_conditions.rb",
105
- "generators/surveyor/templates/migrate/create_validations.rb",
106
- "generators/surveyor/templates/surveys/kitchen_sink_survey.rb",
107
- "generators/surveyor/templates/surveys/quiz.rb",
108
- "generators/surveyor/templates/tasks/surveyor.rb",
109
- "hudson.rakefile",
110
- "init_testbed.rakefile",
111
- "lib/formtastic/surveyor_builder.rb",
112
- "lib/surveyor.rb",
113
- "lib/surveyor/acts_as_response.rb",
114
- "lib/surveyor/common.rb",
115
- "lib/surveyor/models/answer_methods.rb",
116
- "lib/surveyor/models/dependency_condition_methods.rb",
117
- "lib/surveyor/models/dependency_methods.rb",
118
- "lib/surveyor/models/question_group_methods.rb",
119
- "lib/surveyor/models/question_methods.rb",
120
- "lib/surveyor/models/response_methods.rb",
121
- "lib/surveyor/models/response_set_methods.rb",
122
- "lib/surveyor/models/survey_methods.rb",
123
- "lib/surveyor/models/survey_section_methods.rb",
124
- "lib/surveyor/models/validation_condition_methods.rb",
125
- "lib/surveyor/models/validation_methods.rb",
126
- "lib/surveyor/parser.rb",
127
- "lib/surveyor/redcap_parser.rb",
128
- "lib/surveyor/surveyor_controller_methods.rb",
129
- "lib/surveyor/unparser.rb",
130
- "lib/tasks/surveyor_tasks.rake",
131
- "rails/init.rb",
132
- "spec/controllers/surveyor_controller_spec.rb",
133
- "spec/factories.rb",
134
- "spec/helpers/surveyor_helper_spec.rb",
135
- "spec/lib/benchmark_spec.rb",
136
- "spec/lib/common_spec.rb",
137
- "spec/lib/parser_spec.rb",
138
- "spec/lib/redcap_parser_spec.rb",
139
- "spec/lib/unparser_spec.rb",
140
- "spec/models/answer_spec.rb",
141
- "spec/models/dependency_condition_spec.rb",
142
- "spec/models/dependency_spec.rb",
143
- "spec/models/question_group_spec.rb",
144
- "spec/models/question_spec.rb",
145
- "spec/models/response_set_spec.rb",
146
- "spec/models/response_spec.rb",
147
- "spec/models/survey_section_spec.rb",
148
- "spec/models/survey_spec.rb",
149
- "spec/models/validation_condition_spec.rb",
150
- "spec/models/validation_spec.rb",
151
- "spec/rcov.opts",
152
- "spec/spec.opts",
153
- "spec/spec_helper.rb",
154
- "surveyor.gemspec",
155
- "testbed/Gemfile"
156
- ]
157
11
  s.homepage = %q{http://github.com/NUBIC/surveyor}
158
12
  s.post_install_message = %q{Thanks for installing surveyor! The time has come to run the surveyor generator and migrate your database, even if you are upgrading.}
159
- s.require_paths = ["lib"]
160
- s.rubygems_version = %q{1.6.2}
161
13
  s.summary = %q{A rails (gem) plugin to enable surveys in your application}
162
14
 
163
- if s.respond_to? :specification_version then
164
- s.specification_version = 3
15
+ s.files = `git ls-files`.split("\n") - ['irb']
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency('rails', '~> 3.0')
21
+ s.add_dependency('haml', '~> 3.1.3')
22
+ s.add_dependency('sass')
23
+ s.add_dependency('fastercsv', '~> 1.5.4')
24
+ s.add_dependency('formtastic', '~> 1.2.4')
25
+ s.add_dependency('uuid')
165
26
 
166
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
167
- s.add_runtime_dependency(%q<haml>, [">= 0"])
168
- s.add_runtime_dependency(%q<sass>, [">= 0"])
169
- s.add_runtime_dependency(%q<fastercsv>, [">= 0"])
170
- s.add_runtime_dependency(%q<formtastic>, [">= 0"])
171
- s.add_runtime_dependency(%q<uuid>, [">= 0"])
172
- s.add_development_dependency(%q<yard>, [">= 0"])
173
- else
174
- s.add_dependency(%q<haml>, [">= 0"])
175
- s.add_dependency(%q<sass>, [">= 0"])
176
- s.add_dependency(%q<fastercsv>, [">= 0"])
177
- s.add_dependency(%q<formtastic>, [">= 0"])
178
- s.add_dependency(%q<uuid>, [">= 0"])
179
- s.add_dependency(%q<yard>, [">= 0"])
180
- end
181
- else
182
- s.add_dependency(%q<haml>, [">= 0"])
183
- s.add_dependency(%q<sass>, [">= 0"])
184
- s.add_dependency(%q<fastercsv>, [">= 0"])
185
- s.add_dependency(%q<formtastic>, [">= 0"])
186
- s.add_dependency(%q<uuid>, [">= 0"])
187
- s.add_dependency(%q<yard>, [">= 0"])
188
- end
27
+ s.add_development_dependency('yard')
28
+ s.add_development_dependency('rake', '0.8.7')
29
+ s.add_development_dependency('rspec-rails', '~> 2.6.0')
30
+ s.add_development_dependency('bundler', '~> 1.0', '>= 1.0.21')
31
+ s.add_development_dependency('factory_girl', '~> 2.1.2')
32
+ s.add_development_dependency('sqlite3')
33
+ s.add_development_dependency('cucumber-rails', '~> 1.1.1')
34
+ s.add_development_dependency('database_cleaner', '~> 0.6.7')
35
+ s.add_development_dependency('launchy', '~> 2.0.5')
36
+ s.add_development_dependency('capybara', '~> 1.1.1')
37
+ s.add_development_dependency('ci_reporter', '~> 1.6')
189
38
  end
190
39