require 'rails_helper'

RSpec.describe MenuCategory, type: :model do
  it { should validate_presence_of(:name) }
  it { should belong_to(:menu) }

  describe ' #parent & #children' do
    it 'should be able to do parent tree' do
      menu = Menu.new(:name => "Test Category Menu", :is_active => true )
      menu.save!

      c1 = MenuCategory.new(:name =>"Parent Category", :menu => menu)
      c1.save!
      c2 = MenuCategory.new(:name =>"Child Category", :menu => menu, :parent => c1)
      c2.save

      expect(c1.children).to include(c2)
      expect(c2.parent).to eq c1
    end
  end

end
