rapidfire 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -13
- data/app/controllers/rapidfire/attempts_controller.rb +29 -0
- data/app/controllers/rapidfire/questions_controller.rb +35 -34
- data/app/controllers/rapidfire/surveys_controller.rb +60 -0
- data/app/models/rapidfire/answer.rb +3 -3
- data/app/models/rapidfire/attempt.rb +11 -0
- data/app/models/rapidfire/question.rb +3 -3
- data/app/models/rapidfire/{question_group.rb → survey.rb} +1 -1
- data/app/services/rapidfire/{answer_group_builder.rb → attempt_builder.rb} +12 -12
- data/app/services/rapidfire/base_service.rb +1 -1
- data/app/services/rapidfire/question_form.rb +4 -4
- data/app/services/rapidfire/{question_group_results.rb → survey_results.rb} +3 -3
- data/app/views/rapidfire/{answer_groups → attempts}/new.html.erb +2 -2
- data/app/views/rapidfire/questions/_question.html.erb +2 -2
- data/app/views/rapidfire/questions/edit.html.erb +1 -1
- data/app/views/rapidfire/questions/index.html.erb +1 -1
- data/app/views/rapidfire/questions/new.html.erb +1 -1
- data/app/views/rapidfire/surveys/_form.html.erb +15 -0
- data/app/views/rapidfire/surveys/_survey.html.erb +18 -0
- data/app/views/rapidfire/{question_groups → surveys}/index.html.erb +4 -4
- data/app/views/rapidfire/surveys/new.html.erb +1 -0
- data/app/views/rapidfire/{question_groups → surveys}/results.html.erb +1 -1
- data/config/routes.rb +3 -3
- data/db/migrate/20130502170733_create_rapidfire_question_groups.rb +1 -1
- data/db/migrate/20130502195310_create_rapidfire_questions.rb +2 -2
- data/db/migrate/20130502195415_create_rapidfire_answer_groups.rb +4 -4
- data/db/migrate/20130502195504_create_rapidfire_answers.rb +2 -2
- data/lib/generators/rapidfire/templates/migrations/rename_answer_groups_and_question_groups.rb +9 -0
- data/lib/generators/rapidfire/upgrade_migration_generator.rb +18 -0
- data/lib/generators/rapidfire/views_generator.rb +4 -4
- data/lib/rapidfire/version.rb +1 -1
- data/lib/tasks/rapidfire.rake +10 -0
- data/spec/controllers/rapidfire/attempts_controller_spec.rb +20 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +61 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +72 -0
- data/spec/dummy/config/environments/test.rb +41 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +8 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +53 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +394 -0
- data/spec/dummy/log/test.log +2380 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/answers_factory.rb +7 -0
- data/spec/factories/attempts_factory.rb +5 -0
- data/spec/factories/questions_factory.rb +30 -0
- data/spec/factories/surveys_factory.rb +5 -0
- data/spec/features/rapidfire/answering_questions_spec.rb +55 -0
- data/spec/features/rapidfire/managing_questions_spec.rb +95 -0
- data/spec/features/rapidfire/managing_surveys_spec.rb +141 -0
- data/spec/models/rapidfire/answer_spec.rb +23 -0
- data/spec/models/rapidfire/attempt_spec.rb +9 -0
- data/spec/models/rapidfire/question_spec.rb +123 -0
- data/spec/models/rapidfire/questions/checkbox_spec.rb +90 -0
- data/spec/models/rapidfire/questions/date_spec.rb +78 -0
- data/spec/models/rapidfire/questions/numeric_spec.rb +114 -0
- data/spec/models/rapidfire/questions/select_spec.rb +90 -0
- data/spec/models/rapidfire/survey_spec.rb +11 -0
- data/spec/serializers/rapidfire/question_result_serializer_spec.rb +44 -0
- data/spec/services/rapidfire/attempt_builder_spec.rb +88 -0
- data/spec/services/rapidfire/question_form_spec.rb +93 -0
- data/spec/services/rapidfire/survey_results_spec.rb +63 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/support/rapidfire/answer_spec_helper.rb +23 -0
- data/spec/support/rapidfire/question_spec_helper.rb +13 -0
- data/spec/tasks/change_delimiter_from_comma_to_srsn_spec.rb +31 -0
- metadata +133 -30
- data/app/controllers/rapidfire/answer_groups_controller.rb +0 -29
- data/app/controllers/rapidfire/question_groups_controller.rb +0 -59
- data/app/models/rapidfire/answer_group.rb +0 -11
- data/app/views/rapidfire/question_groups/_form.html.erb +0 -15
- data/app/views/rapidfire/question_groups/_question_group.html.erb +0 -18
- data/app/views/rapidfire/question_groups/new.html.erb +0 -1
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapidfire::Question do
|
4
|
+
describe "Validations" do
|
5
|
+
it { is_expected.to validate_presence_of(:survey) }
|
6
|
+
it { is_expected.to validate_presence_of(:question_text) }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Associations" do
|
10
|
+
it { is_expected.to belong_to(:survey) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#rules" do
|
14
|
+
let(:question) { FactoryGirl.create(:q_long, validation_rules: validation_rules) }
|
15
|
+
|
16
|
+
context "when there are no validation rules" do
|
17
|
+
let(:validation_rules) { {} }
|
18
|
+
|
19
|
+
it "returns empty hash" do
|
20
|
+
expect(question.rules).to be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when validation rules are present" do
|
25
|
+
let(:validation_rules) do
|
26
|
+
{ :presence => "1" }
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns those rules" do
|
30
|
+
expect(question.rules[:presence]).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "validate_answer" do
|
36
|
+
let(:question) { FactoryGirl.create(:q_long, validation_rules: validation_rules) }
|
37
|
+
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
|
38
|
+
before { answer.valid? }
|
39
|
+
|
40
|
+
context "when there are no validation rules" do
|
41
|
+
let(:validation_rules) { {} }
|
42
|
+
let(:answer_text) { "" }
|
43
|
+
|
44
|
+
it "answer should pass validations" do
|
45
|
+
expect(answer.errors).to be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when question should have an answer" do
|
50
|
+
let(:validation_rules) { { presence: "1" } }
|
51
|
+
|
52
|
+
context "when answer is empty" do
|
53
|
+
let(:answer_text) { "" }
|
54
|
+
|
55
|
+
it "fails validations" do
|
56
|
+
expect(answer.errors).not_to be_empty
|
57
|
+
end
|
58
|
+
|
59
|
+
it "says answer should be present" do
|
60
|
+
expect(answer.errors[:answer_text]).to include("can't be blank")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when answer is not empty" do
|
65
|
+
let(:answer_text) { "sample answer" }
|
66
|
+
|
67
|
+
it "passes validations" do
|
68
|
+
expect(answer.errors).to be_empty
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when question should have an answer with min or max length" do
|
74
|
+
let(:validation_rules) { { minimum: "10", maximum: "20" } }
|
75
|
+
|
76
|
+
context "when answer is empty" do
|
77
|
+
let(:answer_text) { "" }
|
78
|
+
|
79
|
+
it "fails validations" do
|
80
|
+
expect(answer.errors).not_to be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
it "says answer is too short" do
|
84
|
+
expect(answer.errors[:answer_text].first).to match("is too short")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when answer is not empty" do
|
89
|
+
context "when answer is less than min chars" do
|
90
|
+
let(:answer_text) { 'i' * 9 }
|
91
|
+
|
92
|
+
it "fails validations" do
|
93
|
+
expect(answer.errors).not_to be_empty
|
94
|
+
end
|
95
|
+
|
96
|
+
it "says answer is too short" do
|
97
|
+
expect(answer.errors[:answer_text].first).to match("is too short")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when answer is in between min and max chars" do
|
102
|
+
let(:answer_text) { 'i' * 15 }
|
103
|
+
|
104
|
+
it "passes validations" do
|
105
|
+
expect(answer.errors).to be_empty
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when answer is more than max chars" do
|
110
|
+
let(:answer_text) { 'i' * 21 }
|
111
|
+
|
112
|
+
it "fails validations" do
|
113
|
+
expect(answer.errors).not_to be_empty
|
114
|
+
end
|
115
|
+
|
116
|
+
it "says answer is too long" do
|
117
|
+
expect(answer.errors[:answer_text].first).to match("is too long")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapidfire::Questions::Checkbox do
|
4
|
+
describe "Validations" do
|
5
|
+
it { is_expected.to validate_presence_of(:answer_options) }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#options" do
|
9
|
+
let(:question) { FactoryGirl.create(:q_select) }
|
10
|
+
|
11
|
+
it "returns options" do
|
12
|
+
expect(question.options).to match_array(["mac", "windows"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "validate_answer" do
|
17
|
+
let(:question) { FactoryGirl.create(:q_checkbox, validation_rules: validation_rules) }
|
18
|
+
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
|
19
|
+
before { answer.valid? }
|
20
|
+
|
21
|
+
context "when there are no validation rules" do
|
22
|
+
let(:validation_rules) { {} }
|
23
|
+
let(:answer_text) { "" }
|
24
|
+
|
25
|
+
it "answer should pass validations" do
|
26
|
+
expect(answer.errors).to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when there is an answer" do
|
30
|
+
context "when answer is valid option" do
|
31
|
+
let(:answer_text) { "hindi\r\ntelugu" }
|
32
|
+
|
33
|
+
it "passes validation" do
|
34
|
+
expect(answer.errors).to be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when answer is an invalid option" do
|
39
|
+
let(:answer_text) { "sample answer" }
|
40
|
+
|
41
|
+
it "fails validation" do
|
42
|
+
expect(answer.errors).not_to be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "says answer is invalid" do
|
46
|
+
expect(answer.errors[:answer_text]).to include("is invalid")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when question should have an answer" do
|
53
|
+
let(:validation_rules) { { presence: "1" } }
|
54
|
+
|
55
|
+
context "when answer is empty" do
|
56
|
+
let(:answer_text) { "" }
|
57
|
+
|
58
|
+
it "fails validations" do
|
59
|
+
expect(answer.errors).not_to be_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
it "says answer should be present" do
|
63
|
+
expect(answer.errors[:answer_text]).to include("can't be blank")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when answer is not empty" do
|
68
|
+
context "when answer is valid option" do
|
69
|
+
let(:answer_text) { "kannada" }
|
70
|
+
|
71
|
+
it "passes validation" do
|
72
|
+
expect(answer.errors).to be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when answer is an invalid option" do
|
77
|
+
let(:answer_text) { "sample answer" }
|
78
|
+
|
79
|
+
it "fails validation" do
|
80
|
+
expect(answer.errors).not_to be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
it "says answer is invalid" do
|
84
|
+
expect(answer.errors[:answer_text]).to include("is invalid")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapidfire::Questions::Date do
|
4
|
+
describe "validate_answer" do
|
5
|
+
let(:question) { FactoryGirl.create(:q_date, validation_rules: validation_rules) }
|
6
|
+
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
|
7
|
+
before { answer.valid? }
|
8
|
+
|
9
|
+
context "when there are no validation rules" do
|
10
|
+
let(:validation_rules) { {} }
|
11
|
+
let(:answer_text) { "" }
|
12
|
+
|
13
|
+
it "answer should pass validations" do
|
14
|
+
expect(answer.errors).to be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when there is an answer" do
|
18
|
+
context "when answer is valid date" do
|
19
|
+
let(:answer_text) { Date.today.to_s }
|
20
|
+
|
21
|
+
it "passes validation" do
|
22
|
+
expect(answer.errors).to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when answer is invalid date" do
|
27
|
+
let(:answer_text) { "sample answer" }
|
28
|
+
|
29
|
+
it "fails validation" do
|
30
|
+
expect(answer.errors).not_to be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it "says answer is invalid" do
|
34
|
+
expect(answer.errors[:answer_text]).to include("is invalid")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when question should have an answer" do
|
41
|
+
let(:validation_rules) { { presence: "1" } }
|
42
|
+
|
43
|
+
context "when answer is empty" do
|
44
|
+
let(:answer_text) { "" }
|
45
|
+
|
46
|
+
it "fails validations" do
|
47
|
+
expect(answer.errors).not_to be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it "says answer should be present" do
|
51
|
+
expect(answer.errors[:answer_text]).to include("can't be blank")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when answer is not empty" do
|
56
|
+
context "when answer is valid date" do
|
57
|
+
let(:answer_text) { Date.today.to_s }
|
58
|
+
|
59
|
+
it "passes validation" do
|
60
|
+
expect(answer.errors).to be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when answer is invalid date" do
|
65
|
+
let(:answer_text) { "sample answer" }
|
66
|
+
|
67
|
+
it "fails validation" do
|
68
|
+
expect(answer.errors).not_to be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
it "says answer is invalid" do
|
72
|
+
expect(answer.errors[:answer_text]).to include("is invalid")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapidfire::Questions::Numeric do
|
4
|
+
describe "validate_answer" do
|
5
|
+
let(:question) { FactoryGirl.create(:q_numeric, validation_rules: validation_rules) }
|
6
|
+
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
|
7
|
+
before { answer.valid? }
|
8
|
+
|
9
|
+
context "when there are no validation rules" do
|
10
|
+
let(:validation_rules) { {} }
|
11
|
+
let(:answer_text) { "" }
|
12
|
+
|
13
|
+
it "answer should pass validations" do
|
14
|
+
expect(answer.errors).to be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when there is an answer" do
|
18
|
+
context "when answer is valid number" do
|
19
|
+
let(:answer_text) { "24" }
|
20
|
+
|
21
|
+
it "passes validation" do
|
22
|
+
expect(answer.errors).to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when answer is not a valid number" do
|
27
|
+
let(:answer_text) { "sample answer" }
|
28
|
+
|
29
|
+
it "fails validation" do
|
30
|
+
expect(answer.errors).not_to be_empty
|
31
|
+
end
|
32
|
+
|
33
|
+
it "says answer is invalid" do
|
34
|
+
expect(answer.errors[:answer_text]).to include("is not a number")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when question should have an answer" do
|
41
|
+
let(:validation_rules) { { presence: "1" } }
|
42
|
+
|
43
|
+
context "when answer is empty" do
|
44
|
+
let(:answer_text) { "" }
|
45
|
+
|
46
|
+
it "fails validations" do
|
47
|
+
expect(answer.errors).not_to be_empty
|
48
|
+
end
|
49
|
+
|
50
|
+
it "says answer should be present" do
|
51
|
+
expect(answer.errors[:answer_text]).to include("can't be blank")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when answer is not empty" do
|
56
|
+
context "when the answer is a number" do
|
57
|
+
let(:answer_text) { "20" }
|
58
|
+
|
59
|
+
it "passes validation" do
|
60
|
+
expect(answer.errors).to be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the answer is not a number" do
|
65
|
+
let(:answer_text) { "sample answer" }
|
66
|
+
|
67
|
+
it "fails validation" do
|
68
|
+
expect(answer.errors).not_to be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
it "says answer is not a number" do
|
72
|
+
expect(answer.errors[:answer_text]).to include("is not a number")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when question should have an answer with >= or <= values" do
|
79
|
+
let(:validation_rules) { { greater_than_or_equal_to: "15", less_than_or_equal_to: "25" } }
|
80
|
+
|
81
|
+
context "when answer is less than min value" do
|
82
|
+
let(:answer_text) { "14" }
|
83
|
+
|
84
|
+
it "fails validations" do
|
85
|
+
expect(answer.errors).not_to be_empty
|
86
|
+
end
|
87
|
+
|
88
|
+
it "says answer is too short" do
|
89
|
+
expect(answer.errors[:answer_text].first).to match("must be greater than or equal to")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when answer is in between min and max value" do
|
94
|
+
let(:answer_text) { "20" }
|
95
|
+
|
96
|
+
it "passes validations" do
|
97
|
+
expect(answer.errors).to be_empty
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when answer is more than max value" do
|
102
|
+
let(:answer_text) { "26" }
|
103
|
+
|
104
|
+
it "fails validations" do
|
105
|
+
expect(answer.errors).not_to be_empty
|
106
|
+
end
|
107
|
+
|
108
|
+
it "says answer is too long" do
|
109
|
+
expect(answer.errors[:answer_text].first).to match("must be less than or equal to")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rapidfire::Questions::Select do
|
4
|
+
describe "Validations" do
|
5
|
+
it { is_expected.to validate_presence_of(:answer_options) }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#options" do
|
9
|
+
let(:question) { FactoryGirl.create(:q_select) }
|
10
|
+
|
11
|
+
it "returns options" do
|
12
|
+
expect(question.options).to match_array(["mac", "windows"])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "validate_answer" do
|
17
|
+
let(:question) { FactoryGirl.create(:q_select, validation_rules: validation_rules) }
|
18
|
+
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
|
19
|
+
before { answer.valid? }
|
20
|
+
|
21
|
+
context "when there are no validation rules" do
|
22
|
+
let(:validation_rules) { {} }
|
23
|
+
let(:answer_text) { "" }
|
24
|
+
|
25
|
+
it "answer should pass validations" do
|
26
|
+
expect(answer.errors).to be_empty
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when there is an answer" do
|
30
|
+
context "when answer is valid option" do
|
31
|
+
let(:answer_text) { "windows" }
|
32
|
+
|
33
|
+
it "passes validation" do
|
34
|
+
expect(answer.errors).to be_empty
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when answer is an invalid option" do
|
39
|
+
let(:answer_text) { "sample answer" }
|
40
|
+
|
41
|
+
it "fails validation" do
|
42
|
+
expect(answer.errors).not_to be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "says answer is invalid" do
|
46
|
+
expect(answer.errors[:answer_text]).to include("is not included in the list")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when question should have an answer" do
|
53
|
+
let(:validation_rules) { { presence: "1" } }
|
54
|
+
|
55
|
+
context "when answer is empty" do
|
56
|
+
let(:answer_text) { "" }
|
57
|
+
|
58
|
+
it "fails validations" do
|
59
|
+
expect(answer.errors).not_to be_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
it "says answer should be present" do
|
63
|
+
expect(answer.errors[:answer_text]).to include("can't be blank")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when answer is not empty" do
|
68
|
+
context "when answer is valid option" do
|
69
|
+
let(:answer_text) { "mac" }
|
70
|
+
|
71
|
+
it "passes validation" do
|
72
|
+
expect(answer.errors).to be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when answer is an invalid option" do
|
77
|
+
let(:answer_text) { "sample answer" }
|
78
|
+
|
79
|
+
it "fails validation" do
|
80
|
+
expect(answer.errors).not_to be_empty
|
81
|
+
end
|
82
|
+
|
83
|
+
it "says answer is invalid" do
|
84
|
+
expect(answer.errors[:answer_text]).to include("is not included in the list")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|