diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index e83366b..c3f6a4b 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -18,7 +18,8 @@ guid_save = guidance.present? ? guidance.save : true if ex_save && guid_save - redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully created.') + typ = (!ex_save && !guid_save ? 'example answer and guidance' : (!guid_save ? 'guidance' : 'example answer')) + redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: success_message(typ, _('created')) else @section = @question.section @phase = @section.phase @@ -74,7 +75,8 @@ @section = @question.section @phase = @section.phase if ex_save && guid_save - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') + typ = (!ex_save && !guid_save ? 'example answer and guidance' : (!guid_save ? 'guidance' : 'example answer')) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: success_message(typ, _('saved')) else if !ex_save && !guid_save flash[:notice] = failed_create_error(example_answer, _('example answer')) + '\n' + @@ -96,7 +98,7 @@ @section = @question.section @phase = @section.phase if @example_answer.destroy - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: success_message(_('information'), _('deleted')) else redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: flash[:notice] = failed_destroy_error(@example_answer, _('example answer')) end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 742ce33..bbf3384 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -253,7 +253,7 @@ @template.description = params["template-desc"] if @template.update_attributes(params[:template]) - flash[:notice] = _('Information was successfully updated.') + flash[:notice] = success_message(_('template'), _('saved')) else flash[:notice] = failed_update_error(@template, _('template')) @@ -282,7 +282,7 @@ @template.description = params['template-desc'] if @template.save - redirect_to admin_template_template_path(@template), notice: _('Information was successfully created.') + redirect_to admin_template_template_path(@template), notice: success_message(_('template'), _('created')) else @hash = @template.to_hash flash[:notice] = failed_create_error(@template, _('template')) diff --git a/test/functional/annotations_controller_test.rb b/test/functional/annotations_controller_test.rb index 67c7756..cf299b7 100644 --- a/test/functional/annotations_controller_test.rb +++ b/test/functional/annotations_controller_test.rb @@ -50,20 +50,20 @@ post admin_create_annotation_path(id: Annotation.first.id), params_both assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" - assert_equal _('Information was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal "some guidance text", Annotation.last.text, "expected the guidance to have been created!" assert_equal "example answer text", Annotation.all[-2].text, "expected the example answer to have been created" # just an example answer post admin_create_annotation_path(id: Annotation.first.id), params_example assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" - assert_equal _('Information was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal "example answer text", Annotation.last.text, "expected the record to have been created!" # just some guidance post admin_create_annotation_path(id: Annotation.first.id), params_guid assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" - assert_equal _('Information was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal "some guidance text", Annotation.last.text, "expected the record to have been created!" end @@ -84,19 +84,19 @@ # Valid save for guidance only put admin_update_annotation_path(id: Annotation.first.id), params_guid - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" assert_equal 'UPDATE', Annotation.first.text, "expected the record to have been updated" # valid save for example only put admin_update_annotation_path(id: Annotation.first.id), params_example - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" assert_equal 'UPDATE', Annotation.first.text, "expected the record to have been updated" # valid save for both example answer and guidance put admin_update_annotation_path(id: Annotation.first.id), params_both - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" assert_equal 'gUPDATE', Annotation.first.text, "expected the record to have been updated" @@ -115,7 +115,7 @@ sign_in @user delete admin_destroy_annotation_path(id: id) - assert_equal _('Information was successfully deleted.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_response :redirect assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true§ion_id=#{@question.section.id}" assert assigns(:question) diff --git a/test/functional/guidance_groups_controller_test.rb b/test/functional/guidance_groups_controller_test.rb index 234e319..f4d55ff 100644 --- a/test/functional/guidance_groups_controller_test.rb +++ b/test/functional/guidance_groups_controller_test.rb @@ -59,7 +59,7 @@ post admin_create_guidance_group_path(@user.org), {guidance_group: params} assert_response :redirect assert_redirected_to admin_index_guidance_path(@user.org) - assert_equal _('Guidance group was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert assigns(:guidance_group) assert_equal 'Testing create', GuidanceGroup.last.name, "expected the record to have been created!" @@ -95,7 +95,7 @@ sign_in @user put admin_update_guidance_group_path(GuidanceGroup.first), {guidance_group: params} - assert_equal _('Guidance group was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to "#{admin_index_guidance_path(@user.org)}?name=Testing+UPDATE" assert assigns(:guidance_group) @@ -121,7 +121,7 @@ delete admin_destroy_guidance_group_path(GuidanceGroup.first) assert_response :redirect assert_redirected_to admin_index_guidance_path - assert_equal _('Guidance group was successfully deleted.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do GuidanceGroup.find(id).nil? end diff --git a/test/functional/guidances_controller_test.rb b/test/functional/guidances_controller_test.rb index 4d0e8c2..a7f7696 100644 --- a/test/functional/guidances_controller_test.rb +++ b/test/functional/guidances_controller_test.rb @@ -96,7 +96,7 @@ post admin_create_guidance_path(@user.org), params assert_response :redirect assert_redirected_to admin_edit_guidance_path(Guidance.last) - assert_equal _('Guidance was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert assigns(:guidance) assert_equal 'Testing create', Guidance.last.text, "expected the record to have been created!" @@ -120,7 +120,7 @@ put admin_update_guidance_path(Guidance.first), params assert_response :redirect - assert_equal _('Guidance was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_redirected_to "#{admin_edit_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" @@ -145,7 +145,7 @@ delete admin_destroy_guidance_path(Guidance.first) assert_response :redirect assert_redirected_to admin_index_guidance_path - assert_equal _('Guidance was successfully deleted.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert assigns(:guidance) assert_raise ActiveRecord::RecordNotFound do Guidance.find(id).nil? diff --git a/test/functional/orgs_controller_test.rb b/test/functional/orgs_controller_test.rb index c467ff0..8b7ca8b 100644 --- a/test/functional/orgs_controller_test.rb +++ b/test/functional/orgs_controller_test.rb @@ -56,7 +56,7 @@ sign_in @user put admin_update_org_path(@org), {org: params} - assert_equal _('Organisation was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :success assert assigns(:org) assert_equal 'Testing UPDATE', @org.reload.name, "expected the record to have been updated" diff --git a/test/functional/phases_controller_test.rb b/test/functional/phases_controller_test.rb index 3cd91b5..5b26435 100644 --- a/test/functional/phases_controller_test.rb +++ b/test/functional/phases_controller_test.rb @@ -153,7 +153,7 @@ sign_in @user post admin_create_phase_path(@template.phases.first), {phase: params} - assert_equal _('Information was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_response :redirect assert_redirected_to admin_show_phase_path(id: Phase.last.id, edit: 'true') assert assigns(:phase) @@ -186,7 +186,7 @@ # Valid save put admin_update_phase_path(@template.phases.first), {phase: params} - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to admin_show_phase_url(@template.phases.first) assert assigns(:phase) @@ -223,7 +223,7 @@ delete admin_destroy_phase_path(id: @template.phases.first.id, phase_id: id) assert_response :redirect assert_redirected_to admin_template_template_path(@template) - assert_equal _('Information was successfully deleted.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Phase.find(id).nil? end diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb index 75708f2..4d98b0b 100644 --- a/test/functional/plans_controller_test.rb +++ b/test/functional/plans_controller_test.rb @@ -87,7 +87,7 @@ sign_in @user post plans_path(format: :js), params - assert flash[:notice].include?(_('Plan was successfully created.')) + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_response :success assert assigns(:plan) assert_equal "Testing Create", Plan.last.title, "expected the record to have been created" @@ -128,7 +128,7 @@ sign_in @user put plan_path(@plan), {plan: params} - assert_equal _('Plan was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to plan_url(@plan) assert assigns(:plan) @@ -159,7 +159,7 @@ sign_in @user post duplicate_plan_path(@plan, format: :js) @duplicate_plan = Plan.last - assert_equal _('Plan was successfully duplicated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('copied') assert_response :success assert assigns(:plan) assert_equal 'Copy of Test Plan', @duplicate_plan.title, "Copy of" @@ -183,7 +183,7 @@ sign_in @user delete plan_path(@plan) - assert_equal _('Plan was successfully deleted.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_response :redirect assert assigns(:plan) assert_redirected_to plans_path diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index ce6414c..61007c4 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -57,7 +57,7 @@ assert_response :redirect 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 flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal 'Test Question', Question.last.text, "expected the record to have been created!" # Make sure that the template's dirty flag got set @@ -92,7 +92,7 @@ # Valid save put admin_update_question_path(@section.questions.first), {question: params} - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') 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) @@ -137,7 +137,7 @@ 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 flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Question.find(id).nil? end diff --git a/test/functional/registrations_controller_test.rb b/test/functional/registrations_controller_test.rb index 6f15e6c..b5c7126 100644 --- a/test/functional/registrations_controller_test.rb +++ b/test/functional/registrations_controller_test.rb @@ -85,7 +85,7 @@ # Change name put user_registration_path, {user: {email: @user.email, firstname: 'Testing', surname: 'UPDATE', org_id: Org.first.id}} - assert_equal _('Details successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') assert_response :redirect assert_redirected_to edit_user_registration_url diff --git a/test/functional/roles_controller_test.rb b/test/functional/roles_controller_test.rb index 7937867..c0f7a98 100644 --- a/test/functional/roles_controller_test.rb +++ b/test/functional/roles_controller_test.rb @@ -91,7 +91,7 @@ # Valid save put role_path(role), {role: params} - assert_equal _('Sharing details successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to share_plan_path(@plan) assert assigns(:role) diff --git a/test/functional/sections_controller_test.rb b/test/functional/sections_controller_test.rb index 2856a89..0c8e1e1 100644 --- a/test/functional/sections_controller_test.rb +++ b/test/functional/sections_controller_test.rb @@ -51,7 +51,7 @@ post admin_create_section_path(@phase), {section: params} 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 flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_equal 'Section Tester', Section.last.title, "expected the record to have been created!" # Make sure that the template's dirty flag got set @@ -84,7 +84,7 @@ # Valid save put admin_update_section_path(@phase.sections.first), {section: params} - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :redirect assert_redirected_to admin_show_phase_url(id: @phase.id, section_id: @phase.sections.first.id, edit: 'true') assert_equal 'Phase - UPDATE', @phase.sections.first.title, "expected the record to have been updated" @@ -123,7 +123,7 @@ 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 flash[:notice].start_with?('Successfully') && flash[:notice].include?('deleted') assert_raise ActiveRecord::RecordNotFound do Section.find(id).nil? end diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 0987259..048f679 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -149,7 +149,7 @@ sign_in @user post admin_create_template_path(@user.org), {template: params} - assert_equal _('Information was successfully created.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('created') assert_response :redirect assert_redirected_to admin_template_template_url(Template.last.id) assert assigns(:template) @@ -192,7 +192,7 @@ # Make sure we get the right response when editing an unpublished template put admin_update_template_path(current), {template: params} - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') && flash[:notice].include?('saved') assert_response :success assert assigns(:template) assert assigns(:hash) diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 02726e2..c0a8aee 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -31,9 +31,6 @@ sign_in @user -puts "USER: #{@user.org.inspect}" -puts "ORG: #{Org.last.inspect}" - get admin_index_users_path assert_response :success assert assigns(:users) @@ -67,7 +64,7 @@ # Valid save put admin_update_permissions_user_path(@user.org.users.last), {user: params} - assert_equal _('Information was successfully updated.'), flash[:notice] + assert flash[:notice].start_with?('Successfully') assert_response :redirect assert_redirected_to admin_index_users_url @user.org.users.last.perms.each do |perm|