diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index 9550016..b4ba81c 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -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
@@ -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
diff --git a/app/views/institutions/index.html.erb b/app/views/institutions/index.html.erb
index cff6c89..e90d6f2 100644
--- a/app/views/institutions/index.html.erb
+++ b/app/views/institutions/index.html.erb
@@ -38,6 +38,9 @@
<%= link_to institution, class: "btn btn-floating red", data: { confirm: "Are you sure?" } do %>
highlight_remove
<% end %>
+ <%= link_to institution_jobs_path(institution), class: "btn-floating gray", title: "Jobs Posted" do %>
+ library_books
+ <% end %>
<% end %>
diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb
new file mode 100644
index 0000000..9f34a2e
--- /dev/null
+++ b/app/views/jobs/_form.html.erb
@@ -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 %>
diff --git a/app/views/jobs/edit.html.erb b/app/views/jobs/edit.html.erb
index e69de29..9eafc2f 100644
--- a/app/views/jobs/edit.html.erb
+++ b/app/views/jobs/edit.html.erb
@@ -0,0 +1,14 @@
+
+
+
+ <%= t ".page_title" %>
+ <%= link_to t("actions.back"), institution_jobs_path, class: "btn gray right" %>
+
+
+
+
+
+
+ <%= render "form" %>
+
+
diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb
index e69de29..1a2f52c 100644
--- a/app/views/jobs/index.html.erb
+++ b/app/views/jobs/index.html.erb
@@ -0,0 +1,50 @@
+
+
+
+ <%= Job.model_name.human(count: 2) %>
+
+
+
+ <%= link_to t("actions.add"), new_institution_job_path(@institution), class: "btn green" %>
+ <%= link_to t("actions.back"), institutions_path, class: "btn gray" %>
+
+
+
+
+
+
+
+
+
+ <%= Job.human_attribute_name(:title) %> |
+ <%= Job.human_attribute_name(:description) %> |
+ <%= Job.human_attribute_name(:requirements) %> |
+ <%= Job.human_attribute_name(:start_date) %> |
+ <%= Job.human_attribute_name(:end_date) %> |
+
+
+
+ <% @institution.jobs.each do |job| %>
+
+ <%= job.title %> |
+ <%= job.description %> |
+ <%= job.requirements %> |
+ <%= job.start_date.strftime("%m/%d/%Y") %> |
+ <%= job.end_date.strftime("%m/%d/%Y") %> |
+
+ <%= link_to edit_institution_job_path(job.institution, job), class: "btn-floating blue" do %>
+ edit
+ <% end %>
+ <%= link_to institution_job_path(job.institution, job), method: :delete, class: "btn btn-floating red", data: { confirm: "Are you sure?" } do %>
+ highlight_remove
+ <% end %>
+ <%= link_to institution_job_path(job.institution, job), class: "btn btn-floating gray" do %>
+ class
+ <% end %>
+ |
+
+ <% end %>
+
+
+
+
diff --git a/app/views/jobs/new.html.erb b/app/views/jobs/new.html.erb
index e69de29..be15204 100644
--- a/app/views/jobs/new.html.erb
+++ b/app/views/jobs/new.html.erb
@@ -0,0 +1,14 @@
+
+
+
+ <%= t ".page_title" %>
+ <%= link_to t("actions.back"), institutions_path, class: "btn gray right" %>
+
+
+
+
+
+
+ <%= render "form" %>
+
+
diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb
index e69de29..2b408a5 100644
--- a/app/views/jobs/show.html.erb
+++ b/app/views/jobs/show.html.erb
@@ -0,0 +1,35 @@
+
+
+
+ <%= @job.title %>
+
+ <%= link_to t("actions.edit"), edit_institution_job_path(@job), class: "btn blue" %>
+ <%= link_to t("actions.back"), institution_jobs_path, class: "btn gray" %>
+
+
+
+
+
+
+
+
+
<%= Job.human_attribute_name(:title) %>:
+
<%= @job.title %>
+
+
+
<%= Job.human_attribute_name(:description) %>:
+
<%= @job.description %>
+
+
+
<%= Job.human_attribute_name(:requirements) %>:
+
<%= @job.requirements %>
+
+
+
<%= Job.human_attribute_name(:start_date) %>:
+
<%= @job.start_date %>
+
+
+
<%= Job.human_attribute_name(:end_date) %>:
+
<%= @job.end_date %>
+
+
diff --git a/test/integration/job_actions_test.rb b/test/integration/job_actions_test.rb
new file mode 100644
index 0000000..53ff63f
--- /dev/null
+++ b/test/integration/job_actions_test.rb
@@ -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