We like passing specs

This commit is contained in:
2015-04-29 10:55:24 +02:00
parent e4e7198af5
commit dcd8c13e57
6 changed files with 15 additions and 12 deletions
+5 -2
View File
@@ -9,7 +9,10 @@ class Employee
}
DEFAULT_SETTINGS.each do |attribute, default_value|
define_method(attribute) { settings.public_send attribute }
define_method("#{attribute}=") { |value| settings.set attribute, value }
define_method("#{attribute}=") do |value|
is_dirty
settings.set attribute, value
end
if default_value == true or default_value == false # boolean
define_method(:"#{attribute}?"){ public_send attribute }
end
@@ -49,7 +52,7 @@ class Employee
#settings.persist!
#orig_save(*args)
#end
before_validation(on: :save){ settings.persist! }
before_save { settings.persist! }
def settings
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
+1 -1
View File
@@ -20,5 +20,5 @@ step 'a new order on a table in another section is created' do
# @new_section = create :section, title: 'Terrace', supplier: @supplier
# @new_table = create :table, number: 59, section: @new_section, supplier: @supplier
@new_list = create :list, section: @other_section, table: @other_table, supplier: @supplier, user_ids: [@user.id]
@new_order = @new_list.place_order(products: {@product.id => 3}, user: @user)
@new_order = @new_list.place_order(product_orders: [ {'product_id' => @product.id, 'quantity' => 3}], user: @user)
end
+1 -1
View File
@@ -1,7 +1,7 @@
step "A new order is placed" do
@user ||= create :user
@list = create :list, state: 'active', supplier: @supplier, table: @table, section: @section, user_ids: [@user.id]
@order = @list.place_order products: {@product.id => 2}, user: @user
@order = @list.place_order product_orders: [{ 'product_id' => @product.id, 'quantity' => 2}], user: @user
end
step "an order with :quantity products :product_name should have been created" do |quantity, product_name|
+1 -1
View File
@@ -9,7 +9,7 @@ step "the order should be marked as delivered" do
end
step "another order is placed" do
@new_order = @list.place_order(products: {@product.id => 5}, user: @user)
@new_order = @list.place_order(product_orders: [{ 'product_id' => @product.id, 'quantity' => 5}], user: @user)
end
step "the user order should be created as a new order" do
@@ -43,7 +43,7 @@ step "there is another signed in user on the same list" do
end
step 'the other user orders a product :count times' do |count|
@list.place_order products: {@product.id => count.to_i}, user: @other_user
@list.place_order product_orders: [{'product_id' => @product.id, 'quantity' => count.to_i}], user: @other_user
end
step 'the other user is part of the list' do
+6 -6
View File
@@ -126,30 +126,30 @@ describe List do
describe '#place_order' do
it 'returns an order object' do
list.place_order(products: {product.id => 7}, user: user).should be_a Order
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user).should be_a Order
end
it 'creates an order' do
expect{ list.place_order(products: {product.id => 7}, user: user) }.to change{ Order.count }.by(1)
expect{ list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user) }.to change{ Order.count }.by(1)
end
describe 'broadcasting' do
it 'broadcasts to the user and the supplier the active order counter' do
# create existing order
list.place_order(products: {product.id => 7}, user: user)
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user)
# expect{
# list.place_order(products: {product.id => 3}, 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)
expect{
list.place_order(products: {product.id => 5}, user: user)
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 5}], user: user)
}.to broadcast_to_supplier(supplier.id).message('orders_placed_count').with(count: 2)
end
end
it 'sets the list price as kind of caching' do
list.place_order(products: {product.id => 7}, user: user)
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user)
list.reload
list.price.should == 15.54
end