Specs are greengg!

This commit is contained in:
2015-09-22 09:56:45 +02:00
parent ee199d7da8
commit 735ed9b70d
2 changed files with 39 additions and 24 deletions
+23 -8
View File
@@ -124,31 +124,35 @@ describe List do
end end
describe '#place_order' do describe '#place_order' do
subject{ list.place_order order_options }
describe "first order" do
let(:order_options){ {user: user, first_order: true} }
it 'returns an order object' do it 'returns an order object' do
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user).should be_a Order order_options[:product_orders] = [{'product_id' => product.id, 'quantity' => 7}]
subject.should be_a Order
end end
it 'creates an order' do it 'creates an order' do
expect{ list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user) }.to change{ Order.count }.by(1) order_options[:product_orders] = [{'product_id' => product.id, 'quantity' => 7}]
expect{ subject }.to change{ Order.count }.by(1)
end end
describe 'broadcasting' do describe 'broadcasting' do
it 'broadcasts to the user and the supplier the active order counter' do it 'broadcasts to the user and the supplier the active order counter' do
# create existing order # create existing order to test with counts higher than 2
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user) list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user, first_order: true)
# expect{ # expect{
# list.place_order(product_orders: [{product_id: product.id, quantity: 5}], user: user) # list.place_order(product_orders: [{product_id: product.id, quantity: 5}], user: user)
# }.to broadcast_to_user(user.id).message('orders_placed_count').with(count: 2) # }.to broadcast_to_user(user.id).message('orders_placed_count').with(count: 2)
expect{ order_options[:product_orders] = [{'product_id' => product.id, 'quantity' => 7}]
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 5}], user: user, first_order: false) expect{ subject }.to broadcast_to_supplier(supplier.id).message('new_list').with hash_including(supplier_orders_placed_count: 2)
}.to broadcast_to_supplier(supplier.id).message('supplier_orders_placed_count').with(count: 2)
end end
end end
it 'sets the list price as kind of caching' do it 'sets the list price as kind of caching' do
product.price.should eq 2.22
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user) list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user)
list.reload list.reload
list.price.should == 15.54 list.price.should == 15.54
@@ -157,6 +161,17 @@ describe List do
describe 'product order creation' describe 'product order creation'
end end
describe "followup order" do
let(:order_options){ {user: user, first_order: false} }
describe 'broadcasting' do
it 'broadcasts to the user and the supplier the active order counter' do
order_options[:product_orders] = [{'product_id' => product.id, 'quantity' => 7}]
expect{ subject }.to broadcast_to_supplier(supplier.id).message('new_order').with hash_including(supplier_orders_placed_count: 1)
end
end
end
end
describe '#close!' do describe '#close!' do
it 'removes the helped mark' do it 'removes the helped mark' do
list_options[:needs_help] = true list_options[:needs_help] = true
@@ -25,7 +25,7 @@ module Matchers
relevant_broadcasts = test_broadcaster.broadcasts.select{|b| b[:channel] =~ /^\/supplier\/#{@supplier_id}/ && b[:data][:event] == @message} relevant_broadcasts = test_broadcaster.broadcasts.select{|b| b[:channel] =~ /^\/supplier\/#{@supplier_id}/ && b[:data][:event] == @message}
@failure_debug_content = "was #{relevant_broadcasts.map{|b| b[:data][:data].inspect}.join(" and ")}" @failure_debug_content = "was #{relevant_broadcasts.map{|b| b[:data][:data].inspect}.join(" and ")}"
relevant_broadcasts.any?{|b| b[:data][:data] == @target_object} relevant_broadcasts.any?{|b| @target_object === b[:data][:data] }
end end
def message(msg) def message(msg)