I added some test to spec/views/projects/index.html.erb_spec.rb
file. Maybe because of version change I'm getting the error. The code is written for Rails 5, and I'm using Rails 6.
Here's the error I'm facing:
Failures:
1) projects/index renders the index page with correct dom elements
Failure/Error: let(:completed_task) { Task.create!(completed_at: 1.day.ago, size: 1) }
ActiveRecord::NotNullViolation:
SQLite3::ConstraintException: NOT NULL constraint failed: tasks.project_id
2) adding a project allows a user to create a project with tasks
Failure/Error: (Time.zone.today + projected_days_remaining) <= due_date
ActionView::Template::Error:
Infinity
Both of the errors are from the spec/views/projects/index.html.erb_spec.rb
file.
Here's spec/views/projects/index.html.erb_spec.rb
file:
require "rails_helper"
describe "projects/index" do
let(:completed_task) { Task.create!(completed_at: 1.day.ago, size: 1) }
let(:on_schedule) { Project.create!(
due_date: 1.year.from_now, name: "On Schedule", tasks: [completed_task]) }
let(:incomplete_task) { Task.create!(size: 1) }
let(:behind_schedule) { Project.create!(
due_date: 1.day.from_now, name: "Behind Schedule",
tasks: [incomplete_task]) }
it "renders the index page with correct dom elements" do
@projects = [on_schedule, behind_schedule]
render
expect(rendered).to have_selector("#project_#{on_schedule.id} .on_schedule")
expect(rendered).to have_selector("#project_#{behind_schedule.id} .behind_schedule")
end
end
Here's app/views/projects/index.html.erb
file:
<h1>All Projects</h1>
<table>
<thead>
<tr>
<td>Project Name</td>
<td>Total Project Size</td>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr class="project-row" id="<%= dom_id(project) %>">
<td class="name"><%= name_with_status(project) %></td>
<td class="total-size"><%= project.size %></td>
</tr>
<% end %>
</tbody>
</table>