From 493939c7d3d73c29612cf6e115367eb52145202f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Mon, 25 Sep 2017 22:17:05 -0300 Subject: [PATCH 1/6] implemented - Create views for jobs --- app/controllers/jobs_controller.rb | 8 +++-- app/views/institutions/index.html.erb | 3 ++ app/views/jobs/_form.html.erb | 8 +++++ app/views/jobs/edit.html.erb | 14 ++++++++ app/views/jobs/index.html.erb | 50 +++++++++++++++++++++++++++ app/views/jobs/new.html.erb | 14 ++++++++ app/views/jobs/show.html.erb | 35 +++++++++++++++++++ hack2save | 1 + 8 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 app/views/jobs/_form.html.erb create mode 160000 hack2save diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index 9550016..cc702bf 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 @@ -15,7 +16,7 @@ def new def create build_job - save_job || render(:new, status: :unprocessable_entity) + save_job || render(institution_job(@job.institution), status: :unprocessable_entity) end @@ -29,7 +30,7 @@ def edit def update build_job - save_job || render(:edit, status: :unprocessable_entity) + save_job || render(edit_institution_job_path(@job.institution, @job), status: :unprocessable_entity) end @@ -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..dfe1e09 --- /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 %> \ No newline at end of file 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..a486a22 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" %> +
+
+
+ +
+
+ + + + + + + + + + + + <% @institution.jobs.each do |job| %> + + + + + + + + + <% end %> + +
<%= 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) %>
<%= 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 %> +
+
+
\ No newline at end of file diff --git a/app/views/jobs/new.html.erb b/app/views/jobs/new.html.erb index e69de29..dbbf3a6 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" %> +
+
\ No newline at end of file diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb index e69de29..25f2e77 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 %>
+
+
\ No newline at end of file diff --git a/hack2save b/hack2save new file mode 160000 index 0000000..d95fe6e --- /dev/null +++ b/hack2save @@ -0,0 +1 @@ +Subproject commit d95fe6e4d5195e28e4be97a1a730542d8fe75f7b From 8f1fb27c0f71d86b1f3bdbe0a5140713223d5d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Mon, 25 Sep 2017 22:54:29 -0300 Subject: [PATCH 2/6] resolved controller testes --- app/controllers/jobs_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb index cc702bf..b4ba81c 100644 --- a/app/controllers/jobs_controller.rb +++ b/app/controllers/jobs_controller.rb @@ -16,7 +16,7 @@ def new def create build_job - save_job || render(institution_job(@job.institution), status: :unprocessable_entity) + save_job || render(:new, status: :unprocessable_entity) end @@ -30,7 +30,7 @@ def edit def update build_job - save_job || render(edit_institution_job_path(@job.institution, @job), status: :unprocessable_entity) + save_job || render(:edit, status: :unprocessable_entity) end From bea6e378a674030d05f1eff3030bb22f69079fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Wed, 27 Sep 2017 12:54:36 -0300 Subject: [PATCH 3/6] integration create test --- test/integration/job_actions_test.rb | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/integration/job_actions_test.rb diff --git a/test/integration/job_actions_test.rb b/test/integration/job_actions_test.rb new file mode 100644 index 0000000..a841087 --- /dev/null +++ b/test/integration/job_actions_test.rb @@ -0,0 +1,34 @@ +require 'test_helper' + +class JobActionsTest < ActionDispatch::IntegrationTest + setup do + @user = users(:standard) + sign_in @user + @institution = institutions(:standard) + end + + # Use separate examples per route / case + 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_response :redirect + follow_redirect! + assert_response :success + end +end From 0bb689feaf456cae825bdd0d55c7990bfc18b2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Mon, 2 Oct 2017 17:19:40 -0300 Subject: [PATCH 4/6] update integration teste --- test/integration/job_actions_test.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/integration/job_actions_test.rb b/test/integration/job_actions_test.rb index a841087..53ff63f 100644 --- a/test/integration/job_actions_test.rb +++ b/test/integration/job_actions_test.rb @@ -7,7 +7,6 @@ class JobActionsTest < ActionDispatch::IntegrationTest @institution = institutions(:standard) end - # Use separate examples per route / case test "can fill in form to create a new job" do get new_institution_job_path(@institution) assert_response :success @@ -26,8 +25,20 @@ class JobActionsTest < ActionDispatch::IntegrationTest } } 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_response :redirect + assert @institution.jobs.last.title == "New name" + assert_redirected_to institution_jobs_path(@institution.id) follow_redirect! assert_response :success end From 217e82f570d5eb2375c0c8864244d54c6f9d0697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Mon, 2 Oct 2017 17:48:54 -0300 Subject: [PATCH 5/6] removing invalid folder --- hack2save | 1 - 1 file changed, 1 deletion(-) delete mode 160000 hack2save diff --git a/hack2save b/hack2save deleted file mode 160000 index d95fe6e..0000000 --- a/hack2save +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d95fe6e4d5195e28e4be97a1a730542d8fe75f7b From 433fdc2344577c07c17a18ac272e5551a463b662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20C=C3=A2ndido?= Date: Mon, 2 Oct 2017 17:55:00 -0300 Subject: [PATCH 6/6] adding new line at end of file --- app/views/jobs/_form.html.erb | 2 +- app/views/jobs/index.html.erb | 2 +- app/views/jobs/new.html.erb | 2 +- app/views/jobs/show.html.erb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/jobs/_form.html.erb b/app/views/jobs/_form.html.erb index dfe1e09..9f34a2e 100644 --- a/app/views/jobs/_form.html.erb +++ b/app/views/jobs/_form.html.erb @@ -5,4 +5,4 @@ <%= f.input :start_date, as: :date, html5: true %> <%= f.input :end_date, as: :date, html5: true %> <%= f.submit class: "btn blue" %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/jobs/index.html.erb b/app/views/jobs/index.html.erb index a486a22..1a2f52c 100644 --- a/app/views/jobs/index.html.erb +++ b/app/views/jobs/index.html.erb @@ -47,4 +47,4 @@ - \ No newline at end of file + diff --git a/app/views/jobs/new.html.erb b/app/views/jobs/new.html.erb index dbbf3a6..be15204 100644 --- a/app/views/jobs/new.html.erb +++ b/app/views/jobs/new.html.erb @@ -11,4 +11,4 @@
<%= render "form" %>
- \ No newline at end of file + diff --git a/app/views/jobs/show.html.erb b/app/views/jobs/show.html.erb index 25f2e77..2b408a5 100644 --- a/app/views/jobs/show.html.erb +++ b/app/views/jobs/show.html.erb @@ -32,4 +32,4 @@ <%= Job.human_attribute_name(:end_date) %>:
<%= @job.end_date %>
- \ No newline at end of file +