Sha256: 692d0b3d153e7b4fb13be7f85e2a273575f7e956867ada2d7f6897fd1ff8342e

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require "spec_helper"

module Spree
  describe AssignPartToBundleForm do
    describe "#submit" do
      context "when given a quantity < 1" do
        it "is invalid" do
          product = build(:product)
          part_options = { count: -1 }

          command = AssignPartToBundleForm.new(product, part_options)

          expect(command).to be_invalid
        end
      end

      context "when given options for an existing assembly" do
        it "updates attributes on the existing assignment" do
          bundle = create(:product)
          part = create(:product, can_be_part: true)
          assignment = AssembliesPart.create(
            assembly_id: bundle.id,
            count: 1,
            part_id: part.id
          )

          part_options = { count: 2, id: assignment.id }

          command = AssignPartToBundleForm.new(bundle, part_options)
          command.submit
          assignment.reload

          expect(assignment.count).to be(2)
        end
      end

      context "when given options for an assembly that does not exist" do
        it "creates a new assembly part assignment with the provided options" do
          bundle = create(:product)
          part = create(:product, can_be_part: true)

          part_options = { count: 2, variant_id: part.id }

          command = AssignPartToBundleForm.new(bundle, part_options)

          expect { command.submit }.to change { AssembliesPart.count }.by(1)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_product_bundle-1.0.1 spec/models/spree/assign_part_to_bundle_form_spec.rb
solidus_product_bundle-1.0.0 spec/models/spree/assign_part_to_bundle_form_spec.rb