From 3e1f4628e3665a0483afd7984002d775e20ef828 Mon Sep 17 00:00:00 2001 From: Rob H Date: Wed, 3 Sep 2014 17:04:57 +1000 Subject: [PATCH] Can change owner of enterprises from index page --- app/views/admin/enterprises/index.html.haml | 9 ++++++--- spec/features/admin/enterprises_spec.rb | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/views/admin/enterprises/index.html.haml b/app/views/admin/enterprises/index.html.haml index c783277b63..d2ca8efb2f 100644 --- a/app/views/admin/enterprises/index.html.haml +++ b/app/views/admin/enterprises/index.html.haml @@ -11,11 +11,12 @@ %table#listing_enterprises.index %colgroup %col{style: "width: 25%;"}/ - %col{style: "width: 10%;"}/ + %col{style: "width: 15%;"}/ %col{style: "width: 5%;"}/ - if spree_current_user.admin? - %col{style: "width: 10%;"}/ - %col{style: "width: 20%;"}/ + %col{style: "width: 12%;"}/ + %col{style: "width: 18%;"}/ + %col{style: "width: 25%;"}/ %thead %tr{"data-hook" => "enterprises_header"} %th Name @@ -23,6 +24,7 @@ %th Visible? - if spree_current_user.admin? %th Type + %th Owner %th %tbody = f.fields_for :collection do |enterprise_form| @@ -38,6 +40,7 @@ %td= enterprise_form.check_box :visible - if spree_current_user.admin? %td= enterprise_form.select :type, Enterprise::TYPES, {}, class: 'select2 fullwidth' + %td= enterprise_form.select :owner_id, enterprise.users.map{ |e| [ e.email, e.id ] }, {}, class: "select2 fullwidth" %td{"data-hook" => "admin_users_index_row_actions"} = render 'actions', enterprise: enterprise - if @enterprises.empty? diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 283056ca5c..ee67dc1a73 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -38,6 +38,9 @@ feature %q{ scenario "editing enterprises in bulk" do s = create(:supplier_enterprise) d = create(:distributor_enterprise, type: 'profile') + d_manager = create_enterprise_user + d_manager.enterprise_roles.build(enterprise: d).save + expect(d.owner).to_not eq d_manager login_to_admin_section click_link 'Enterprises' @@ -46,12 +49,14 @@ feature %q{ expect(page).to have_checked_field "enterprise_set_collection_attributes_0_visible" uncheck "enterprise_set_collection_attributes_0_visible" select 'full', from: "enterprise_set_collection_attributes_0_type" + select d_manager.email, from: 'enterprise_set_collection_attributes_0_owner_id' end click_button "Update" flash_message.should == 'Enterprises updated successfully' distributor = Enterprise.find(d.id) expect(distributor.visible).to eq false expect(distributor.type).to eq 'full' + expect(distributor.owner).to eq d_manager end scenario "viewing an enterprise" do