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

add tests for vacancies controller #100

Merged
merged 4 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
config.filter_rails_from_backtrace!

config.include FactoryBot::Syntax::Methods
config.include Devise::Test::IntegrationHelpers, type: :request
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
Expand Down
71 changes: 70 additions & 1 deletion spec/requests/vacancies_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
require "rails_helper"

RSpec.describe "Vacancies", type: :request do
pending "add some examples to (or delete) #{__FILE__}"
let(:user) { build(:user) }
let(:vacancy) { build(:vacancy) }

describe "#index" do
it "returns http status success" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove word "returns" in each specs

get vacancies_path
expect(response).to have_http_status(:success)
end
end

describe "#new" do
before { sign_in user }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if user is not company to redirect to root_page only test in code we will fix letter


it "returns http status success" do
get new_vacancy_path
expect(response).to have_http_status(:success)
end
end

describe "#create" do
before { sign_in user }

context "when valid params" do
let(:create_vacancy) { post vacancies_path, params: { vacancy: vacancy.attributes } }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not create let for one spec


it "returns http status success" do
create_vacancy
expect(response).to have_http_status(:redirect)
end

it { expect { create_vacancy }.to change(Vacancy, :count).by(1) }
end
end

describe "#edit" do
let(:vacancy) { create(:vacancy) }

before { sign_in vacancy.user }

it "returns http status success" do
get edit_vacancy_path(vacancy)
expect(response).to have_http_status(:success)
end
end

describe "#update" do
let(:vacancy) { create(:vacancy) }

before { sign_in vacancy.user }

it "retuns http_status success" do
patch vacancy_path(vacancy), params: { vacancy: vacancy.attributes }
expect(response).to redirect_to(vacancy_path(vacancy))
end
end

describe "#destroy" do
let(:vacancy) { create(:vacancy) }

before { sign_in vacancy.user }

it "destroy vacancy record" do
expect { delete vacancy_path(vacancy) }.to change(Vacancy, :count).by(-1)
end

it "redirects to the vacancies list" do
delete vacancy_path(vacancy)
expect(response).to redirect_to(vacancies_path)
end
end
end