require 'rails_helper'

RSpec.describe TasksController, type: :controller do
  render_views

  let(:user) { create(:user) }
  let(:account) { user.primary_account }
  let(:project) { create(:project, account: user.primary_account) }

  before do
    sign_in user
  end

  describe "#index" do
    it "responds successfully" do
      get :index, params: { project_id: project }

      expect(response).to be_successful
    end

    it "renders content" do
      create(:task_request, :completed, project: project, description: "Another Request")

      get :index, params: { project_id: project }

      expect(response.body).to have_content "Completed"
      expect(response.body).to have_link "View Deliverable"
    end

    context "when there are many records" do
      it "paginates the table" do
        create_list(:task_request, 20, :completed, project: project)

        get :index, params: { project_id: project }

        expect(response.body).to have_link("2", href: project_tasks_path(project, page: 2))
      end
    end
  end
end
