require 'spec_helper'

describe 'projects/index' do
  let!(:role) { FactoryBot.create(:role, :name => "trustee") }
  let!(:user) { role.user }
  let!(:project) { FactoryBot.create(:project, :extra_question_1 => "Extra Question 1", :extra_answer_1 => "Extra Answer 1") }

  it 'displays extra questions and answers' do 
    assign(:chapter, project.chapter)
    assign(:projects, ProjectFilter.new(project.chapter.projects).page(1).result)
    view.stubs(:current_user).returns(user)

    render
    expect(rendered).to have_content("Extra Question 1")
    expect(rendered).to have_content("Extra Answer 1")
  end
end

describe 'projects/show' do
  let!(:user) { FactoryBot.create(:user) }
  let!(:unfunded_project) { FactoryBot.create(:project) }

  it 'displays the application text for an unfunded project' do 
    assign(:project, unfunded_project)
    view.stubs(:current_user).returns(user)
    
    render
    expect(rendered).to have_content(unfunded_project.about_project)
  end
end

describe 'projects/_form' do
  let!(:active_chapter) { FactoryBot.create(:chapter) }
  let!(:inactive_chapter) { FactoryBot.create(:inactive_chapter) }

  before do
    view.stubs(:current_user).returns(Guest.new)
  end

  context 'projects/new' do
    it 'does not show inactive chapters' do
      assign(:project, Project.new)

      render :template => 'projects/new'
      expect(rendered).to     have_content(active_chapter.name)
      expect(rendered).not_to have_content(inactive_chapter.name)
    end
  end

  context 'projects/edit' do
    it 'shows inactive chapters' do
      assign(:project, FactoryBot.create(:project, :chapter => inactive_chapter))

      render :template => 'projects/edit'
      expect(rendered).to have_content(active_chapter.name)
      expect(rendered).to have_content(inactive_chapter.name)
    end
  end
end
