require 'rails_helper'

RSpec.describe FoodUnit, type: :model do

  describe 'matches?' do
    it 'matches empty units to each-like terms' do
      each_terms = [
          'Each',
          'each',
          'ech',
          'item',
          'per',
          'PER',
          'Per'
      ]

      each_terms.each do |t|
        expect(create(:food_unit, name: t).matches?('')).to eq(true), "expected #{t} to match"
      end
    end

    it 'matches unit names' do
      expect(create(:food_unit, name: 'Clove').matches?('clove')).to eq true
    end

    it 'matches pluralized unit names' do
      expect(create(:food_unit, name: 'Clove').matches?('cloves')).to eq true
    end
  end

end