We like passing specs
This commit is contained in:
@@ -9,7 +9,10 @@ class Employee
|
|||||||
}
|
}
|
||||||
DEFAULT_SETTINGS.each do |attribute, default_value|
|
DEFAULT_SETTINGS.each do |attribute, default_value|
|
||||||
define_method(attribute) { settings.public_send attribute }
|
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
|
if default_value == true or default_value == false # boolean
|
||||||
define_method(:"#{attribute}?"){ public_send attribute }
|
define_method(:"#{attribute}?"){ public_send attribute }
|
||||||
end
|
end
|
||||||
@@ -49,7 +52,7 @@ class Employee
|
|||||||
#settings.persist!
|
#settings.persist!
|
||||||
#orig_save(*args)
|
#orig_save(*args)
|
||||||
#end
|
#end
|
||||||
before_validation(on: :save){ settings.persist! }
|
before_save { settings.persist! }
|
||||||
|
|
||||||
def settings
|
def settings
|
||||||
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
||||||
|
|||||||
@@ -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_section = create :section, title: 'Terrace', supplier: @supplier
|
||||||
# @new_table = create :table, number: 59, section: @new_section, 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_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
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
step "A new order is placed" do
|
step "A new order is placed" do
|
||||||
@user ||= create :user
|
@user ||= create :user
|
||||||
@list = create :list, state: 'active', supplier: @supplier, table: @table, section: @section, user_ids: [@user.id]
|
@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
|
end
|
||||||
|
|
||||||
step "an order with :quantity products :product_name should have been created" do |quantity, product_name|
|
step "an order with :quantity products :product_name should have been created" do |quantity, product_name|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ step "the order should be marked as delivered" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "another order is placed" do
|
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
|
end
|
||||||
|
|
||||||
step "the user order should be created as a new order" do
|
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
|
end
|
||||||
|
|
||||||
step 'the other user orders a product :count times' do |count|
|
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
|
end
|
||||||
|
|
||||||
step 'the other user is part of the list' do
|
step 'the other user is part of the list' do
|
||||||
|
|||||||
@@ -126,30 +126,30 @@ describe List do
|
|||||||
describe '#place_order' do
|
describe '#place_order' do
|
||||||
|
|
||||||
it 'returns an order object' 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
|
end
|
||||||
|
|
||||||
it 'creates an order' do
|
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
|
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
|
||||||
list.place_order(products: {product.id => 7}, user: user)
|
list.place_order(product_orders: [{'product_id' => product.id, 'quantity' => 7}], user: user)
|
||||||
|
|
||||||
# expect{
|
# 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)
|
# }.to broadcast_to_user(user.id).message('orders_placed_count').with(count: 2)
|
||||||
|
|
||||||
expect{
|
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)
|
}.to broadcast_to_supplier(supplier.id).message('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
|
||||||
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.reload
|
||||||
list.price.should == 15.54
|
list.price.should == 15.54
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user