require "rails_helper"

RSpec.describe ApprovalsController, 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 "#new" do
    let!(:medical_release) { create(:medical_release, project: project) }

    it "responds successfully" do
      get :new, params: { medical_release_id: medical_release }

      expect(response).to be_successful
    end
  end

  describe "#create" do
    it "changes approval status successfully" do
      medical_release = create(:medical_release, project: project)

      expect(MedicalRelease.last.approved?).to eq false

      post :create, params: { medical_release_id: medical_release }

      expect(response).to redirect_to [project, :medical_releases]
      expect(MedicalRelease.last.approved?).to eq true
    end
  end
end
