2014-12-04 19:50:02 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: orders
|
|
|
|
#
|
2015-03-19 16:22:55 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# user_id :integer
|
|
|
|
# price_cents :integer
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# cancelled :boolean default("f")
|
2014-12-04 19:50:02 +01:00
|
|
|
#
|
|
|
|
|
2015-09-02 20:33:35 +02:00
|
|
|
describe Order do
|
|
|
|
before :each do
|
2015-09-03 10:08:17 +02:00
|
|
|
@user = create :user
|
|
|
|
@order = create :order, user: @user
|
2015-09-02 20:33:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a valid factory' do
|
|
|
|
expect(@order).to be_valid
|
|
|
|
end
|
2015-09-03 10:08:17 +02:00
|
|
|
|
|
|
|
describe 'cancelling' do
|
|
|
|
it 'should cancel the order' do
|
|
|
|
@order.cancel
|
|
|
|
expect(@order.cancelled).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not happen twice' do
|
|
|
|
@order.cancel
|
|
|
|
expect(@order.cancel).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not work on old orders' do
|
|
|
|
order = create :order, created_at: 3.days.ago
|
|
|
|
expect(order.cancel).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should change the orders_count' do
|
|
|
|
expect(@user.reload.orders_count).to eq(1)
|
|
|
|
@order.cancel
|
|
|
|
expect(@user.reload.orders_count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2015-09-02 20:33:35 +02:00
|
|
|
end
|