Sha256: c96793c4f5ade16c000374934181975aefcc533cc8118fb942518a8fa3527fb1

Contents?: true

Size: 1.06 KB

Versions: 32

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'

describe Spree::Order, type: :model do
  let(:order) { stub_model(Spree::Order) }
  before do
    Spree::Order.define_state_machine!
  end

  context "validations" do
    context "email validation" do
      # Regression test for https://github.com/spree/spree/issues/1238
      it "o'brien@gmail.com is a valid email address" do
        order.state = 'address'
        order.email = "o'brien@gmail.com"
        expect(order.error_on(:email).size).to eq(0)
      end
    end
  end

  context "#save" do
    context "when associated with a registered user" do
      let(:user) { double(:user, email: "test@example.com") }

      before do
        allow(order).to receive_messages user: user
      end

      it "should assign the email address of the user" do
        order.run_callbacks(:create)
        expect(order.email).to eq(user.email)
      end
    end
  end

  context "in the cart state" do
    it "should not validate email address" do
      order.state = "cart"
      order.email = nil
      expect(order.error_on(:email).size).to eq(0)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.2.2 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.1.1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.0.3 spec/models/spree/order/callbacks_spec.rb
solidus_core-1.4.2 spec/models/spree/order/callbacks_spec.rb
solidus_core-1.3.2 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.3.0 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.0.2 spec/models/spree/order/callbacks_spec.rb
solidus_core-1.4.1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.2.1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.2.0 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.1.0 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/order/callbacks_spec.rb
solidus_core-2.0.1 spec/models/spree/order/callbacks_spec.rb