mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
New product form shows permitted suppliers
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
Spree::Admin::ProductsController.class_eval do
|
||||
before_filter :load_bpe_data, :only => :bulk_edit
|
||||
before_filter :load_form_data, only: [:bulk_edit, :new]
|
||||
before_filter :load_bpe_data, only: :bulk_edit
|
||||
|
||||
alias_method :location_after_save_original, :location_after_save
|
||||
|
||||
@@ -85,10 +86,13 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
private
|
||||
|
||||
def load_bpe_data
|
||||
current_user.generate_spree_api_key! unless spree_current_user.spree_api_key
|
||||
@spree_api_key = spree_current_user.spree_api_key
|
||||
def load_form_data
|
||||
@producers = OpenFoodNetwork::Permissions.new(spree_current_user).managed_product_enterprises.is_primary_producer.by_name
|
||||
@taxons = Spree::Taxon.order(:name)
|
||||
end
|
||||
|
||||
def load_bpe_data
|
||||
current_user.generate_spree_api_key! unless spree_current_user.spree_api_key
|
||||
@spree_api_key = spree_current_user.spree_api_key
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier_id, t(:supplier)
|
||||
%span.required *
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.collection_select(:supplier_id, @producers, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.error_message_on :supplier
|
||||
.six.columns.omega
|
||||
= f.field_container :name do
|
||||
|
||||
@@ -745,8 +745,6 @@ feature %q{
|
||||
permissions_list: [:manage_products])
|
||||
end
|
||||
|
||||
use_short_wait
|
||||
|
||||
before do
|
||||
@enterprise_user = create_enterprise_user
|
||||
@enterprise_user.enterprise_roles.build(enterprise: supplier_managed1).save
|
||||
@@ -779,6 +777,28 @@ feature %q{
|
||||
expect(page).to have_field 'product_name', with: product_supplied_inactive.name
|
||||
end
|
||||
|
||||
it "allows me to create a product" do
|
||||
taxon = create(:taxon, name: 'Fruit')
|
||||
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
find("a", text: "NEW PRODUCT").click
|
||||
expect(page).to have_content 'NEW PRODUCT'
|
||||
expect(page).to have_select 'product_supplier_id', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name]
|
||||
|
||||
within 'fieldset#new_product' do
|
||||
fill_in 'product_name', with: 'Big Bag Of Apples'
|
||||
select supplier_permitted.name, from: 'product_supplier_id'
|
||||
fill_in 'product_price', with: '10.00'
|
||||
select taxon.name, from: 'product_primary_taxon_id'
|
||||
end
|
||||
click_button 'Create'
|
||||
|
||||
expect(URI.parse(current_url).path).to eq '/admin/products/bulk_edit'
|
||||
expect(flash_message).to eq 'Product "Big Bag Of Apples" has been successfully created!'
|
||||
expect(page).to have_field "product_name", with: 'Big Bag Of Apples'
|
||||
end
|
||||
|
||||
it "allows me to update a product" do
|
||||
p = product_supplied_permitted
|
||||
|
||||
|
||||
Reference in New Issue
Block a user