supplier improvements

This commit is contained in:
2013-03-09 14:18:21 +01:00
parent 730f910881
commit cc13797f5a
53 changed files with 819 additions and 156 deletions
@@ -0,0 +1,64 @@
require 'spec_helper'
describe ProductCategoryDecorator do
let(:supplier) { build :supplier }
let(:product_category){ build :product_category, supplier: supplier }
let(:day_names) { %w[sunday monday tuesday wednesday thursday friday saturday]}
subject { ActiveDecorator::Decorator.instance.decorate product_category }
describe '#visible_on' do
before do
ActiveDecorator::ViewContext.current = Suppliers::ApplicationController.new.view_context
product_category.stub(:week_days).and_return([1,1,0,0,0,1,0])
I18n.stub(:t).with('date.day_names').and_return(day_names)
end
its(:visible_on) { should include 'sunday' }
its(:visible_on) { should include 'monday' }
its(:visible_on) { should_not include 'tuesday' }
its(:visible_on) { should_not include 'wednesday' }
its(:visible_on) { should_not include 'thursday' }
its(:visible_on) { should include 'friday' }
its(:visible_on) { should_not include 'saturday' }
its(:visible_on) { should start_with 'monday'}
it "starts with sunday if week does not start on monday" do
supplier.stub(:week_starts_on_monday?).and_return(false)
subject.visible_on.should start_with 'sunday'
end
it "includes the time when full day is false" do
product_category.full_day = false
product_category.start_from = 800
product_category.end_on = 900
subject.visible_on.should include '13:20 - 15:00'
end
it "shows a dash when it is never visible" do
product_category.stub(:week_days).and_return([0,0,0,0,0,0,0])
subject.visible_on.should include 'icon-eye-close'
end
it "should display an icon when always visible" do
product_category.stub(:week_days).and_return([1,1,1,1,1,1,1])
subject.visible_on.should include 'icon-refresh'
end
it "should only display time when all days active and time range given" do
product_category.stub(:week_days).and_return([1,1,1,1,1,1,1])
product_category.full_day = false
product_category.start_from = 800
product_category.end_on = 900
subject.visible_on.should == '13:20 - 15:00'
end
end
describe '#products' do
it "decorates products" do
product = build :product
product_category.instance_variable_set('@products', all: [product])
subject.products.first.should be_a ProductDecorator
end
end
end
+17
View File
@@ -0,0 +1,17 @@
require 'spec_helper'
describe I18n do
describe 'translate' do
describe 'day_names' do
it "returns english day names" do
I18n.locale = :en
I18n.t('date.day_names').first.should == 'Sunday'
end
it "returns dutch day names" do
I18n.locale = :nl
I18n.t('date.day_names').first.should == 'zondag'
end
end
end
end