From 45b16d52dde25ad578340738dfee2cc12e151c73 Mon Sep 17 00:00:00 2001 From: Rob H Date: Wed, 18 Jun 2014 11:44:47 +1000 Subject: [PATCH] Add visible checkbox to enterprises index page to allow bulk editing of visibility --- app/controllers/admin/enterprises_controller.rb | 3 ++- app/views/admin/enterprises/index.html.haml | 2 +- spec/features/admin/enterprises_spec.rb | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 5f4d64a99f..50d12b5865 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -10,7 +10,8 @@ module Admin def bulk_update @enterprise_set = EnterpriseSet.new(params[:enterprise_set]) if @enterprise_set.save - redirect_to main_app.admin_enterprises_path, :notice => 'Distributor collection times updated.' + flash[:success] = 'Enterprises updated successfully' + redirect_to main_app.admin_enterprises_path else render :index end diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index 18a295b920..e92f87c231 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -36,7 +36,7 @@ Producer - else %h1.icon-exclamation-sign.with-tip{"data-powertip" => "This enterprise does not have any roles", style: "text-align: center;color: #DA5354"} - %td= enterprise.visible ? 'Visible' : 'Invisible' + %td= enterprise_form.check_box :visible %td= enterprise.description %td{"data-hook" => "admin_users_index_row_actions"} = link_to_with_icon('icon-edit', 'Edit Profile', main_app.edit_admin_enterprise_path(enterprise), class: 'edit') diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 765a6251bf..8b5dcbb64a 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -33,6 +33,23 @@ feature %q{ end end + scenario "editing enterprises in bulk" do + s = create(:supplier_enterprise) + d = create(:distributor_enterprise) + + login_to_admin_section + click_link 'Enterprises' + + within("tr.enterprise-#{d.id}") do + page.should have_field "enterprise_set_collection_attributes_0_visible", checked: true + uncheck "enterprise_set_collection_attributes_0_visible" + end + click_button "Update" + flash_message.should == 'Enterprises updated successfully' + distributor = Enterprise.find(d.id) + distributor.visible.should == false + end + scenario "viewing an enterprise" do e = create(:enterprise)