active_record_survey_api 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record_survey_api/concerns/controllers/answers.rb +2 -0
- data/lib/active_record_survey_api/concerns/controllers/questions.rb +23 -2
- data/lib/active_record_survey_api/version.rb +1 -1
- data/spec/controllers/active_record_survey_api/surveys/questions_spec.rb +66 -0
- data/spec/controllers/active_record_survey_api/surveys_spec.rb +1 -1
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/log/test.log +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 434cef59789f897cc5cd0d3c2da75393391f8672
|
4
|
+
data.tar.gz: a243df204fcb37fa0a3bef01b9900f415cc5018a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbb260c9e0d0645760a6df5e5a8cdc230f28b9ed29e897e03e6a070700973a4a0c910b67bde1ba5a171ced428eb3000890fbde417b23d4e74859464299ab3870
|
7
|
+
data.tar.gz: ed268fe5eff2d6e1a72232c3ac5916d3c4ed119a1d13f22cb2baf428d5fb0eb04dc01e216e09a030c37667ffc2767bf1e3370dd5ca00e46ab854522cec86fa6d
|
@@ -29,12 +29,31 @@ module ActiveRecordSurveyApi
|
|
29
29
|
|
30
30
|
def update
|
31
31
|
@question = question_by_id(params[:id])
|
32
|
-
|
32
|
+
if !question_params[:type].nil?
|
33
|
+
begin
|
34
|
+
@question.update_question_type(question_params[:type].to_s.constantize)
|
35
|
+
@question.survey.save
|
36
|
+
rescue Exception => $e
|
37
|
+
render json: {
|
38
|
+
errors: [
|
39
|
+
{
|
40
|
+
status: "422",
|
41
|
+
code: "422"
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}, status: :loop_detected
|
45
|
+
return
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@question.update_attributes(question_params.except(:type))
|
33
50
|
|
34
51
|
render json: serialize_model(@question, serializer: ActiveRecordSurveyApi::QuestionSerializer)
|
35
52
|
end
|
36
53
|
|
37
54
|
def create
|
55
|
+
question_params.delete(:type) unless question_params[:type].nil? # cannot set type through create
|
56
|
+
|
38
57
|
@question = new_question(question_params)
|
39
58
|
@question.survey = @survey
|
40
59
|
@question.save
|
@@ -102,7 +121,9 @@ module ActiveRecordSurveyApi
|
|
102
121
|
end
|
103
122
|
|
104
123
|
def question_params
|
105
|
-
json_params.require(:question).require(:attributes).permit(:text)
|
124
|
+
json_params.require(:question).require(:attributes).permit(:text,:type).tap { |whitelisted|
|
125
|
+
whitelisted[:type] = "ActiveRecordSurvey::Node::Answer#{ ((whitelisted[:type].to_s.empty?) ? "" : "::") }#{whitelisted[:type].camelize}" unless whitelisted[:type].nil?
|
126
|
+
}
|
106
127
|
end
|
107
128
|
|
108
129
|
def find_survey
|
@@ -12,6 +12,72 @@ describe ActiveRecordSurveyApi::QuestionsController, :type => :controller, :ques
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
+
describe 'update' do
|
16
|
+
it 'should change all question answer types when :type is passed' do
|
17
|
+
I18n.locale = :en
|
18
|
+
|
19
|
+
survey = FactoryGirl.build(:basic_survey)
|
20
|
+
survey.save
|
21
|
+
|
22
|
+
q4 = nil
|
23
|
+
survey.questions.each {|question|
|
24
|
+
q4 = question if question.text === "Question #4"
|
25
|
+
}
|
26
|
+
|
27
|
+
# Update Question #4 answers to boolean
|
28
|
+
put :update,
|
29
|
+
{
|
30
|
+
:question => {
|
31
|
+
:attributes => {
|
32
|
+
:type => "boolean"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}.to_json, @header_params.merge(:id => q4.id)
|
36
|
+
|
37
|
+
expect(survey.reload.as_map(:no_ids => true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[{"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer::Boolean", :children=>[]}]}]}]}]}])
|
38
|
+
|
39
|
+
# Update Question #4 answers to regular
|
40
|
+
put :update,
|
41
|
+
{
|
42
|
+
:question => {
|
43
|
+
:attributes => {
|
44
|
+
:type => ""
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}.to_json, @header_params.merge(:id => q4.id)
|
48
|
+
|
49
|
+
expect(survey.reload.as_map(:no_ids => true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not allow updating questions already linked to other questions' do
|
53
|
+
I18n.locale = :en
|
54
|
+
|
55
|
+
survey = FactoryGirl.build(:basic_survey)
|
56
|
+
survey.save
|
57
|
+
|
58
|
+
q3 = nil
|
59
|
+
survey.questions.each {|question|
|
60
|
+
q3 = question if question.text === "Question #3"
|
61
|
+
}
|
62
|
+
|
63
|
+
# Update Question #3 answers to boolean
|
64
|
+
put :update,
|
65
|
+
{
|
66
|
+
:question => {
|
67
|
+
:attributes => {
|
68
|
+
:type => "boolean"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}.to_json, @header_params.merge(:id => q3.id)
|
72
|
+
json_body = JSON.parse(response.body)
|
73
|
+
|
74
|
+
expect(json_body).to eq({"errors"=>[{"status"=>"422", "code"=>"422"}]})
|
75
|
+
|
76
|
+
# No change should have happened
|
77
|
+
expect(survey.reload.as_map(:no_ids => true)).to eq([{"text"=>"Question #1", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q1 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #2", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q2 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q2 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}]}]}, {"text"=>"Q1 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #3", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q3 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}, {"text"=>"Q3 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}]}, {"text"=>"Q1 Answer #3", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[{"text"=>"Question #4", :type=>"ActiveRecordSurvey::Node::Question", :children=>[{"text"=>"Q4 Answer #1", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}, {"text"=>"Q4 Answer #2", :type=>"ActiveRecordSurvey::Node::Answer", :children=>[]}]}]}]}])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
15
81
|
describe 'next-question' do
|
16
82
|
it 'should link/unlink and get the next question' do
|
17
83
|
I18n.locale = :en
|
@@ -26,7 +26,7 @@ describe ActiveRecordSurveyApi::SurveysController, :type => :controller, :survey
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'GET nodes' do
|
29
|
-
it 'should get all nodes of a survey'
|
29
|
+
it 'should get all nodes of a survey' do
|
30
30
|
survey = FactoryGirl.build(:basic_survey)
|
31
31
|
survey.save
|
32
32
|
|
Binary file
|
data/spec/test_app/log/test.log
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_survey_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.45
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.45
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: active_record_survey-node_map_group
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|