breakpointer-surveyor 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/app/controllers/answers_controller.rb +87 -0
- data/app/controllers/dependencies_controller.rb +87 -0
- data/app/controllers/dependency_conditions_controller.rb +87 -0
- data/app/controllers/questions_controller.rb +85 -0
- data/app/controllers/sections_controller.rb +87 -0
- data/app/controllers/surveying_controller.rb +139 -0
- data/app/controllers/surveys_controller.rb +87 -0
- data/app/helpers/answers_helper.rb +2 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/questions_helper.rb +2 -0
- data/app/helpers/sections_helper.rb +2 -0
- data/app/helpers/survey_form_builder.rb +38 -0
- data/app/helpers/survey_importer_helper.rb +2 -0
- data/app/helpers/surveying_helper.rb +91 -0
- data/app/helpers/surveys_helper.rb +2 -0
- data/app/models/answer.rb +18 -0
- data/app/models/dependency.rb +43 -0
- data/app/models/dependency_condition.rb +76 -0
- data/app/models/question.rb +44 -0
- data/app/models/question_group.rb +5 -0
- data/app/models/response.rb +58 -0
- data/app/models/response_set.rb +174 -0
- data/app/models/survey.rb +54 -0
- data/app/models/survey_section.rb +19 -0
- data/app/models/user.rb +5 -0
- data/app/views/answer_display_types/_any_answer.html.haml +3 -0
- data/app/views/answer_display_types/_any_other_and_string.html.haml +5 -0
- data/app/views/answer_display_types/_any_string.html.haml +4 -0
- data/app/views/answer_display_types/_date.html.haml +3 -0
- data/app/views/answer_display_types/_datetime.html.haml +2 -0
- data/app/views/answer_display_types/_default.html.haml +1 -0
- data/app/views/answer_display_types/_float.html.haml +5 -0
- data/app/views/answer_display_types/_grid_any_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_default.html.haml +2 -0
- data/app/views/answer_display_types/_grid_float.html.haml +2 -0
- data/app/views/answer_display_types/_grid_integer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_one_answer.html.haml +2 -0
- data/app/views/answer_display_types/_grid_string.html.haml +2 -0
- data/app/views/answer_display_types/_integer.html.haml +6 -0
- data/app/views/answer_display_types/_one_answer.html.haml +3 -0
- data/app/views/answer_display_types/_one_string.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_integer.html.haml +6 -0
- data/app/views/answer_display_types/_repeater_string.html.haml +7 -0
- data/app/views/answer_display_types/_string.html.haml +7 -0
- data/app/views/answer_display_types/_text.html.haml +6 -0
- data/app/views/answer_display_types/_time.html.haml +2 -0
- data/app/views/layouts/surveys.html.erb +17 -0
- data/app/views/question_display_types/_default.html.haml +12 -0
- data/app/views/question_display_types/_dropdown.html.haml +12 -0
- data/app/views/question_display_types/_grid_default.html.haml +14 -0
- data/app/views/question_display_types/_grid_dropdown.html.haml +15 -0
- data/app/views/question_display_types/_group_default.html.haml +8 -0
- data/app/views/question_display_types/_group_dropdown.html.haml +6 -0
- data/app/views/question_display_types/_image.html.haml +2 -0
- data/app/views/question_display_types/_inline.html.haml +12 -0
- data/app/views/question_display_types/_label.html.haml +4 -0
- data/app/views/question_display_types/_repeater_default.html.haml +10 -0
- data/app/views/question_display_types/_repeater_dropdown.html.haml +8 -0
- data/app/views/question_display_types/_slider.html.haml +17 -0
- data/app/views/question_group_display_types/_default.html.haml +13 -0
- data/app/views/question_group_display_types/_grid.html.haml +24 -0
- data/app/views/question_group_display_types/_repeater.html.haml +20 -0
- data/app/views/surveying/edit.html.haml +38 -0
- data/app/views/surveying/finish.html.haml +1 -0
- data/app/views/surveying/index.html.erb +19 -0
- data/app/views/surveying/new.html.haml +17 -0
- data/app/views/surveying/show.html.haml +8 -0
- data/config/routes.rb +10 -0
- data/generators/surveyor/surveyor_generator.rb +38 -0
- data/generators/surveyor/templates/README +9 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_11x11_icon_resize_se.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_35x9_colorpicker_indicator.gif.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/222222_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/454545_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_leftright.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_arrows_updown.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_close.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_doc.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_closed.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_folder_open.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_minus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_11x11_icon_plus.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_down.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_left.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_right.gif +0 -0
- data/generators/surveyor/templates/assets/images/888888_7x7_arrow_up.gif +0 -0
- data/generators/surveyor/templates/assets/images/dadada_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/e6e6e6_40x100_textures_02_glass_75.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_01_flat_0.png +0 -0
- data/generators/surveyor/templates/assets/images/ffffff_40x100_textures_02_glass_65.png +0 -0
- data/generators/surveyor/templates/assets/javascripts/accessibleUISlider.jQuery.js +201 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-1.2.6.js +3549 -0
- data/generators/surveyor/templates/assets/javascripts/jquery-ui-personalized-1.5.3.js +7616 -0
- data/generators/surveyor/templates/assets/javascripts/jquery.form.js +637 -0
- data/generators/surveyor/templates/assets/javascripts/surveyor.js +35 -0
- data/generators/surveyor/templates/assets/stylesheets/jquery-ui-slider-additions.css +71 -0
- data/generators/surveyor/templates/assets/stylesheets/reset.css +46 -0
- data/generators/surveyor/templates/assets/stylesheets/sass/surveyor.sass +321 -0
- data/generators/surveyor/templates/assets/stylesheets/surveyor.css +245 -0
- data/generators/surveyor/templates/assets/stylesheets/ui.theme.css +851 -0
- data/generators/surveyor/templates/migrate/create_answers.rb +46 -0
- data/generators/surveyor/templates/migrate/create_dependencies.rb +21 -0
- data/generators/surveyor/templates/migrate/create_dependency_conditions.rb +29 -0
- data/generators/surveyor/templates/migrate/create_question_groups.rb +18 -0
- data/generators/surveyor/templates/migrate/create_questions.rb +33 -0
- data/generators/surveyor/templates/migrate/create_response_sets.rb +22 -0
- data/generators/surveyor/templates/migrate/create_responses.rb +33 -0
- data/generators/surveyor/templates/migrate/create_survey_sections.rb +25 -0
- data/generators/surveyor/templates/migrate/create_surveys.rb +25 -0
- data/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +201 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/tasks/surveyor_tasks.rake +29 -0
- data/lib/tiny_code.rb +58 -0
- data/lib/user_manager.rb +9 -0
- data/lib/xml_formatter.rb +12 -0
- data/script/surveyor/answer.rb +84 -0
- data/script/surveyor/columnizer.rb +36 -0
- data/script/surveyor/dependency.rb +43 -0
- data/script/surveyor/dependency_condition.rb +74 -0
- data/script/surveyor/dslparse.rb +66 -0
- data/script/surveyor/question.rb +76 -0
- data/script/surveyor/question_group.rb +33 -0
- data/script/surveyor/specs/answer_spec.rb +66 -0
- data/script/surveyor/specs/question_dependency_spec.rb +46 -0
- data/script/surveyor/specs/question_group_spec.rb +9 -0
- data/script/surveyor/specs/question_spec.rb +111 -0
- data/script/surveyor/specs/section_spec.rb +58 -0
- data/script/surveyor/survey.rb +108 -0
- data/script/surveyor/survey_section.rb +153 -0
- data/script/surveyor/whr_dsl.tmproj +244 -0
- data/spec/controllers/answers_controller_spec.rb +64 -0
- data/spec/controllers/dependencies_controller_spec.rb +63 -0
- data/spec/controllers/dependency_conditions_controller_spec.rb +64 -0
- data/spec/controllers/questions_controller_spec.rb +64 -0
- data/spec/controllers/sections_controller_spec.rb +64 -0
- data/spec/controllers/surveying_controller_spec.rb +328 -0
- data/spec/controllers/surveying_routing_spec.rb +45 -0
- data/spec/controllers/surveys_controller_spec.rb +64 -0
- data/spec/fixtures/answers.yml +9 -0
- data/spec/fixtures/dependencies.yml +7 -0
- data/spec/fixtures/dependency_conditions.yml +27 -0
- data/spec/fixtures/question_groups.yml +7 -0
- data/spec/fixtures/questions.yml +15 -0
- data/spec/fixtures/response_sets.yml +13 -0
- data/spec/fixtures/responses.yml +9 -0
- data/spec/fixtures/survey_sections.yml +11 -0
- data/spec/fixtures/surveys.yml +9 -0
- data/spec/fixtures/users.yml +7 -0
- data/spec/helpers/survey_importer_helper_spec.rb +11 -0
- data/spec/helpers/surveying_helper_spec.rb +11 -0
- data/spec/models/answer_spec.rb +62 -0
- data/spec/models/dependency_condition_spec.rb +347 -0
- data/spec/models/dependency_spec.rb +82 -0
- data/spec/models/question_group_spec.rb +11 -0
- data/spec/models/question_spec.rb +70 -0
- data/spec/models/response_set_spec.rb +172 -0
- data/spec/models/response_spec.rb +94 -0
- data/spec/models/survey_section_spec.rb +34 -0
- data/spec/models/survey_spec.rb +72 -0
- data/spec/models/user_spec.rb +11 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +72 -0
- data/spec/views/app/edit.html.erb_spec.rb +20 -0
- data/spec/views/app/index.html.erb_spec.rb +19 -0
- data/spec/views/app/new.html.erb_spec.rb +21 -0
- data/spec/views/app/show.html.erb_spec.rb +17 -0
- data/surveyor.gemspec +258 -0
- data/uninstall.rb +1 -0
- metadata +286 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
|
2
|
+
|
|
3
|
+
one:
|
|
4
|
+
dependency_id: 1
|
|
5
|
+
question_id: 1
|
|
6
|
+
answer_id: 1
|
|
7
|
+
operator: MyString
|
|
8
|
+
datetime_value: 2008-09-07 07:33:46
|
|
9
|
+
integer_value: 1
|
|
10
|
+
float_value: 1.5
|
|
11
|
+
unit: MyString
|
|
12
|
+
text_value: MyText
|
|
13
|
+
string_value: MyString
|
|
14
|
+
response_other: MyString
|
|
15
|
+
|
|
16
|
+
two:
|
|
17
|
+
dependency_id: 1
|
|
18
|
+
question_id: 1
|
|
19
|
+
answer_id: 1
|
|
20
|
+
operator: MyString
|
|
21
|
+
datetime_value: 2008-09-07 07:33:46
|
|
22
|
+
integer_value: 1
|
|
23
|
+
float_value: 1.5
|
|
24
|
+
unit: MyString
|
|
25
|
+
text_value: MyText
|
|
26
|
+
string_value: MyString
|
|
27
|
+
response_other: MyString
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
|
2
|
+
|
|
3
|
+
one:
|
|
4
|
+
survey_section_id: 1
|
|
5
|
+
display_group_id: 1
|
|
6
|
+
display_type: MyString
|
|
7
|
+
display_order: 1
|
|
8
|
+
text: MyText
|
|
9
|
+
|
|
10
|
+
two:
|
|
11
|
+
survey_section_id: 1
|
|
12
|
+
display_group_id: 1
|
|
13
|
+
display_type: MyString
|
|
14
|
+
display_order: 1
|
|
15
|
+
text: MyText
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
|
2
|
+
|
|
3
|
+
one:
|
|
4
|
+
user_id: 1
|
|
5
|
+
survey_id: 1
|
|
6
|
+
started_at: 2008-06-19 09:31:24
|
|
7
|
+
completed_at: 2008-06-19 09:31:24
|
|
8
|
+
|
|
9
|
+
two:
|
|
10
|
+
user_id: 1
|
|
11
|
+
survey_id: 1
|
|
12
|
+
started_at: 2008-06-19 09:31:24
|
|
13
|
+
completed_at: 2008-06-19 09:31:24
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SurveyImporterHelper do
|
|
4
|
+
|
|
5
|
+
#Delete this example and add some real ones or delete this file
|
|
6
|
+
it "should be included in the object returned by #helper" do
|
|
7
|
+
included_modules = (class << helper; self; end).send :included_modules
|
|
8
|
+
included_modules.should include(SurveyImporterHelper)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe SurveyingHelper do
|
|
4
|
+
|
|
5
|
+
#Delete this example and add some real ones or delete this file
|
|
6
|
+
it "should be included in the object returned by #helper" do
|
|
7
|
+
included_modules = (class << helper; self; end).send :included_modules
|
|
8
|
+
included_modules.should include(AppHelper)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
# describe Answer, "validations" do
|
|
4
|
+
# test_helper :validations
|
|
5
|
+
# before(:each) do
|
|
6
|
+
# @model = @answer = Answer.new(:question_id => 1, :text => "Red")
|
|
7
|
+
# end
|
|
8
|
+
# it 'should validate presence of' do
|
|
9
|
+
# assert_invalid :text, "can't be blank", '', ' ', nil
|
|
10
|
+
# end
|
|
11
|
+
# it 'should validate numericality of' do
|
|
12
|
+
# assert_invalid :question_id, 'is not a number', '', ' ', nil
|
|
13
|
+
# assert_valid :question_id, '1', '2'
|
|
14
|
+
# assert_invalid :question_id, 'is not a number', 'abcd', '1,2', '1.3'
|
|
15
|
+
# end
|
|
16
|
+
# end
|
|
17
|
+
describe Answer, "when creating a new answer" do
|
|
18
|
+
before(:each) do
|
|
19
|
+
@q = mock_model(Question)
|
|
20
|
+
@answer = Answer.new(:question => @q, :text => "Red")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should be valid" do
|
|
24
|
+
@answer.should be_valid
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should be invalid without a unique reference identifier (within the scope of its parent)" do
|
|
28
|
+
pending
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should return its parent question" do
|
|
32
|
+
@answer.question_id.should == @q.id
|
|
33
|
+
@answer.question.should == @q
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should have 'default' partial_name with nil question" do
|
|
37
|
+
@answer.question = nil
|
|
38
|
+
@answer.partial_name.should == "default"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should have 'default' partial_name with nil question.pick and response_class" do
|
|
42
|
+
@question=mock_model(Question, :pick => nil)
|
|
43
|
+
@answer.stub!(:question).and_return(@question)
|
|
44
|
+
@answer.response_class = nil
|
|
45
|
+
@answer.partial_name.should == "default"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should have a_b partial_name for a question.pick and b response_class_string" do
|
|
49
|
+
@question=mock_model(Question, :pick => "a")
|
|
50
|
+
@answer.stub!(:question).and_return(@question)
|
|
51
|
+
@answer.stub!(:response_class_string).and_return("b")
|
|
52
|
+
@answer.partial_name.should == "a_b"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should return a downcase response_class_string or nil" do
|
|
56
|
+
@answer.response_class = nil
|
|
57
|
+
@answer.response_class_string.should == nil
|
|
58
|
+
@answer.response_class = "CamelCase"
|
|
59
|
+
@answer.response_class_string.should == "camelcase"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,347 @@
|
|
|
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
|
+
DependencyCondition.respond_to?(:operators).should be_true
|
|
7
|
+
DependencyCondition.operators.class.should == Array
|
|
8
|
+
DependencyCondition.operators.size.should > 0
|
|
9
|
+
|
|
10
|
+
DependencyCondition.operators.include?("==").should be_true
|
|
11
|
+
DependencyCondition.operators.include?("!=").should be_true
|
|
12
|
+
DependencyCondition.operators.include?("<").should be_true
|
|
13
|
+
DependencyCondition.operators.include?(">").should be_true
|
|
14
|
+
DependencyCondition.operators.include?("<=").should be_true
|
|
15
|
+
DependencyCondition.operators.include?(">=").should be_true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe DependencyCondition, "instance" do
|
|
20
|
+
before(:each) do
|
|
21
|
+
@dependency_condition = DependencyCondition.new(:dependency_id => 1, :question_id => 45, :operator => "==", :answer_id => 23, :rule_key => "1")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should be valid" do
|
|
25
|
+
@dependency_condition.should be_valid
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should be invalid without a parent dependency_id, question_id, answer_id" do
|
|
29
|
+
@dependency_condition.dependency_id = nil
|
|
30
|
+
@dependency_condition.should have(1).errors_on(:dependency_id)
|
|
31
|
+
@dependency_condition.question_id = nil
|
|
32
|
+
@dependency_condition.should have(1).errors_on(:question_id)
|
|
33
|
+
@dependency_condition.answer_id = nil
|
|
34
|
+
@dependency_condition.should have(1).errors_on(:answer_id)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should be invalid without an operator" do
|
|
38
|
+
@dependency_condition.operator = nil
|
|
39
|
+
@dependency_condition.should have(2).errors_on(:operator)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should be invalid without a rule_key" do
|
|
43
|
+
@dependency_condition.should be_valid
|
|
44
|
+
@dependency_condition.rule_key = nil
|
|
45
|
+
@dependency_condition.should_not be_valid
|
|
46
|
+
@dependency_condition.should have(1).errors_on(:rule_key)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should have unique rule_key within the context of a dependency" do
|
|
50
|
+
@dependency_condition.should be_valid
|
|
51
|
+
DependencyCondition.create(:dependency_id => 2, :question_id => 46, :operator => "==", :answer_id => 14, :rule_key => "2")
|
|
52
|
+
@dependency_condition.rule_key = "2" #rule key uniquness is scoped by dependency_id
|
|
53
|
+
@dependency_condition.dependency_id = 2
|
|
54
|
+
@dependency_condition.should_not be_valid
|
|
55
|
+
@dependency_condition.should have(1).errors_on(:rule_key)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should have an operator in DependencyCondition.operators" do
|
|
59
|
+
DependencyCondition.operators.each do |o|
|
|
60
|
+
@dependency_condition.operator = o
|
|
61
|
+
@dependency_condition.should have(0).errors_on(:operator)
|
|
62
|
+
end
|
|
63
|
+
@dependency_condition.operator = "#"
|
|
64
|
+
@dependency_condition.should have(1).error_on(:operator)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should evaluate within the context of a response set object" do
|
|
68
|
+
@response = Response.new(:question_id => 45, :response_set_id => 40, :answer_id => 23)
|
|
69
|
+
@response.answer = Answer.new(:question_id => 45, :response_class => "answer")
|
|
70
|
+
@response_set = ResponseSet.new()
|
|
71
|
+
@response_set.stub!(:find_response).and_return(@response)
|
|
72
|
+
@dependency_condition.evaluation_of(@response_set).should be_true
|
|
73
|
+
# inversion
|
|
74
|
+
@alt_response = Response.new(:question_id => 45, :response_set_id => 40, :answer_id => 55)
|
|
75
|
+
@alt_response.answer = Answer.new(:question_id => 45, :response_class => "answer")
|
|
76
|
+
@alt_resp_set = ResponseSet.new()
|
|
77
|
+
|
|
78
|
+
@alt_resp_set.stub!(:find_response).and_return(@alt_response)
|
|
79
|
+
@dependency_condition.evaluation_of(@alt_resp_set).should be_false
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should return false if there is no response set value that corresponds to the dependency condition" do
|
|
84
|
+
@empty_rs = mock(ResponseSet, :find_response => nil)
|
|
85
|
+
@dependency_condition.evaluation_of(@empty_rs).should be_false
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe "when helping the dependency object determine state" do
|
|
89
|
+
|
|
90
|
+
it "returns its key as a symbol" do
|
|
91
|
+
@dependency_condition.symbol_key.should == @dependency_condition.rule_key.to_sym
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "converts to a hash for evaluation by the depedency object" do
|
|
95
|
+
@rs = mock(ResponseSet)
|
|
96
|
+
@dependency_condition.stub!(:evaluation_of).with(@rs)
|
|
97
|
+
@dependency_condition.to_evaluation_hash(@rs)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
describe DependencyCondition, "evaluting the resonse_set state" do
|
|
104
|
+
|
|
105
|
+
describe "when if given a response object whether the dependency is satisfied using '=='" do
|
|
106
|
+
before(:each) do
|
|
107
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => "==")
|
|
108
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
109
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
110
|
+
@response.answer = @select_answer
|
|
111
|
+
@dep_c.answer = @select_answer
|
|
112
|
+
@dep_c.as(:answer).should == 2
|
|
113
|
+
@response.as(:answer).should == 2
|
|
114
|
+
@dep_c.as(:answer).should == @response.as(:answer)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "knows checkbox/radio type response" do
|
|
118
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
119
|
+
@dep_c.answer_id = 12
|
|
120
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "knows string value response" do
|
|
124
|
+
@select_answer.response_class = "string"
|
|
125
|
+
@response.string_value = "hello123"
|
|
126
|
+
@dep_c.string_value = "hello123"
|
|
127
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
128
|
+
@response.string_value = "foo_abc"
|
|
129
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "knows a text value response" do
|
|
133
|
+
@select_answer.response_class = "text"
|
|
134
|
+
@response.text_value = "hello this is some text for comparison"
|
|
135
|
+
@dep_c.text_value = "hello this is some text for comparison"
|
|
136
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
137
|
+
@response.text_value = "Not the same text"
|
|
138
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "knows an integer value response" do
|
|
142
|
+
@select_answer.response_class = "integer"
|
|
143
|
+
@response.integer_value = 10045
|
|
144
|
+
@dep_c.integer_value = 10045
|
|
145
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
146
|
+
@response.integer_value = 421
|
|
147
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "knows a float value response" do
|
|
151
|
+
@select_answer.response_class = "float"
|
|
152
|
+
@response.float_value = 121.1
|
|
153
|
+
@dep_c.float_value = 121.1
|
|
154
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
155
|
+
@response.float_value = 130.123
|
|
156
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
describe "when if given a response object whether the dependency is satisfied using '!='" do
|
|
162
|
+
before(:each) do
|
|
163
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => "!=")
|
|
164
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
165
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
166
|
+
@response.answer = @select_answer
|
|
167
|
+
@dep_c.answer = @select_answer
|
|
168
|
+
@dep_c.as(:answer).should == 2
|
|
169
|
+
@response.as(:answer).should == 2
|
|
170
|
+
@dep_c.as(:answer).should == @response.as(:answer)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "knows checkbox/radio type response" do
|
|
174
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
175
|
+
@dep_c.answer_id = 12
|
|
176
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "knows string value response" do
|
|
180
|
+
@select_answer.response_class = "string"
|
|
181
|
+
@response.string_value = "hello123"
|
|
182
|
+
@dep_c.string_value = "hello123"
|
|
183
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
184
|
+
@response.string_value = "foo_abc"
|
|
185
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "knows a text value response" do
|
|
189
|
+
@select_answer.response_class = "text"
|
|
190
|
+
@response.text_value = "hello this is some text for comparison"
|
|
191
|
+
@dep_c.text_value = "hello this is some text for comparison"
|
|
192
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
193
|
+
@response.text_value = "Not the same text"
|
|
194
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "knows an integer value response" do
|
|
198
|
+
@select_answer.response_class = "integer"
|
|
199
|
+
@response.integer_value = 10045
|
|
200
|
+
@dep_c.integer_value = 10045
|
|
201
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
202
|
+
@response.integer_value = 421
|
|
203
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "knows a float value response" do
|
|
207
|
+
@select_answer.response_class = "float"
|
|
208
|
+
@response.float_value = 121.1
|
|
209
|
+
@dep_c.float_value = 121.1
|
|
210
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
211
|
+
@response.float_value = 130.123
|
|
212
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
describe "when if given a response object whether the dependency is satisfied using '<'" do
|
|
218
|
+
before(:each) do
|
|
219
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => "<")
|
|
220
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
221
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
222
|
+
@response.answer = @select_answer
|
|
223
|
+
@dep_c.answer = @select_answer
|
|
224
|
+
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "knows operator on integer value response" do
|
|
228
|
+
@select_answer.response_class = "integer"
|
|
229
|
+
@response.integer_value = 50
|
|
230
|
+
@dep_c.integer_value = 100
|
|
231
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
232
|
+
@response.integer_value = 421
|
|
233
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "knows operator on float value response" do
|
|
237
|
+
@select_answer.response_class = "float"
|
|
238
|
+
@response.float_value = 5.1
|
|
239
|
+
@dep_c.float_value = 121.1
|
|
240
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
241
|
+
@response.float_value = 130.123
|
|
242
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
describe "when if given a response object whether the dependency is satisfied using '<='" do
|
|
248
|
+
before(:each) do
|
|
249
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => "<=")
|
|
250
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
251
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
252
|
+
@response.answer = @select_answer
|
|
253
|
+
@dep_c.answer = @select_answer
|
|
254
|
+
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it "knows operator on integer value response" do
|
|
258
|
+
@select_answer.response_class = "integer"
|
|
259
|
+
@response.integer_value = 50
|
|
260
|
+
@dep_c.integer_value = 100
|
|
261
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
262
|
+
@response.integer_value = 100
|
|
263
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
264
|
+
@response.integer_value = 421
|
|
265
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
it "knows operator on float value response" do
|
|
269
|
+
@select_answer.response_class = "float"
|
|
270
|
+
@response.float_value = 5.1
|
|
271
|
+
@dep_c.float_value = 121.1
|
|
272
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
273
|
+
@response.float_value = 121.1
|
|
274
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
275
|
+
@response.float_value = 130.123
|
|
276
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
describe "when if given a response object whether the dependency is satisfied using '>'" do
|
|
282
|
+
before(:each) do
|
|
283
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => ">")
|
|
284
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
285
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
286
|
+
@response.answer = @select_answer
|
|
287
|
+
@dep_c.answer = @select_answer
|
|
288
|
+
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "knows operator on integer value response" do
|
|
292
|
+
@select_answer.response_class = "integer"
|
|
293
|
+
@response.integer_value = 50
|
|
294
|
+
@dep_c.integer_value = 100
|
|
295
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
296
|
+
@response.integer_value = 421
|
|
297
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it "knows operator on float value response" do
|
|
301
|
+
@select_answer.response_class = "float"
|
|
302
|
+
@response.float_value = 5.1
|
|
303
|
+
@dep_c.float_value = 121.1
|
|
304
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
305
|
+
@response.float_value = 130.123
|
|
306
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
describe "when if given a response object whether the dependency is satisfied using '>='" do
|
|
312
|
+
before(:each) do
|
|
313
|
+
@dep_c = DependencyCondition.new(:answer_id => 2, :operator => ">=")
|
|
314
|
+
@select_answer = Answer.new(:question_id => 1, :response_class => "answer")
|
|
315
|
+
@response = Response.new(:question_id => 314, :response_set_id => 159, :answer_id => 2)
|
|
316
|
+
@response.answer = @select_answer
|
|
317
|
+
@dep_c.answer = @select_answer
|
|
318
|
+
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it "knows operator on integer value response" do
|
|
322
|
+
@select_answer.response_class = "integer"
|
|
323
|
+
@response.integer_value = 50
|
|
324
|
+
@dep_c.integer_value = 100
|
|
325
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
326
|
+
@response.integer_value = 100
|
|
327
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
328
|
+
@response.integer_value = 421
|
|
329
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
it "knows operator on float value response" do
|
|
333
|
+
@select_answer.response_class = "float"
|
|
334
|
+
@response.float_value = 5.1
|
|
335
|
+
@dep_c.float_value = 121.1
|
|
336
|
+
@dep_c.is_satisfied_by?(@response).should be_false
|
|
337
|
+
@response.float_value = 121.1
|
|
338
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
339
|
+
@response.float_value = 130.123
|
|
340
|
+
@dep_c.is_satisfied_by?(@response).should be_true
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
end
|
|
347
|
+
|