Skip to content

Commit

Permalink
used devise helpers, fixed specs and created a new partial
Browse files Browse the repository at this point in the history
  • Loading branch information
FaxriddinMaxmadiyorov committed Oct 13, 2023
1 parent 976aad5 commit 2a02b57
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
8 changes: 3 additions & 5 deletions app/controllers/vacancies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class VacanciesController < ApplicationController
before_action :authenticate_user!, only: %i[my_vacancies]

def index
@vacancies = Vacancy.all
end
Expand Down Expand Up @@ -48,11 +50,7 @@ def destroy
end

def my_vacancies
if current_user.nil?
redirect_to root_path unless current_user
else
@my_vacancies = current_user.vacancies
end
@my_vacancies = current_user.vacancies
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nav.navbar.navbar-expand-lg.bg-body-tertiary
= link_to "Home", root_path, class: "nav-link fs-4 text-black"
li.nav-item
= link_to "Vacancies", vacancies_path, class: "nav-link fs-4 text-black"
- unless current_user.nil?
- if user_signed_in?
li.nav-item
= link_to "My Vacancies", my_vacancies_vacancies_path, class: "nav-link fs-4 text-black"
ul.navbar-nav.ms-3
Expand Down
7 changes: 7 additions & 0 deletions app/views/vacancies/_vacancy.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.col.d-flex.align-items-stretch
.card.w-100
.card-body.d-flex.flex-column
h5.card-title
= link_to vacancy.title, vacancy_path(vacancy)
p.card-text
= truncate(vacancy.body, length: 100)
8 changes: 1 addition & 7 deletions app/views/vacancies/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@
= button_to "New vacancy", new_vacancy_path, method: :get, class: "btn btn-primary mx-2"
.row.row-cols-1.row-cols-md-2.row-cols-xl-4.g-4.mx-20.mt-0
- @vacancies.each do |vacancy|
.col.d-flex.align-items-stretch
.card.w-100
.card-body.d-flex.flex-column
h5.card-title
= link_to vacancy.title, vacancy_path(vacancy)
p.card-text
= truncate(vacancy.body, length: 100)
= render partial: "vacancy", locals: { vacancy: vacancy }
8 changes: 1 addition & 7 deletions app/views/vacancies/my_vacancies.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@
= button_to "New vacancy", new_vacancy_path, method: :get, class: "btn btn-primary mx-2"
.row.row-cols-1.row-cols-md-2.row-cols-xl-4.g-4.mx-20.mt-0
- @my_vacancies.each do |vacancy|
.col.d-flex.align-items-stretch
.card.w-100
.card-body.d-flex.flex-column
h5.card-title
= link_to vacancy.title, vacancy_path(vacancy)
p.card-text
= truncate(vacancy.body, length: 100)
= render partial: "vacancy", locals: { vacancy: vacancy }
8 changes: 4 additions & 4 deletions spec/requests/vacancies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

RSpec.describe "Vacancies", type: :request do
describe "GET /vacancies" do
it "returns http success" do
it "http success" do
get vacancies_path
expect(response).to have_http_status(:success)
end

it "redirects to root_path if current_user is not authenticated" do
it "redirects user to users/sign_in if user is not authenticated" do
get my_vacancies_vacancies_path
expect(response).to redirect_to(root_path)
expect(response).to redirect_to(new_user_session_path)
end

it "redirects with 302 status code if current_user is not authenticated" do
it "redirects user with 302 status code if user is not authenticated" do
get my_vacancies_vacancies_path
expect(response).to have_http_status(:found)
end
Expand Down

0 comments on commit 2a02b57

Please sign in to comment.