Skip to content

Commit

Permalink
Fix: Adjusted specs to match new form & reference
Browse files Browse the repository at this point in the history
  • Loading branch information
AidenEscamilla committed Feb 21, 2024
1 parent 0a2ed90 commit 6b5f10b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion job_tracker/app/models/supporting_document.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SupportingDocument < ApplicationRecord
has_many :document_linkers
has_many :document_linkers, dependent: :destroy
has_many :job_applications, :through => :document_linkers

has_one_attached :document, dependent: :destroy
Expand Down
6 changes: 6 additions & 0 deletions job_tracker/spec/factories/document_linkers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :document_linker do
job_application { nil }
supporting_document { nil }
end
end
3 changes: 2 additions & 1 deletion job_tracker/spec/factories/supporting_documents.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FactoryBot.define do
factory :supporting_document do
name { "" }
job_application { nil }

# TODO: figure out a way to generate these
end
end
8 changes: 4 additions & 4 deletions job_tracker/spec/models/supporting_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
let(:job_application) { create(:job_application, employer: employer) }
let(:supporting_document) {
create(:supporting_document,
job_application: job_application,
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf")
)
}
let!(:document_linker) {create(:document_linker, job_application:, supporting_document:)}


describe 'associations' do
context 'belongs_to' do
it "belongs to job_application" do
expect(supporting_document.job_application).to eq(job_application)
context 'has_many' do
it "has a document_linker" do
expect(supporting_document.document_linkers.first).to_not be_nil
end
end

Expand Down
6 changes: 3 additions & 3 deletions job_tracker/spec/requests/supporting_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
{
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf"),
job_application_id: job_application.id
job_application_ids: [job_application.id]
}
}

let(:invalid_attributes) {
{
name: nil,
document: nil,
job_application_id: nil
job_application_ids: []
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@
{
name: "Cover Letter",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/cover_letter.pdf", "application/pdf"),
job_application_id: job_application.id
job_application_ids: [job_application.id]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
let(:employer) { Employer.create!(name: "Employer") }
let(:job_application) {create(:job_application, employer: employer)}

let(:supporting_document) {
SupportingDocument.create!(
let(:supporting_document) {SupportingDocument.create!(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf"),
job_application: job_application
)
}
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf")
)}

before(:each) do
before do
assign(:supporting_document, supporting_document)
end

Expand All @@ -25,7 +22,7 @@

assert_select "input[name=?]", "supporting_document[document]"

assert_select "select[name=?]", "supporting_document[job_application_id]"
assert_select "input[name=?]", "supporting_document[job_application_ids][]"
end
end
end
24 changes: 11 additions & 13 deletions job_tracker/spec/views/supporting_documents/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
RSpec.describe "supporting_documents/index", type: :view do
let(:employer) { create(:employer) }
let(:job_application) { create(:job_application, employer: employer) }
let(:supporting_document1) { SupportingDocument.create!(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf")
)}

let(:supporting_document2) { SupportingDocument.create!(
name: "Cover letter",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/cover_letter.pdf", "application/pdf")
)}

before do
assign(:supporting_documents, [
SupportingDocument.create!(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf"),
job_application: job_application
),
SupportingDocument.create!(
name: "Cover letter",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/cover_letter.pdf", "application/pdf"),
job_application: job_application
)
])
assign(:supporting_documents, [supporting_document1, supporting_document2])
end

it "renders a list of supporting_documents" do
render

assert_select "div>h2", text: Regexp.new("Name:\n*+".to_s), count: 2
assert_select "div>p", text: Regexp.new("Job application:\n*+".to_s), count: 2
assert_select "div>p", text: Regexp.new("Job applications:\n*+".to_s), count: 2
assert_select "div>p", text: Regexp.new("Document:*+".to_s), count: 2
end
end
15 changes: 8 additions & 7 deletions job_tracker/spec/views/supporting_documents/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
RSpec.describe "supporting_documents/new", type: :view do
let(:employer) { create(:employer) }
let(:job_application) { create(:job_application, employer: employer) }
let(:supporting_document) {SupportingDocument.create!(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf")
)}

before do
assign(:supporting_document, SupportingDocument.new(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf"),
job_application: job_application
))
assign(:supporting_document, supporting_document)
end

it "renders new supporting_document form" do
render

assert_select "form[action=?][method=?]", supporting_documents_path, "post" do
assert_select "form[action=?][method=?]", "#{supporting_documents_path}/#{supporting_document.id}", "post" do

assert_select "input[name=?]", "supporting_document[name]"

assert_select "input[name=?]", "supporting_document[document]"

assert_select "select[name=?]", "supporting_document[job_application_id]"
assert_select "input[name=?]", "supporting_document[job_application_ids][]"
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
RSpec.describe "supporting_documents/show", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application) { JobApplication.create!(employer: employer) }

before(:each) do
assign(:supporting_document, SupportingDocument.create!(
let(:supporting_document) {SupportingDocument.create!(
name: "Resume",
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf"),
job_application: job_application
))
document: Rack::Test::UploadedFile.new("spec/fixtures/files/resume.pdf", "application/pdf")
)}
# let(:document_linker) { DocumentLinker.create!( job_application:,supporting_document:) }

before do
assign(:supporting_document, supporting_document)
end


it "renders attributes in <p>" do
render
expect(rendered).to match(/Name/)
expect(rendered).to match(/Document/)
expect(rendered).to match(/Job application/)
expect(rendered).to match(/Job applications/)
end
end

0 comments on commit 6b5f10b

Please sign in to comment.