Skip to content

Commit

Permalink
this creates the projects table
Browse files Browse the repository at this point in the history
ParzivalRealm committed Feb 7, 2023
1 parent c965c93 commit 68b36e5
Showing 18 changed files with 269 additions and 0 deletions.
70 changes: 70 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class ProjectsController < ApplicationController
before_action :set_project, only: %i[ show edit update destroy ]

# GET /projects or /projects.json
def index
@projects = Project.all
end

# GET /projects/1 or /projects/1.json
def show
end

# GET /projects/new
def new
@project = Project.new
end

# GET /projects/1/edit
def edit
end

# POST /projects or /projects.json
def create
@project = Project.new(project_params)

respond_to do |format|
if @project.save
format.html { redirect_to project_url(@project), notice: "Project was successfully created." }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /projects/1 or /projects/1.json
def update
respond_to do |format|
if @project.update(project_params)
format.html { redirect_to project_url(@project), notice: "Project was successfully updated." }
format.json { render :show, status: :ok, location: @project }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end

# DELETE /projects/1 or /projects/1.json
def destroy
@project.destroy

respond_to do |format|
format.html { redirect_to projects_url, notice: "Project was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_project
@project = Project.find(params[:id])
end

# Only allow a list of trusted parameters through.
def project_params
params.fetch(:project, {})
end
end
2 changes: 2 additions & 0 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProjectsHelper
end
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Project < ApplicationRecord
end
12 changes: 12 additions & 0 deletions app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<%= simple_form_for(@project) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>

<div class="form-inputs">
</div>

<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/projects/_project.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="<%= dom_id project %>">
</div>
2 changes: 2 additions & 0 deletions app/views/projects/_project.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! project, :id, :created_at, :updated_at
json.url project_url(project, format: :json)
10 changes: 10 additions & 0 deletions app/views/projects/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Editing project</h1>

<%= render "form", project: @project %>

<br>

<div>
<%= link_to "Show this project", @project %> |
<%= link_to "Back to projects", projects_path %>
</div>
14 changes: 14 additions & 0 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p style="color: green"><%= notice %></p>

<h1>Projects</h1>

<div id="projects">
<% @projects.each do |project| %>
<%= render project %>
<p>
<%= link_to "Show this project", project %>
</p>
<% end %>
</div>

<%= link_to "New project", new_project_path %>
1 change: 1 addition & 0 deletions app/views/projects/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @projects, partial: "projects/project", as: :project
9 changes: 9 additions & 0 deletions app/views/projects/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>New project</h1>

<%= render "form", project: @project %>

<br>

<div>
<%= link_to "Back to projects", projects_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @project %>

<div>
<%= link_to "Edit this project", edit_project_path(@project) %> |
<%= link_to "Back to projects", projects_path %>

<%= button_to "Destroy this project", @project, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/projects/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "projects/project", project: @project
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :projects

resources :suppliers
resources :part_numbers
28 changes: 28 additions & 0 deletions db/migrate/20230207144437_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class CreateProjects < ActiveRecord::Migration[7.0]
def change
create_table :projects do |t|
t.string :name
t.string :description
t.string :status
t.string :start_date
t.string :end_date
t.string :project_manager
t.string :project_owner
t.string :project_team
t.string :project_budget
t.string :project_risk
t.string :project_milestones
t.string :project_dependencies
t.string :project_issues
t.string :project_notes
t.string :project_attachments
t.string :project_tasks
t.string :project_comments
t.string :project_reports
t.string :project_timesheets
t.string :project_invoices
t.string :project_expenses
t.timestamps
end
end
end
48 changes: 48 additions & 0 deletions test/controllers/projects_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "test_helper"

class ProjectsControllerTest < ActionDispatch::IntegrationTest
setup do
@project = projects(:one)
end

test "should get index" do
get projects_url
assert_response :success
end

test "should get new" do
get new_project_url
assert_response :success
end

test "should create project" do
assert_difference("Project.count") do
post projects_url, params: { project: { } }
end

assert_redirected_to project_url(Project.last)
end

test "should show project" do
get project_url(@project)
assert_response :success
end

test "should get edit" do
get edit_project_url(@project)
assert_response :success
end

test "should update project" do
patch project_url(@project), params: { project: { } }
assert_redirected_to project_url(@project)
end

test "should destroy project" do
assert_difference("Project.count", -1) do
delete project_url(@project)
end

assert_redirected_to projects_url
end
end
11 changes: 11 additions & 0 deletions test/fixtures/projects.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/models/project_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class ProjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
39 changes: 39 additions & 0 deletions test/system/projects_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "application_system_test_case"

class ProjectsTest < ApplicationSystemTestCase
setup do
@project = projects(:one)
end

test "visiting the index" do
visit projects_url
assert_selector "h1", text: "Projects"
end

test "should create project" do
visit projects_url
click_on "New project"

click_on "Create Project"

assert_text "Project was successfully created"
click_on "Back"
end

test "should update Project" do
visit project_url(@project)
click_on "Edit this project", match: :first

click_on "Update Project"

assert_text "Project was successfully updated"
click_on "Back"
end

test "should destroy Project" do
visit project_url(@project)
click_on "Destroy this project", match: :first

assert_text "Project was successfully destroyed"
end
end

0 comments on commit 68b36e5

Please sign in to comment.