# Feature: Browse table index
#   As a visitor
#   I want to browse the table index
#   So I can find a table to join
feature 'Table index', :devise do
  context 'As a visitor' do
    # Scenario: Visitor can browse table index
    #   Given I am not signed in
    #   When I click browse tables
    #   Then I see an index of tables
    scenario 'I can see all the tables', js: true do
      5.times { FactoryGirl.create :table }
      visit root_path
      click_link 'Browse Tables'
      Table.all.each do |table|
        expect(page).to have_content "Sign in"
        expect(page).to have_content table.title
      end
    end
  end

  context 'As a user' do
    # Scenario: User can browse table index
    #   Given I am signed in
    #   When I click browse tables
    #   Then I see an index of tables
    scenario 'I can see all the tables', js: true do
      @user = FactoryGirl.create :user
      signin(@user.email,'password')

      5.times { FactoryGirl.create :table }
      visit root_path
      click_link 'Browse Tables'
      Table.all.each do |table|
        expect(page).to have_content "Sign out"
        expect(page).to have_content table.title
      end
    end
  end

end
