Sha256: 7ac99ee2897f89dfe1d811f81b588bf066727a5df10df5c59e210d0f3bf016a9

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

module SimpleCart
  RSpec.describe Order, type: :model do
    subject(:order) { Order.new(:total_price => 12, :completed_date => '2016') }

    it 'should be a Order class' do
      expect(Order.is_a?(Class)).to be_truthy
      expect(Order < ActiveRecord::Base).to be_truthy
    end

    it 'should include AASM module' do
      expect(Order.include?(AASM)).to be_truthy
    end

    it { is_expected.to respond_to(:subtotal) }

    it { should have_db_column(:total_price).of_type(:decimal) }
    it { should have_db_column(:completed_date).of_type(:date) }
    it { should have_db_column(:aasm_state).of_type(:string) }

    it { should have_one(:credit_card) }
    it { should belong_to(:delivery) }
    it { should have_one(:billing_address) }
    it { should have_one(:shipping_address) }
    it { should have_many(:order_items).dependent(:destroy) }

    it { should validate_presence_of(:total_price) }
    it { should validate_presence_of(:completed_date) }
    it { should validate_presence_of(:aasm_state) }
    it { should validate_numericality_of(:total_price) }
    it { should validate_inclusion_of(:aasm_state).in_array(['in_progress', 'in_queue', 'in_delivery', 'delivered', 'canceled']) }

    it 'should have 5 specified aasm states' do
      expect(Order.aasm.states.map(&:name)).to eq([:in_progress, :in_queue, :in_delivery, :delivered, :canceled])
    end

    it 'should have in_progress state on initialize' do
      expect(order).to have_state(:in_progress)
    end

    it 'should change in_progress state to in_queue on queue event' do
      expect(order).to transition_from(:in_progress).to(:in_queue).on_event(:queued)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_cart-0.0.5 spec/models/simple_cart/order_spec.rb
simple_cart-0.0.4 spec/models/simple_cart/order_spec.rb