require 'rails_helper'

RSpec.describe Ingredient, type: :model do

  describe 'validation' do

    it 'validates density' do
      i = build(:ingredient)
      expect(i).to be_valid

      i.density = '5'
      expect(i).not_to be_valid

      i.density = '5 cup'
      expect(i).not_to be_valid

      i.density = '5 gram/cup'
      expect(i).to be_valid

      i.density = '5 mile/hour'
      expect(i).not_to be_valid
    end

  end

  describe 'set_usda_food' do
    it 'sets the density' do
      i = build(:ingredient)
      f = create(:salted_butter)

      i.set_usda_food(f)

      expect(i.density).not_to be_nil
    end
  end

end
