Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/spec/controllers/spree/api/v1/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ module Spree
user
end

shared_examples_for 'action in which order has default store assigned' do
it 'default store should be assigned' do
Spree::Store.create!(
name: "Jaspreet's store", code: 'jaspreet21anand',
url: 'vinsol.com', mail_from_address: 'jaspreet21anand@gmail.com',
default: true
)
expect { api_post :create }.not_to raise_error
order = Order.last
expect(order.store).to eq(Spree::Store.default)
end
end

before do
stub_authentication!
end
Expand Down Expand Up @@ -245,6 +258,8 @@ module Spree
expect(json_response["user_id"]).to eq(current_api_user.id)
end

it_should_behave_like 'action in which order has default store assigned'

it "assigns email when creating a new order" do
api_post :create, :order => { :email => "guest@spreecommerce.com" }
expect(json_response['email']).not_to eq controller.current_api_user
Expand Down Expand Up @@ -669,6 +684,8 @@ def clean_address(address)
expect(json_response["state"]).to eq("cart")
end

it_should_behave_like 'action in which order has default store assigned'

it "can arbitrarily set the line items price" do
api_post :create, order: {
line_items: [{ price: 33.0, variant_id: variant.to_param, quantity: 5 }]
Expand Down
3 changes: 2 additions & 1 deletion backend/app/controllers/spree/admin/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def close_adjustments
private
def order_params
params[:created_by_id] = try_spree_current_user.try(:id)
params.permit(:created_by_id, :user_id)
params[:store_id] ||= current_store.id
params.permit(:created_by_id, :user_id, :store_id)
end

def load_order
Expand Down
14 changes: 13 additions & 1 deletion backend/spec/controllers/spree/admin/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,22 @@ def initialize(user)

# Test for #3346
context "#new" do
it "a new order has the current user assigned as a creator" do
before do
Spree::Store.create!(
name: "Jaspreet's store", code: 'jaspreet21anand',
url: 'vinsol.com', mail_from_address: 'jaspreet21anand@gmail.com',
default: true
)
spree_get :new
end

it "a new order has the current user assigned as a creator" do
expect(assigns[:order].created_by).to eq(controller.try_spree_current_user)
end

it "a new order has default store assigned when no param for store is present" do
expect(assigns[:order].store).to eq(Spree::Store.default)
end
end

# Regression test for #3684
Expand Down
3 changes: 2 additions & 1 deletion core/lib/spree/core/controller_helpers/strong_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def permitted_checkout_attributes

def permitted_order_attributes
permitted_checkout_attributes + [
line_items_attributes: permitted_line_item_attributes
line_items_attributes: permitted_line_item_attributes,
store_attributes: permitted_store_attributes
]
end

Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/core/importer/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.import(user, params)

create_params = params.slice :currency
order = Spree::Order.create! create_params
order.update!(store: Spree::Store.default) unless order.store
order.associate_user!(user)

shipments_attrs = params.delete(:shipments_attributes)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/permitted_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module PermittedAttributes
@@stock_movement_attributes = [
:quantity, :stock_item, :stock_item_id, :originator, :action]

@@store_attributes = [:name, :url, :seo_title, :meta_keywords,
@@store_attributes = [:id, :name, :url, :seo_title, :meta_keywords,
:meta_description, :default_currency, :mail_from_address]

@@store_credit_attributes = [:amount, :category_id, :memo]
Expand Down