From d471c3db620b4cb5ec9e22825b47dbc83a6e012d Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Tue, 24 Jun 2014 11:15:47 +0200 Subject: [PATCH] better test coverage and removed unnecessary code --- .../helena/admin/question_groups_controller.rb | 5 ----- .../helena/admin/manage_question_spec.rb | 18 ++++++++++++++++++ .../helena/admin/manage_survey_spec.rb | 7 +++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/controllers/helena/admin/question_groups_controller.rb b/app/controllers/helena/admin/question_groups_controller.rb index b723caa..9dc59f4 100644 --- a/app/controllers/helena/admin/question_groups_controller.rb +++ b/app/controllers/helena/admin/question_groups_controller.rb @@ -22,8 +22,6 @@ def create if @question_group.save notify_successful_create_for(@question_group.title) - else - notify_error end respond_with @question_group, location: admin_survey_question_groups_path(@survey) end @@ -37,9 +35,6 @@ def update if @question_group.update_attributes question_group_params notify_successful_update_for(@question_group.title) - else - notify_error - add_breadcrumb @question_group.title_was end respond_with @question_group, location: admin_survey_question_groups_path(@survey) end diff --git a/spec/features/helena/admin/manage_question_spec.rb b/spec/features/helena/admin/manage_question_spec.rb index eb378d0..dac115c 100644 --- a/spec/features/helena/admin/manage_question_spec.rb +++ b/spec/features/helena/admin/manage_question_spec.rb @@ -38,6 +38,14 @@ expect { click_button 'Save' }.to change { question_group.reload.questions.count }.by(1) end + scenario 'creating a new question errors when without entering a code' do + visit helena.new_admin_survey_question_group_question_path(draft_version.survey, question_group) + + fill_in 'Code', with: '' + + expect { click_button 'Save' }.to change { question_group.reload.questions.count }.by(0) + end + scenario 'edits a question' do question = create :question, question_text: 'We are here?', question_group: question_group @@ -52,6 +60,16 @@ expect(question.reload.code).to eq 'b12' end + scenario 'edits a question errors when code text is empty' do + question = create :question, question_text: 'We are here?', question_group: question_group + + visit helena.edit_admin_survey_question_group_question_path(draft_version.survey, question.question_group, question) + + fill_in 'Code', with: '' + + expect{ click_button 'Save' }.not_to change { question.reload } + end + scenario 'moving a question' do first_question = create :question, question_group: question_group, position: 1 second_question = create :question, question_group: question_group, position: 2 diff --git a/spec/features/helena/admin/manage_survey_spec.rb b/spec/features/helena/admin/manage_survey_spec.rb index 517ed3c..e92125c 100644 --- a/spec/features/helena/admin/manage_survey_spec.rb +++ b/spec/features/helena/admin/manage_survey_spec.rb @@ -42,7 +42,14 @@ end expect { click_button 'Save' }.to change { Helena::Survey.count }.by 1 + end + + scenario 'creates a new surveys errors without a name' do + visit helena.new_admin_survey_path + + fill_in 'Name', with: '' + expect { click_button 'Save' }.to change { Helena::Survey.count }.by 0 end scenario 'edits a survey' do