require 'spec_helper'

describe "shared dropdown menu partial" do

  it "displays the repository menu for repositories and snapshots" do
    repositories = FactoryGirl.create_list(:repositories, 3, :with_snapshots)
    repository = repositories.first
    snapshot = repository.snapshots.first

    locals = { entities: [repositories, snapshot], display: repository }
    rendered = render partial: 'shared/dropdown_menu', locals: locals

    expect(rendered).to have_selector('a[data-toggle]', repository.to_s)
    repositories.each do |entity|
      path = repository_snapshot_path(entity, snapshot)
      expect(rendered).to have_link(entity.to_s, href: path)
    end
  end

  it "displays the snapshots menu for repositories and snapshots" do
    repositories = FactoryGirl.create_list(:repositories, 3, :with_snapshots)
    repository = repositories.first

    snapshots = repository.snapshots.to_a
    snapshot = snapshots.first

    locals = { entities: [repository, snapshots], display: snapshot }
    rendered = render partial: 'shared/dropdown_menu', locals: locals

    expect(rendered).to have_selector('a[data-toggle]', snapshot.to_s)
    snapshots.each do |entity|
      path = repository_snapshot_path(repository, entity)
      expect(rendered).to have_link(entity.to_s, href: path)
    end
  end

end

Write test for new dropdown menu
Write test for new dropdown menu

I hope this time the whole dropdown thing is solved altogether. I have
written a test for the new design. By using two parameters, everything
should be satisfiable.

A entities array with objects and arrays of objects. The objects will
be passed to the link method and the array is the one being iterating
whereas the array object in the entities array is replaced during the
iteration.

Signed-off-by: Konrad Reiche <4ff0213f56e2082fcd8c882d04c546881c579ce4@gmail.com>
