Fix active order display in supplier side
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
FactoryGirl.define do
|
||||
factory :order do
|
||||
association :list
|
||||
association :user
|
||||
association :supplier #TODO warning! this may create a different supplier than the one created by the associated table
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
email "test@example.com"
|
||||
sequence( :email ){|i| "test#{i}@example.com" }
|
||||
password "secret"
|
||||
end
|
||||
end
|
||||
|
||||
+67
-11
@@ -2,28 +2,84 @@ require 'spec_helper'
|
||||
|
||||
|
||||
describe List do
|
||||
before :each do
|
||||
@list = create :list
|
||||
end
|
||||
let(:supplier) { create :supplier }
|
||||
let(:user) { create :user }
|
||||
let(:section) { create :section, supplier: supplier}
|
||||
let(:table) { create :table, supplier: supplier}
|
||||
let(:list){ create :list, supplier: supplier, table: table, user_ids: [user.id] }
|
||||
subject { list }
|
||||
describe :as_json do
|
||||
it 'should include _id in as_json serialization' do
|
||||
@list.as_json.keys.map(&:to_sym).should include :_id
|
||||
list.as_json.keys.map(&:to_sym).should include :_id
|
||||
end
|
||||
it 'should include table_number in as_json serialization' do
|
||||
@list.as_json.keys.should include :table_number
|
||||
list.as_json.keys.should include :table_number
|
||||
end
|
||||
end
|
||||
|
||||
describe :mark_as_payed do
|
||||
it "should set payed_at to a time" do
|
||||
@list.payed_at.should be_nil
|
||||
@list.mark_as_payed
|
||||
@list.payed_at.should be_kind_of Time
|
||||
list.payed_at.should be_nil
|
||||
list.mark_as_payed
|
||||
list.payed_at.should be_kind_of Time
|
||||
end
|
||||
it "should set is_payed to true" do
|
||||
@list.is_payed.should be_false
|
||||
@list.mark_as_payed
|
||||
@list.is_payed.should be_true
|
||||
list.is_payed.should be_false
|
||||
list.mark_as_payed
|
||||
list.is_payed.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#move_to_table!' do
|
||||
let(:new_section) { create :section, supplier: supplier}
|
||||
let(:new_table) { create :table, supplier: supplier, section: new_section}
|
||||
before do
|
||||
@order1 = create :order, supplier: supplier, list: list, section: section
|
||||
end
|
||||
|
||||
it 'adds a model to keep track of the movement' do
|
||||
expect{ list.move_to_table! new_table }.to change{ UserTableMove.count }.by(1)
|
||||
end
|
||||
|
||||
it "changes the table" do
|
||||
expect{ list.move_to_table! new_table }.to change{ list.table_id }.to( new_table.id )
|
||||
end
|
||||
|
||||
it "changes the section" do
|
||||
expect{ list.move_to_table! new_table }.to change{ list.section_id }.to( new_section.id )
|
||||
end
|
||||
|
||||
it "changes the section of the orders" do
|
||||
expect{ list.move_to_table! new_table }.to change{ @order1.reload; @order1.section_id }.to( new_section.id )
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_active_orders?' do
|
||||
its(:has_active_orders?) { should be_false }
|
||||
|
||||
it 'returns true when there are placed orders for the list' do
|
||||
create :order, supplier: supplier, list: list, section: section, state: 'placed'
|
||||
list.has_active_orders?.should be_true
|
||||
end
|
||||
|
||||
it 'returns true when there are active orders for the list' do
|
||||
create :order, supplier: supplier, list: list, section: section, state: 'active'
|
||||
list.has_active_orders?.should be_true
|
||||
end
|
||||
|
||||
it 'returns false when there are only delivered orders' do
|
||||
create :order, supplier: supplier, list: list, section: section, state: 'delivered'
|
||||
list.has_active_orders?.should be_false
|
||||
end
|
||||
|
||||
it 'returns false when there are only closed orders' do
|
||||
create :order, supplier: supplier, list: list, section: section, state: 'closed'
|
||||
list.has_active_orders?.should be_false
|
||||
end
|
||||
|
||||
it 'returns false when there are only cancelled orders' do
|
||||
create :order, supplier: supplier, list: list, section: section, state: 'cancelled'
|
||||
list.has_active_orders?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
require 'spec_helper'
|
||||
|
||||
|
||||
describe Order do
|
||||
let(:supplier) { create :supplier }
|
||||
let(:user) { create :user }
|
||||
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' }
|
||||
subject { order }
|
||||
|
||||
its(:placed?) { should be_true }
|
||||
its(:active?) { should be_false }
|
||||
|
||||
describe 'count_active_for_supplier_and_list' do
|
||||
before { order }
|
||||
it 'counts active orders for a list with objects' do
|
||||
Order.count_active_for_supplier_and_list(supplier, list).should == 1
|
||||
end
|
||||
it 'counts active orders for a list with ids' do
|
||||
Order.count_active_for_supplier_and_list(supplier.id, list.id).should == 1
|
||||
end
|
||||
it 'does not count inactive orders' do
|
||||
order.close!
|
||||
Order.count_active_for_supplier_and_list(supplier, list).should == 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
+1
-1
@@ -38,7 +38,7 @@ RSpec.configure do |config|
|
||||
|
||||
# Use color in STDOUT
|
||||
config.color_enabled = true
|
||||
config.fail_fast = true
|
||||
config.fail_fast = false
|
||||
|
||||
# Use color not only in STDOUT but also in pagers and files
|
||||
config.tty = true
|
||||
|
||||
Reference in New Issue
Block a user