Edit product form shows permitted suppliers

This commit is contained in:
Rohan Mitchell
2014-09-12 11:33:47 +10:00
parent a6556f3a4f
commit e50bbeaefb
5 changed files with 26 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
Spree::Admin::ProductsController.class_eval do
before_filter :load_form_data, only: [:bulk_edit, :new]
before_filter :load_form_data, only: [:bulk_edit, :new, :edit]
before_filter :load_bpe_data, only: :bulk_edit
alias_method :location_after_save_original, :location_after_save

View File

@@ -1,5 +0,0 @@
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
:insert_top => "[data-hook='admin_product_form_right']",
:partial => "spree/admin/products/supplier_form",
:name => "add_supplier_to_admin_product",
:original => '18bd94de3eb8bdf8b669932bf04fc59e2e85288b')

View File

@@ -0,0 +1,7 @@
/ insert_top "[data-hook='admin_product_form_right']"
= f.field_container :supplier do
= f.label :supplier
%br
= f.collection_select(:supplier_id, @producers, :id, :name, {:include_blank => true}, {:class => "select2"})
= f.error_message_on :supplier

View File

@@ -1,5 +0,0 @@
= f.field_container :supplier do
= f.label :supplier
%br
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2"})
= f.error_message_on :supplier

View File

@@ -86,11 +86,14 @@ feature %q{
context "as an enterprise user" do
before(:each) do
before do
@new_user = create_enterprise_user
@supplier2 = create(:supplier_enterprise, name: 'Another Supplier')
@supplier_permitted = create(:supplier_enterprise, name: 'Permitted Supplier')
@new_user.enterprise_roles.build(enterprise: @supplier2).save
@new_user.enterprise_roles.build(enterprise: @distributors[0]).save
create(:enterprise_relationship, parent: @supplier_permitted, child: @supplier2,
permissions_list: [:manage_products])
login_to_admin_as @new_user
end
@@ -116,9 +119,8 @@ feature %q{
select taxon.name, from: "product_primary_taxon_id"
# Should only have suppliers listed which the user can manage
within "#product_supplier_id" do
page.should_not have_content @supplier.name
end
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
click_button 'Create'
@@ -127,6 +129,18 @@ feature %q{
product.supplier.should == @supplier2
end
scenario "editing a product" do
product = create(:simple_product, name: 'a product', supplier: @supplier2)
visit spree.edit_admin_product_path product
select 'Permitted Supplier', from: 'product_supplier_id'
click_button 'Update'
flash_message.should == 'Product "a product" has been successfully updated!'
product.reload
product.supplier.should == @supplier_permitted
end
scenario "editing product distributions" do
product = create(:simple_product, supplier: @supplier2)