End of day commit

This commit is contained in:
2014-07-21 20:31:11 +02:00
parent 2fec0b3bb6
commit 8ca59c4e38
27 changed files with 258 additions and 94 deletions
+48 -1
View File
@@ -7,7 +7,8 @@ describe Order do
let(:section) { create :section, supplier: supplier}
let(:table) { create :table, supplier: supplier}
let(:list){ create :list, supplier: supplier, table: table, user_ids: [user.id] }
let(:order) {create :order, supplier: supplier, list: list, state: 'placed' }
let(:order_options){ {supplier: supplier, list: list, state: 'placed' } }
let(:order) {create :order, order_options }
subject { order }
its(:placed?) { should be true }
@@ -41,6 +42,7 @@ describe Order do
describe 'broadcasting' do
it 'broadcasts order info to the user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'order_being_processed' ).with(id: order.id, list_id: list.id)
end
@@ -52,24 +54,29 @@ describe Order do
end
it 'reduces the orders_placed count and communicates it to user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'orders_placed_count' ).with(count: 10)
end
it 'increases the orders_in_process count and communicates it to user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'orders_in_process_count' ).with(count: 8)
end
it 'reduces the orders_placed count and communicates it to supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'orders_placed_count' ).with(count: 10)
end
it 'increases the orders_in_process count and communicates it to supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'orders_in_process_count' ).with(count: 8)
end
end
it 'broadcasts order info to the supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'order_being_processed' ).with(id: order.id, list_id: list.id)
end
@@ -106,4 +113,44 @@ describe Order do
end
end
describe "cancel!" do
it 'changes the state to cancelled' do
order_options[:state] = 'active'
order.cancel!
expect(order.state).to eq 'cancelled'
end
describe 'broadcasting' do
describe 'counters' do
before do
# hack some initial values
Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_placed", 11
Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_in_process", 7
end
it 'decreases the placed count and communicates it to user when state is placed through the order_cancelled broadcast message' do
order_options[:state] = 'placed'
expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, orders_placed_count: 10)
supplier.orders_in_process_count.should == 7 # should not be reduced
end
it 'decreases the placed count and communicates it to supplier when the state is placed through the order_cancelled broadcast message' do
order_options[:state] = 'placed'
expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, orders_placed_count: 10)
supplier.orders_in_process_count.should == 7 # should not be reduced
end
it 'decreases the orders_in_process count and communicates it to user when state is active through the order_cancelled broadcast message' do
order_options[:state] = 'active'
expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, orders_in_process_count: 6)
supplier.orders_placed_count.should == 11 # should not be reduced
end
it 'decreases the orders_in_process count and communicates it to supplier when the state is active through the order_cancelled broadcast message' do
order_options[:state] = 'active'
expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, orders_in_process_count: 6)
supplier.orders_placed_count.should == 11 # should not be reduced
end
end
end
end
end