Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views for jobs created #43

Merged
merged 6 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class JobsController < ApplicationController

before_action :load_jobs, only: :index
before_action :load_job, only: [:show, :edit, :update, :destroy]
before_action :load_institution, only: [:index, :new, :edit]


def index
Expand Down Expand Up @@ -73,4 +74,7 @@ def job_scope
Institution.find(params[:institution_id]).jobs
end

def load_institution
@institution = Institution.find(params[:institution_id])
end
end
3 changes: 3 additions & 0 deletions app/views/institutions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<%= link_to institution, class: "btn btn-floating red", data: { confirm: "Are you sure?" } do %>
<i class="material-icons">highlight_remove</i>
<% end %>
<%= link_to institution_jobs_path(institution), class: "btn-floating gray", title: "Jobs Posted" do %>
<i class="material-icons">library_books</i>
<% end %>
</td>
</tr>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/jobs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= simple_form_for [@institution, @job] do |f| %>
<%= f.input :title %>
<%= f.input :description, input_html: { class: "materialize-textarea" } %>
<%= f.input :requirements %>
<%= f.input :start_date, as: :date, html5: true %>
<%= f.input :end_date, as: :date, html5: true %>
<%= f.submit class: "btn blue" %>
<% end %>
14 changes: 14 additions & 0 deletions app/views/jobs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="col s12 m12 l12">
<h4>
<%= t ".page_title" %>
<%= link_to t("actions.back"), institution_jobs_path, class: "btn gray right" %>
</h4>
</div>
</div>

<div class="row">
<div class="col s12 m12 l12">
<%= render "form" %>
</div>
</div>
50 changes: 50 additions & 0 deletions app/views/jobs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="row">
<div class="col s12 m12 l12">
<h4 class="col s12 m10 l10">
<%= Job.model_name.human(count: 2) %>
</h4>

<div class="right">
<%= link_to t("actions.add"), new_institution_job_path(@institution), class: "btn green" %>
<%= link_to t("actions.back"), institutions_path, class: "btn gray" %>
</div>
</div>
</div>

<div class="row">
<div class="col s12 m12 l12">
<table class="responsive-table highlight">
<thead>
<tr>
<th><%= Job.human_attribute_name(:title) %></th>
<th><%= Job.human_attribute_name(:description) %></th>
<th><%= Job.human_attribute_name(:requirements) %></th>
<th><%= Job.human_attribute_name(:start_date) %></th>
<th><%= Job.human_attribute_name(:end_date) %></th>
</tr>
</thead>
<tbody>
<% @institution.jobs.each do |job| %>
<tr>
<td><%= job.title %></td>
<td><%= job.description %></td>
<td><%= job.requirements %></td>
<td><%= job.start_date.strftime("%m/%d/%Y") %></td>
<td><%= job.end_date.strftime("%m/%d/%Y") %></td>
<td>
<%= link_to edit_institution_job_path(job.institution, job), class: "btn-floating blue" do %>
<i class="material-icons">edit</i>
<% end %>
<%= link_to institution_job_path(job.institution, job), method: :delete, class: "btn btn-floating red", data: { confirm: "Are you sure?" } do %>
<i class="material-icons">highlight_remove</i>
<% end %>
<%= link_to institution_job_path(job.institution, job), class: "btn btn-floating gray" do %>
<i class="material-icons">class</i>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/jobs/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="col s12 m12 l12">
<h4>
<%= t ".page_title" %>
<%= link_to t("actions.back"), institutions_path, class: "btn gray right" %>
</h4>
</div>
</div>

<div class="row">
<div class="col s12 m12 l12">
<%= render "form" %>
</div>
</div>
35 changes: 35 additions & 0 deletions app/views/jobs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="row">
<div class="col s12 m12 l12">
<h4>
<%= @job.title %>
<div class="right">
<%= link_to t("actions.edit"), edit_institution_job_path(@job), class: "btn blue" %>
<%= link_to t("actions.back"), institution_jobs_path, class: "btn gray" %>
</div>
</h4>
</div>
</div>


<div class="row">
<div class="col s12 m12 l12">
<span style="font-weight: bold"><%= Job.human_attribute_name(:title) %>:</span>
<span><%= @job.title %></span>
<br />

<span style="font-weight: bold"><%= Job.human_attribute_name(:description) %>:</span>
<blockquote><%= @job.description %></blockquote>
<br />

<span style="font-weight: bold"><%= Job.human_attribute_name(:requirements) %>:</span>
<blockquote><%= @job.requirements %></blockquote>
<br />

<span style="font-weight: bold"><%= Job.human_attribute_name(:start_date) %>:</span>
<blockquote><%= @job.start_date %></blockquote>
<br />

<span style="font-weight: bold"><%= Job.human_attribute_name(:end_date) %>:</span>
<blockquote><%= @job.end_date %></blockquote>
</div>
</div>
45 changes: 45 additions & 0 deletions test/integration/job_actions_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class JobActionsTest < ActionDispatch::IntegrationTest
setup do
@user = users(:standard)
sign_in @user
@institution = institutions(:standard)
end

test "can fill in form to create a new job" do
get new_institution_job_path(@institution)
assert_response :success
end

test "can create a job through institution" do
assert_difference ->{ @institution.jobs.count } do
post institution_jobs_path(@institution),
params: {
job: {
title: "Desenvolvedor",
description: "Ruby",
requirements: "rspec and capybara",
start_date: Date.today,
end_date: Date.today + 5.days
}
}
end
assert_redirected_to institution_jobs_path(@institution.id)
follow_redirect!
assert_response :success
end

test "can edit a job through institution" do
get edit_institution_job_path(@institution, @institution.jobs.last)
assert_response :success

patch institution_job_path(@institution, @institution.jobs.last), params: { job: {title: "New name"} }
@institution.reload

assert @institution.jobs.last.title == "New name"
assert_redirected_to institution_jobs_path(@institution.id)
follow_redirect!
assert_response :success
end
end