require 'rails_helper'

RSpec.describe RecipeIngredient, type: :model do

  describe '#can_convert_to_grams' do
    it 'returns false if no quantity or unit' do
      ri = RecipeIngredient.new
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns false if no quantity' do
      ri = RecipeIngredient.new(units: 'lbs')
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns false if no units' do
      ri = RecipeIngredient.new(quantity: '5 1/2')
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns false if weird units' do
      ri = RecipeIngredient.new(quantity: '5 1/2', units: 'dogs')
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns true if unit is mass' do
      ri = RecipeIngredient.new(quantity: '5 1/2', units: 'lbs')
      expect(ri.can_convert_to_grams?).to be_truthy
    end

    it 'returns false if unit is volume and there is no ingredient' do
      ri = RecipeIngredient.new(quantity: '5 1/2', units: 'cups')
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns false if unit is volume and ingredient has no density' do
      ri = RecipeIngredient.new(quantity: '5 1/2', units: 'cups', ingredient: create(:ingredient))
      expect(ri.can_convert_to_grams?).to be_falsey
    end

    it 'returns false if unit is volume and ingredient has density' do
      ri = RecipeIngredient.new(quantity: '5 1/2', units: 'cups', ingredient: create(:ingredient_with_density))
      expect(ri.can_convert_to_grams?).to be_truthy
    end
  end

end
