forked from spree/spree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure users can set price via api
- Loading branch information
Showing
2 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,32 @@ module Spree | |
render_views | ||
|
||
let!(:order) { create(:order) } | ||
let(:variant) { create(:variant) } | ||
|
||
let(:attributes) { [:number, :item_total, :display_total, :total, | ||
:state, :adjustment_total, | ||
:user_id, :created_at, :updated_at, | ||
:completed_at, :payment_total, :shipment_state, | ||
:payment_state, :email, :special_instructions, | ||
:total_quantity, :display_item_total] } | ||
|
||
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } } | ||
|
||
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista", | ||
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678", | ||
:country_id => Country.first.id, :state_id => State.first.id} } | ||
|
||
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista", | ||
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678", | ||
:country_id => Country.first.id, :state_id => State.first.id} } | ||
|
||
let!(:payment_method) { create(:payment_method) } | ||
|
||
let(:current_api_user) do | ||
user = Spree.user_class.new(:email => "[email protected]") | ||
user.generate_spree_api_key! | ||
user | ||
end | ||
|
||
before do | ||
stub_authentication! | ||
|
@@ -68,22 +87,7 @@ module Spree | |
assert_unauthorized! | ||
end | ||
|
||
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } } | ||
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista", | ||
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678", | ||
:country_id => Country.first.id, :state_id => State.first.id} } | ||
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista", | ||
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678", | ||
:country_id => Country.first.id, :state_id => State.first.id} } | ||
let!(:payment_method) { create(:payment_method) } | ||
let(:current_api_user) do | ||
user = Spree.user_class.new(:email => "[email protected]") | ||
user.generate_spree_api_key! | ||
user | ||
end | ||
|
||
it "can create an order" do | ||
variant = create(:variant) | ||
api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } } | ||
response.status.should == 201 | ||
order = Order.last | ||
|
@@ -99,7 +103,6 @@ module Spree | |
|
||
# Regression test for #3404 | ||
it "can specify additional parameters for a line item" do | ||
variant = create(:variant) | ||
Order.should_receive(:create!).and_return(order = Spree::Order.new) | ||
order.stub(:associate_user!) | ||
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem')) | ||
|
@@ -116,9 +119,21 @@ module Spree | |
response.status.should == 201 | ||
end | ||
|
||
it "sets line items price" do | ||
api_post :create, :order => { | ||
:line_items => { | ||
"0" => { | ||
:price => 33.0, :variant_id => variant.to_param, :quantity => 5 | ||
} | ||
} | ||
} | ||
|
||
expect(response.status).to eq 201 | ||
expect(Order.last.line_items.first.price.to_f).to eq 33.0 | ||
end | ||
|
||
# Regression test for #3404 | ||
it "does not update line item needlessly" do | ||
variant = create(:variant) | ||
Order.should_receive(:create!).and_return(order = Spree::Order.new) | ||
order.stub(:associate_user!) | ||
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem')) | ||
|