require 'rails_helper'

RSpec.describe UsdaFood do

  describe '#calculate_density' do

    it 'returns nil for invalid values' do
      expect(build(:usda_food_weight, description: nil).calculate_density).to be_nil
      expect(build(:usda_food_weight, amount: nil).calculate_density).to be_nil
      expect(build(:usda_food_weight, gram_weight: nil).calculate_density).to be_nil
      expect(build(:usda_food_weight, description: 'cats').calculate_density).to be_nil
    end

    it 'returns a density in oz / cup' do
      expect(build(:usda_food_weight).calculate_density.raw_value).to be_within(0.1).of(12.3)
      expect(build(:usda_food_weight).calculate_density.unit.to_s).to eq 'ounce/cup'
    end

  end

end