diff --git a/test/functional/guidance_groups_controller_test.rb b/test/functional/guidance_groups_controller_test.rb index fd6400e..6013502 100644 --- a/test/functional/guidance_groups_controller_test.rb +++ b/test/functional/guidance_groups_controller_test.rb @@ -74,6 +74,7 @@ assert_redirected_to admin_index_guidance_path(@user.org) assert_equal _('Guidance group was successfully created.'), flash[:notice] assert assigns(:guidance_group) + assert_equal 'Testing create', GuidanceGroup.last.name, "expected the record to have been created!" # Invalid object post admin_create_guidance_group_path(@user.org), {guidance_group: {name: nil}} @@ -108,10 +109,11 @@ sign_in @user put admin_update_guidance_group_path(GuidanceGroup.first), {guidance_group: params} + assert_equal _('Guidance group was successfully updated.'), flash[:notice] assert_response :redirect assert_redirected_to "#{admin_index_guidance_path(@user.org)}?name=Testing+UPDATE" - assert_equal _('Guidance group was successfully updated.'), flash[:notice] assert assigns(:guidance_group) + assert_equal 'Testing UPDATE', GuidanceGroup.first.name, "expected the record to have been updated" # Invalid object put admin_update_guidance_group_path(GuidanceGroup.first), {guidance_group: {name: nil}} @@ -124,6 +126,7 @@ # DELETE /org/admin/guidancegroup/:id/admin_destroy (admin_destroy_guidance_group_path) # ---------------------------------------------------------- test 'delete the guidance_group' do + id = GuidanceGroup.first.id # Should redirect user to the root path if they are not logged in! delete admin_destroy_guidance_group_path(GuidanceGroup.first) assert_unauthorized_redirect_to_root_path @@ -134,6 +137,9 @@ assert_response :redirect assert_redirected_to admin_index_guidance_path assert_equal _('Guidance group was successfully deleted.'), flash[:notice] + assert_raise ActiveRecord::RecordNotFound do + GuidanceGroup.find(id).nil? + end end end \ No newline at end of file diff --git a/test/functional/guidances_controller_test.rb b/test/functional/guidances_controller_test.rb index d7d53df..817834d 100644 --- a/test/functional/guidances_controller_test.rb +++ b/test/functional/guidances_controller_test.rb @@ -104,7 +104,7 @@ # POST /org/admin/guidance/:id/admin_create (admin_create_guidance_path) # ---------------------------------------------------------- test 'create a new guidance' do - params = {'guidance-text': 'Testing UPDATE', guidance: {guidance_group_id: GuidanceGroup.first.id, published: true}} + params = {'guidance-text': 'Testing create', guidance: {guidance_group_id: GuidanceGroup.first.id, published: true}} # Should redirect user to the root path if they are not logged in! post admin_create_guidance_path(@user.org), params @@ -117,6 +117,7 @@ assert_redirected_to admin_show_guidance_path(Guidance.last) assert_equal _('Guidance was successfully created.'), flash[:notice] assert assigns(:guidance) + assert_equal 'Testing create', Guidance.last.text, "expected the record to have been created!" # Invalid object post admin_create_guidance_path(@user.org), {'guidance-text': nil, guidance: {published: false}} @@ -141,6 +142,7 @@ assert_equal _('Guidance was successfully updated.'), flash[:notice] assert_redirected_to "#{admin_show_guidance_path(Guidance.first)}?guidance_group_id=#{GuidanceGroup.first.id}" assert assigns(:guidance) + assert_equal 'Testing UPDATE', Guidance.first.text, "expected the record to have been updated" # Invalid object put admin_update_guidance_path(Guidance.first), {'guidance-text': nil, guidance: {guidance_group_id: GuidanceGroup.first.id}} @@ -152,6 +154,7 @@ # DELETE /org/admin/guidance/:id/admin_destroy (admin_destroy_guidance_path) # ---------------------------------------------------------- test 'delete the guidance' do + id = Guidance.first.id # Should redirect user to the root path if they are not logged in! delete admin_destroy_guidance_path(Guidance.first) assert_unauthorized_redirect_to_root_path @@ -163,6 +166,9 @@ assert_redirected_to admin_index_guidance_path assert_equal _('Guidance was successfully deleted.'), flash[:notice] assert assigns(:guidance) + assert_raise ActiveRecord::RecordNotFound do + Guidance.find(id).nil? + end end end \ No newline at end of file diff --git a/test/functional/phases_controller_test.rb b/test/functional/phases_controller_test.rb index 7050ddb..aa01bfc 100644 --- a/test/functional/phases_controller_test.rb +++ b/test/functional/phases_controller_test.rb @@ -141,7 +141,7 @@ # POST /org/admin/templates/phases/:id/admin_create (admin_create_phase_path) # ---------------------------------------------------------- test "create a phase " do - params = {template_id: @template.id, title: 'Phase: Tester 2'} + params = {template_id: @template.id, title: 'Phase: Tester 2', number: 2} # Should redirect user to the root path if they are not logged in! post admin_create_phase_path(@template.phases.first), {phase: params} @@ -150,12 +150,14 @@ sign_in @user post admin_create_phase_path(@template.phases.first), {phase: params} - assert_response :success - assert assigns(:template) + assert_equal _('Information was successfully created.'), flash[:notice] + assert_response :redirect + assert_redirected_to admin_show_phase_path(id: Phase.last.id, edit: 'true') assert assigns(:phase) + assert_equal 'Phase: Tester 2', Phase.last.title, "expected the record to have been created!" # Invalid object - post admin_create_phase_path(@template.phases.first), {phase: params} + post admin_create_phase_path(@template.phases.first), {phase: {template_id: @template.id}} assert_response :success assert flash[:notice].starts_with?(_('Unable to save your changes.')) end @@ -173,11 +175,11 @@ # Valid save put admin_update_phase_path(@template.phases.first), {phase: params} + assert_equal _('Information was successfully updated.'), flash[:notice] assert_response :redirect - assert_redirected_to admin_show_phase_url(@template.phases.first) assert assigns(:phase) - assert_equal _('Information was successfully updated.'), flash[:notice] + assert_equal 'Phase - UPDATE', @template.phases.first.title, "expected the record to have been updated" # Invalid save put admin_update_phase_path(@template.phases.first), {phase: {title: nil}} @@ -191,17 +193,21 @@ # DELETE /org/admin/templates/phases/:id/admin_destroy (admin_destroy_phase_path) # ---------------------------------------------------------- test "delete the phase" do + id = @template.phases.first.id # Should redirect user to the root path if they are not logged in! # TODO: Why are we not just using id: here? shouldn't need to specify the key - delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: @template.phases.first.id) + delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: id) assert_unauthorized_redirect_to_root_path sign_in @user - delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: @template.phases.first.id) + delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: id) assert_response :redirect assert_redirected_to admin_template_template_url assert_equal _('Information was successfully deleted.'), flash[:notice] + assert_raise ActiveRecord::RecordNotFound do + Phase.find(id).nil? + end end end \ No newline at end of file diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index d40bc2f..3120179 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -51,6 +51,7 @@ assert assigns(:question) assert_redirected_to admin_show_phase_url(id: @section.phase.id, edit: 'true', section_id: @section.id, question_id: Question.last.id) assert_equal _('Information was successfully created.'), flash[:notice] + assert_equal 'Test Question', Question.last.text, "expected the record to have been created!" # Invalid object post admin_create_question_path(@section), {question: {section_id: @section.id, text: nil}} @@ -73,12 +74,13 @@ # Valid save put admin_update_question_path(@section.questions.first), {question: params} + assert_equal _('Information was successfully updated.'), flash[:notice] assert_response :redirect assert_redirected_to admin_show_phase_url(id: @section.phase.id, edit: 'true', section_id: @section.id, question_id: @section.questions.first.id) assert assigns(:phase) assert assigns(:section) assert assigns(:question) - assert_equal _('Information was successfully updated.'), flash[:notice] + assert_equal 'Question - UPDATE', @section.questions.first.text, "expected the record to have been updated" # Invalid save put admin_update_question_path(@section.questions.first), {question: {text: nil}} @@ -93,19 +95,23 @@ # DELETE /org/admin/templates/questions/:id/admin_destroy (admin_destroy_question_path) # ---------------------------------------------------------- test "delete the question" do + id = @section.questions.first.id # Should redirect user to the root path if they are not logged in! - delete admin_destroy_question_path(id: @section.id, question_id: @section.questions.first.id) + delete admin_destroy_question_path(id: @section.id, question_id: id) assert_unauthorized_redirect_to_root_path sign_in @user - delete admin_destroy_question_path(id: @section.id, question_id: @section.questions.first.id) + delete admin_destroy_question_path(id: @section.id, question_id: id) assert_response :redirect assert assigns(:phase) assert assigns(:section) assert assigns(:question) assert_redirected_to admin_show_phase_url(id: @section.phase.id, edit: 'true', section_id: @section.id) assert_equal _('Information was successfully deleted.'), flash[:notice] + assert_raise ActiveRecord::RecordNotFound do + Question.find(id).nil? + end end end \ No newline at end of file diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index eb9c9e4..7b9fcae 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -49,6 +49,7 @@ assert_response :redirect assert_redirected_to admin_show_phase_url(id: @phase.id, edit: 'true', section_id: Section.last.id) assert_equal _('Information was successfully created.'), flash[:notice] + assert_equal 'Section Tester', Section.last.title, "expected the record to have been created!" # Invalid object post admin_create_section_path(@phase), {section: {phase_id: @phase.id, title: nil}} @@ -72,9 +73,10 @@ # Valid save put admin_update_section_path(@phase.sections.first), {section: params} + assert_equal _('Information was successfully updated.'), flash[:notice] assert_response :redirect assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: @phase.sections.first.id, edit: 'true') - assert_equal _('Information was successfully updated.'), flash[:notice] + assert_equal 'Phase - UPDATE', @phase.sections.first.title, "expected the record to have been updated" # Invalid save put admin_update_section_path(@phase.sections.first), {section: {title: nil}} @@ -88,19 +90,22 @@ # DELETE /org/admin/templates/sections/:id/admin_destroy (admin_destroy_section_path) # ---------------------------------------------------------- test "delete the section" do + id = @phase.sections.first.id # Should redirect user to the root path if they are not logged in! - delete admin_destroy_section_path(id: @phase.id, section_id: @phase.sections.first.id) + delete admin_destroy_section_path(id: @phase.id, section_id: id) assert_unauthorized_redirect_to_root_path sign_in @user - delete admin_destroy_section_path(id: @phase.id, section_id: @phase.sections.first.id) + delete admin_destroy_section_path(id: @phase.id, section_id: id) assert_response :redirect assert assigns(:section) assert assigns(:phase) - assert_redirected_to admin_show_phase_url(id: @phase.id, edit: 'true' ) assert_equal _('Information was successfully deleted.'), flash[:notice] + assert_raise ActiveRecord::RecordNotFound do + Section.find(id).nil? + end end end \ No newline at end of file diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 75664ef..a2d23d6 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -105,6 +105,7 @@ # DELETE /org/admin/templates/:id/admin_destroy (admin_destroy_template_path) # ---------------------------------------------------------- test "delete the admin template" do + id = @template.id # Should redirect user to the root path if they are not logged in! delete admin_destroy_template_path(@template) assert_unauthorized_redirect_to_root_path @@ -114,6 +115,9 @@ delete admin_destroy_template_path(@template) assert_response :redirect assert_redirected_to admin_index_template_url + assert_raise ActiveRecord::RecordNotFound do + Template.find(id).nil? + end end # TODO: Why are we passing an :id here!? Its a new record but we seem to need the last template's id @@ -129,10 +133,11 @@ sign_in @user post admin_create_template_path(Template.last.id), {template: params} + assert_equal _('Information was successfully created.'), flash[:notice] assert_response :redirect assert_redirected_to admin_template_template_url(Template.last.id) - assert_equal _('Information was successfully created.'), flash[:notice] assert assigns(:template) + assert_equal 'Testing create route', Template.last.title, "expected the record to have been created!" # Invalid object post admin_create_template_path(Template.last.id), {template: {title: nil, org_id: @user.org.id}} @@ -154,9 +159,9 @@ # Make sure we get the proper message if trying to update a published template put admin_update_template_path(@template), {template: params} + assert_equal _('Published templates cannot be edited.'), flash[:notice] assert_response :redirect assert_redirected_to admin_template_template_url(Template.last.id) - assert_equal _('Published templates cannot be edited.'), flash[:notice] assert assigns(:template) @template.published = false @@ -164,10 +169,11 @@ # Make sure we get the right response when editing an unpublished template put admin_update_template_path(@template), {template: params} + assert_equal _('Information was successfully updated.'), flash[:notice] assert_response :redirect assert_redirected_to admin_template_template_url(Template.last.id) - assert_equal _('Information was successfully updated.'), flash[:notice] assert assigns(:template) + assert_equal 'ABCD', @template.reload.title, "expected the record to have been updated" # Make sure we get the right response when providing an invalid template put admin_update_template_path(@template), {template: {title: nil}}