require 'spec_helper'

describe Neuigkeit do
  let(:rubrik) {FactoryGirl.create(:rubrik)}
  let(:user) {FactoryGirl.create(:user)}
  let(:neuigkeit) {(FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id))} 
  let(:attachment) {FactoryGirl.build_stubbed(:attachment)}

  [:title,:text, :rubrik, :author].each do |attr|
    it "should not be valid without #{attr}" do
      neuigkeit.send("#{attr}=".to_sym,nil)
      expect(neuigkeit).not_to be_valid
      expect(neuigkeit.errors[attr]).to have_at_least(1).items
    end
  end
  it "should be created" do
    expect(neuigkeit).to be_valid
    expect(neuigkeit.save).to be true
  end

  it "should be valid" do 
    fp = FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)
    expect(fp).to  be_valid
  end
  it "responds to attachments" do 
    expect(neuigkeit.respond_to?(:attachments)).to be true
  end
  it "uses titlepic attachments as picture" do
    expect(neuigkeit.respond_to?(:picture_robust)).to be true
    attachment.flag_titlepic = true
    expect { neuigkeit.attachments << attachment }.to change {neuigkeit.picture_robust}
  end
  it "is an event if it has a calentry" do
  expect(neuigkeit.event?).to be false
  expect{neuigkeit.calentries << calentry}.to change(neuigkeit, :event?)
  end

  pending "has questions"
  pending "has nlinks"
  pending "has calentries" 
  pending "can be an event"
  pending "is published by date"
  pending "has meeting"
  pending "is shareable"  
end
