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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def new_before
@object.attributes = @object.product.master.attributes.except("id", "created_at", "deleted_at",
"sku", "is_master")
# Shallow Clone of the default price to populate the price field.
@object.prices.build(@object.product.master.default_price.attributes.except("id", "created_at", "updated_at", "deleted_at"))
if (default_price = @object.product.master.default_price)
@object.prices.build(default_price.attributes.except("id", "created_at", "updated_at", "deleted_at"))
end
end

def collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ module Admin
describe VariantsController, type: :controller do
stub_authorization!

describe "#new" do
render_views

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?


let(:product) { create(:product_with_option_types) }

before do
create(:option_value, option_type: product.option_types.first)
end

subject { get :new, params: {product_id: product.slug} }

it "builds a variant with the master default price" do
subject

expect(response).to be_successful
expect(assigns(:variant).default_price.amount).to eq(product.master.default_price.amount)
end

context "when the product has no master default price" do
before do
product.master.prices.delete_all
end

it "builds a variant with a new default price" do
subject

default_price = assigns(:variant).default_price

expect(response).to be_successful
expect(default_price).to be_new_record
expect(default_price.amount).to be_nil
expect(default_price.currency).to eq(Spree::Config[:currency])
end
end
end

describe "#index" do
let(:product) { create(:product) }
let(:params) { {product_id: product.slug} }
Expand Down
Loading