require 'spec_helper'

describe Cheese do
  it 'validates presence of name' do
    nameless_cheese = FactoryGirl.build(:cheese, name: nil)
    expect(nameless_cheese).to have(1).error_on(:name)
  end

  it 'validates presence of creator' do
    creatorless_cheese = FactoryGirl.build(:cheese, creator_id: nil)
    expect(creatorless_cheese).to have(1).error_on(:creator_id)
  end

  it 'validates presence of description' do
    descriptionless_cheese = FactoryGirl.build(:cheese, description: nil)
    expect(descriptionless_cheese).to have(1).error_on(:description)
  end

  it 'has many fans' do
    cheese = FactoryGirl.create(:cheese)
    user = FactoryGirl.create(:user, favorite_cheese_id: cheese.id)

    expect(Cheese.find(cheese.id).fans).to have(1).items
  end

  it 'has many tags' do
    cheese = FactoryGirl.create(:cheese)
    3.times { FactoryGirl.create(:good_tagging, cheese_id: cheese.id) }
    expect(cheese.tags).to have(3).items
  end
end
