diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 395f419..ffdfb33 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -20,13 +20,14 @@ ## # PUT /organisations/1 def admin_update + attrs = org_params @org = Org.find(params[:id]) authorize @org @org.banner_text = params["org_banner_text"] - @org.logo = params[:org][:logo] if params[:org][:logo] - assign_params = params[:org].dup + @org.logo = attrs[:logo] if attrs[:logo] + assign_params = attrs.dup assign_params.delete(:logo) - assign_params.delete(:contact_email) unless params[:org][:contact_email].present? + assign_params.delete(:contact_email) unless attrs[:contact_email].present? begin if @org.update_attributes(assign_params) @@ -37,7 +38,7 @@ # its unclear why its doing this. Placing a check here for the data type. We should reasses though # when doing a broader eval of the look/feel of the site and we come up with a standardized way of # displaying errors - flash[:notice] = @org.errors.collect{|a, e| "#{a} - #{(e.instance_of?(String) ? e : e.message)}"}.join('
').html_safe + flash[:notice] = generate_error_notice(@org) render action: "admin_edit" end rescue Dragonfly::Job::Fetch::NotFound => dflye @@ -45,4 +46,11 @@ render action: "admin_edit" end end + + private + def org_params + # The form on the page is weird. The text and template/section/question stuff is outside of the normal form params + params.require(:org).permit(:name, :abbreviation, :target_url, :is_other, :banner_text, :language_id, + :region_id, :logo, :contact_email) + end end diff --git a/app/views/orgs/admin_edit.html.erb b/app/views/orgs/admin_edit.html.erb index 5d4da43..9bf8d6c 100644 --- a/app/views/orgs/admin_edit.html.erb +++ b/app/views/orgs/admin_edit.html.erb @@ -63,7 +63,7 @@ <%= _('Organisation type') %> - <%= @org.organisation_type %> + <%= @org.org_type %> diff --git a/test/functional/orgs_controller_test.rb b/test/functional/orgs_controller_test.rb index 40b5086..476ff23 100644 --- a/test/functional/orgs_controller_test.rb +++ b/test/functional/orgs_controller_test.rb @@ -1,51 +1,85 @@ require 'test_helper' -class OrgsControllerTest < ActionController::TestCase -=begin +class OrgsControllerTest < ActionDispatch::IntegrationTest + + include Devise::Test::IntegrationHelpers + + # TODO: The following methods SHOULD replace the old 'admin_' prefixed methods. The children_org and templates_org + # routes don't even have an endpoint defined in the controller! + # + # SHOULD BE: + # -------------------------------------------------- + # orgs GET /orgs orgs#index + # POST /orgs orgs#create + # org GET /orgs/:id orgs#show + # PATCH /orgs/:id orgs#update + # PUT /orgs/:id orgs#update + # DELETE /orgs/:id orgs#destroy + # + # CURRENT RESULTS OF `rake routes` + # -------------------------------------------------- + # children_org GET /org/admin/:id/children orgs#children + # templates_org GET /org/admin/:id/templates orgs#templates + # admin_show_org GET /org/admin/:id/admin_show orgs#admin_show + # admin_edit_org GET /org/admin/:id/admin_edit orgs#admin_edit + # admin_update_org PUT /org/admin/:id/admin_update orgs#admin_update + setup do - @organisation = organisations(:one) + @org = Org.first + scaffold_org_admin(@org) end - test "should get index" do - get :index + # GET /org/admin/:id/admin_show (admin_show_org_path) + # ---------------------------------------------------------- + test 'show the org' do + # Should redirect user to the root path if they are not logged in! + get admin_show_org_path(@org) + assert_unauthorized_redirect_to_root_path + + sign_in @user + + get admin_show_org_path(@org) assert_response :success - assert_not_nil assigns(:organisations) + assert assigns(:org) end - test "should get new" do - get :new + # GET /org/admin/:id/admin_edit (admin_edit_org_path) + # ---------------------------------------------------------- + test 'load the edit org page' do + # Should redirect user to the root path if they are not logged in! + get admin_edit_org_path(@org) + assert_unauthorized_redirect_to_root_path + + sign_in @user + + get admin_edit_org_path(@org) assert_response :success + assert assigns(:org) + assert assigns(:languages) end - - test "should create organisation" do - assert_difference('Org.count') do - post :create, organisation: { abbreviation: @organisation.abbreviation, banner_file_id: @organisation.banner_file_id, description: @organisation.description, domain: @organisation.domain, logo_file_id: @organisation.logo_file_id, name: @organisation.name, stylesheet_file_id: @organisation.stylesheet_file_id, target_url: @organisation.target_url, type_id: @organisation.type_id, wayfless_entite: @organisation.wayfless_entite } - end - - assert_redirected_to organisation_path(assigns(:organisation)) - end - - test "should show organisation" do - get :show, id: @organisation + + # PUT /org/admin/:id/admin_update (admin_update_org_path) + # ---------------------------------------------------------- + test 'update the org' do + params = {name: 'Testing UPDATE'} + + # Should redirect user to the root path if they are not logged in! + put admin_update_org_path(@org), {org: params} + assert_unauthorized_redirect_to_root_path + + sign_in @user + + put admin_update_org_path(@org), {org: params} + assert_equal _('Organisation was successfully updated.'), flash[:notice] + assert_response :redirect + assert_redirected_to admin_show_org_path(@org) + assert assigns(:org) + assert_equal 'Testing UPDATE', @org.reload.name, "expected the record to have been updated" + + # Invalid object + put admin_update_org_path(@org), {org: {name: nil}} + assert flash[:notice].starts_with?(_('Unable to save your changes.')) assert_response :success + assert assigns(:org) end - - test "should get edit" do - get :edit, id: @organisation - assert_response :success - end - - test "should update organisation" do - put :update, id: @organisation, organisation: { abbreviation: @organisation.abbreviation, banner_file_id: @organisation.banner_file_id, description: @organisation.description, domain: @organisation.domain, logo_file_id: @organisation.logo_file_id, name: @organisation.name, stylesheet_file_id: @organisation.stylesheet_file_id, target_url: @organisation.target_url, type_id: @organisation.type_id, wayfless_entite: @organisation.wayfless_entite } - assert_redirected_to organisation_path(assigns(:organisation)) - end - - test "should destroy organisation" do - assert_difference('Org.count', -1) do - delete :destroy, id: @organisation - end - - assert_redirected_to organisations_path - end -=end end