50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
# encoding: UTF-8
|
|
|
|
require 'spec_helper'
|
|
|
|
describe Table do
|
|
describe 'for_supplier' do
|
|
let(:supplier){ create(:supplier) }
|
|
let(:options){ Hash.new }
|
|
subject{ Table.for_supplier(supplier, options) }
|
|
it "should return an empty array by default" do
|
|
subject.should be_empty
|
|
end
|
|
describe 'with multiple tables' do
|
|
before do
|
|
@table1 = create :table, supplier: supplier, number: 2
|
|
@table2 = create :table, supplier: supplier, number: 4
|
|
@table3 = create :table, supplier: supplier, number: 6
|
|
@table4 = create :table, number: 4
|
|
end
|
|
it "returns all by default" do
|
|
subject.should == [@table1, @table2, @table3]
|
|
end
|
|
|
|
it "should paginate the result" do
|
|
options[:per_page] = 2
|
|
subject.size.should == 2
|
|
subject.total_count.should == 3
|
|
end
|
|
|
|
it "should filter by table number using from_number" do
|
|
options[:per_page] = 1
|
|
options[:from_number] = 3
|
|
subject.size.should == 1
|
|
subject.total_pages.should == 2
|
|
subject.first.number.should == 4
|
|
|
|
end
|
|
it "should filter by table number using from_number and to_number" do
|
|
options[:from_number] = 3
|
|
options[:to_number] = 5
|
|
subject.size.should == 1
|
|
subject.total_pages.should == 1
|
|
subject.first.number.should == 4
|
|
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|