require 'spec_helper'

describe ProductCategoryDecorator, disabled: true 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
      Thread.current[:active_decorator_view_contexts] = [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 'product-category-visible-never'
    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 'product-category-visible-always'
    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
