require 'rails_helper' describe Contract do describe '#filename' do it 'delegates to the releasable for the name' do project = build_stubbed(:project, name: "My Project") releasable = double("releasable", contract_file_name: "test") contract = Contract.new(releasable) expect(contract.filename).to eq("test.pdf") expect(contract.filename("xls")).to eq("test.xls") end end describe "rendering the contract" do let(:project) { build(:project) } it 'works with appearance releases' do appearance_release = create(:appearance_release_with_contract_template, project: project, person_name: "Jane Doe") result = render_contract_html_for(appearance_release) expect(result).not_to be_nil end it 'works with talent releases' do talent_release = create(:talent_release_with_contract_template, project: project, person_name: "Jane Doe") result = render_contract_html_for(talent_release) expect(result).not_to be_nil end it 'works with location releases' do location_release = create(:location_release_with_contract_template, project: project, person_name: "Jane Doe") result = render_contract_html_for(location_release) expect(result).not_to be_nil end it 'works with material releases' do material_release = create(:material_release_with_contract_template, project: project, person_name: "Jane Doe") result = render_contract_html_for(material_release) expect(result).not_to be_nil end end private # Reaching into the object's internals a bit here to avoid generating a PDF unnecessarily def render_contract_html_for(releasable) Contract.new(releasable).send(:as_html) end end