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

Added: Automatic spec testing w/ github actions #2

Merged
merged 12 commits into from
Feb 6, 2024
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI
AidenEscamilla marked this conversation as resolved.
Show resolved Hide resolved
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14.10
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
AidenEscamilla marked this conversation as resolved.
Show resolved Hide resolved
with:
ruby-version: '3.3'
bundler-cache: true

- name: Install dependent libraries
run: sudo apt-get install libpq-dev

- name: Bundle install
run: |
gem install bundler
cd job_tracker
bundle install --jobs 4 --retry 3

- name: Setup Database
run: |
cd job_tracker
cp config/database.yml.github-actions config/database.yml
bundle exec rake db:create
bundle exec rake db:schema:load
env:
RAILS_ENV: test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

- name: Run RSpec
run: |
cd job_tracker
rails assets:precompile
AidenEscamilla marked this conversation as resolved.
Show resolved Hide resolved
COVERAGE=true bundle exec rspec --require rails_helper
env:
RAILS_ENV: test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
8 changes: 8 additions & 0 deletions job_tracker/config/database.yml.github-actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
adapter: postgresql
host: localhost
encoding: unicode
database: github-actions
pool: 20
username: <%= ENV["POSTGRES_USER"] %>
password: <%= ENV["POSTGRES_PASSWORD"] %>
11 changes: 0 additions & 11 deletions job_tracker/spec/requests/articles_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion job_tracker/spec/requests/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe "Homes", type: :request do
describe "GET /index" do
it "returns http success" do
get "/home/index"
get "/home#index"
expect(response).to have_http_status(:success)
end
end
Expand Down
4 changes: 2 additions & 2 deletions job_tracker/spec/routing/job_descriptions_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
expect(patch: "/job_descriptions/1").to route_to("job_descriptions#update", id: "1")
end

it "routes to #destroy" do
expect(delete: "/job_descriptions/1").to route_to("job_descriptions#destroy", id: "1")
it "does not routes to #destroy" do
expect(delete: "/job_descriptions/1").to_not route_to("job_descriptions#destroy", id: "1")
end
end
end
5 changes: 0 additions & 5 deletions job_tracker/spec/views/articles/index.html.erb_spec.rb

This file was deleted.

25 changes: 16 additions & 9 deletions job_tracker/spec/views/employers/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@
name: "MyString",
phone_number: "MyString",
email: "MyString",
address: ""
address: { "street" => "MyStreet1234", "city" => "MyCity", "state" => "MyState", "zip" => 00005}
)
}

before(:each) do
assign(:employer, employer)
render
end

it "renders the edit employer form" do
render

assert_select "form[action=?][method=?]", employer_path(employer), "post" do

assert_select "input[name=?]", "employer[name]"

assert_select "input[name=?]", "employer[phone_number]"

assert_select "input[name=?]", "employer[email]"

assert_select "input[name=?]", "employer[address]"

assert_select "input[name=?]", "employer[name]"

assert_select "input[name=?]", "employer[phone_number]"

assert_select "input[name=?]", "employer[email]"

assert_select "input[name=?]", "employer[address][street]"

assert_select "input[name=?]", "employer[address][city]"

assert_select "input[name=?]", "employer[address][state]"

assert_select "input[name=?]", "employer[address][zip]"
end
end
end
22 changes: 11 additions & 11 deletions job_tracker/spec/views/employers/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
before(:each) do
assign(:employers, [
Employer.create!(
name: "Name",
phone_number: "Phone Number",
name: "Example",
email: "Email",
address: ""
phone_number: "1234567890",
address: { "street" => "MyStreet1234", "city" => "MyCity", "state" => "MyState", "zip" => 00005}
),
Employer.create!(
name: "Name",
phone_number: "Phone Number",
name: "Example",
email: "Email",
address: ""
phone_number: "1234567890",
address: { "street" => "MyStreet1234", "city" => "MyCity", "state" => "MyState", "zip" => 00005}
)
])
end

it "renders a list of employers" do
render
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
assert_select cell_selector, text: Regexp.new("Name".to_s), count: 2
assert_select cell_selector, text: Regexp.new("Phone Number".to_s), count: 2
assert_select cell_selector, text: Regexp.new("Email".to_s), count: 2
assert_select cell_selector, text: Regexp.new("".to_s), count: 2

assert_select "h2", text: "Name: Example", count: 2
assert_select "div>b", text: "Email:", count: 2
AidenEscamilla marked this conversation as resolved.
Show resolved Hide resolved
assert_select "div>b", text: "Phone Number:", count: 2
assert_select "div>b", text: "Address:", count: 2
end
end
16 changes: 11 additions & 5 deletions job_tracker/spec/views/employers/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
RSpec.describe "employers/new", type: :view do
before(:each) do
assign(:employer, Employer.new(
name: "MyString",
phone_number: "MyString",
email: "MyString",
address: ""
name: "MyName",
phone_number: "1234567890",
email: "[email protected]",
address: { "street" => "MyStreet", "city" => "MyCity", "state" => "MyState", "zip" => 12345 }
))
end

Expand All @@ -21,7 +21,13 @@

assert_select "input[name=?]", "employer[email]"

assert_select "input[name=?]", "employer[address]"
assert_select "input[name=?]", "employer[address][street]"

assert_select "input[name=?]", "employer[address][city]"

assert_select "input[name=?]", "employer[address][state]"

assert_select "input[name=?]", "employer[address][zip]"
end
end
end
10 changes: 9 additions & 1 deletion job_tracker/spec/views/job_applications/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
require 'rails_helper'

RSpec.describe "job_applications/edit", type: :view do
let(:employer) {
Employer.create!(
name: "MyName",
phone_number: "1234567890",
email: "",
address: { "street" => "MyStreet", "city" => "MyCity", "state" => "MyState", "zip" => 12345 }
)
}
let(:job_application) {
JobApplication.create!()
JobApplication.create!(employer: employer)
}

before(:each) do
Expand Down
13 changes: 11 additions & 2 deletions job_tracker/spec/views/job_applications/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require 'rails_helper'

RSpec.describe "job_applications/index", type: :view do
let(:employer) {
Employer.create!(
name: "MyName",
phone_number: "1234567890",
email: "",
address: { "street" => "MyStreet", "city" => "MyCity", "state" => "MyState", "zip" => 12345 }
)
}

before(:each) do
assign(:job_applications, [
JobApplication.create!(),
JobApplication.create!()
JobApplication.create!(employer: employer),
JobApplication.create!(employer: employer)
])
end

Expand Down
14 changes: 12 additions & 2 deletions job_tracker/spec/views/job_applications/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
require 'rails_helper'

RSpec.describe "job_applications/show", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application) { JobApplication.create!(employer: employer) }
let(:job_description) { JobDescription.create!(job_application: job_application) }


before(:each) do
assign(:job_application, JobApplication.create!())
job_application.job_description = job_description
assign(:job_application, job_application)
end

it "renders attributes in <p>" do
it "renders attributes" do
render

assert_select "h1>b", text: "Title:", count: 1
assert_select "div>b", text: "Employer:", count: 1
assert_select "div>b", text: "Status:", count: 1
end
end
7 changes: 5 additions & 2 deletions job_tracker/spec/views/job_descriptions/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require 'rails_helper'

RSpec.describe "job_descriptions/edit", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application) { JobApplication.create!(employer: employer) }

let(:job_description) {
JobDescription.create!(
description: "MyText",
requirements: "MyText",
job_classification: "MyString",
min_salary: 1,
max_salary: 1,
job_application: nil
job_application: job_application
)
}

Expand All @@ -31,7 +34,7 @@

assert_select "input[name=?]", "job_description[max_salary]"

assert_select "input[name=?]", "job_description[job_application_id]"
assert_select "select[name=?]", "job_description[job_application_id]"
end
end
end
22 changes: 13 additions & 9 deletions job_tracker/spec/views/job_descriptions/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'rails_helper'

RSpec.describe "job_descriptions/index", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application1) { JobApplication.create!(employer: employer) }
let(:job_application2) { JobApplication.create!(employer: employer) }

before(:each) do
assign(:job_descriptions, [
JobDescription.create!(
Expand All @@ -9,27 +13,27 @@
job_classification: "Job Classification",
min_salary: 2,
max_salary: 3,
job_application: nil
job_application: job_application1
),
JobDescription.create!(
description: "MyText",
requirements: "MyText",
job_classification: "Job Classification",
min_salary: 2,
max_salary: 3,
job_application: nil
job_application: job_application2
)
])
end

it "renders a list of job_descriptions" do
render
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
assert_select cell_selector, text: Regexp.new("MyText".to_s), count: 2
assert_select cell_selector, text: Regexp.new("MyText".to_s), count: 2
assert_select cell_selector, text: Regexp.new("Job Classification".to_s), count: 2
assert_select cell_selector, text: Regexp.new(2.to_s), count: 2
assert_select cell_selector, text: Regexp.new(3.to_s), count: 2
assert_select cell_selector, text: Regexp.new(nil.to_s), count: 2

assert_select "div>h2", text: Regexp.new("Job application:".to_s), count: 2
assert_select "div>p", text: Regexp.new("Description:".to_s), count: 2
assert_select "div>p", text: Regexp.new("Requirements".to_s), count: 2
assert_select "div>p", text: Regexp.new("Job classification".to_s), count: 2
assert_select "div>p", text: Regexp.new("Min salary:"), count: 2
assert_select "div>p", text: Regexp.new("Max salary:"), count: 2
end
end
7 changes: 5 additions & 2 deletions job_tracker/spec/views/job_descriptions/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require 'rails_helper'

RSpec.describe "job_descriptions/new", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application) { JobApplication.create!(employer: employer) }

before(:each) do
assign(:job_description, JobDescription.new(
description: "MyText",
requirements: "MyText",
job_classification: "MyString",
min_salary: 1,
max_salary: 1,
job_application: nil
job_application_id: job_application.id
))
end

Expand All @@ -27,7 +30,7 @@

assert_select "input[name=?]", "job_description[max_salary]"

assert_select "input[name=?]", "job_description[job_application_id]"
assert_select "select[name=?]", "job_description[job_application_id]"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require 'rails_helper'

RSpec.describe "job_descriptions/show", type: :view do
let(:employer) { Employer.create!(name: "MyString") }
let(:job_application) { JobApplication.create!(employer: employer) }
before(:each) do

assign(:job_description, JobDescription.create!(
description: "MyText",
requirements: "MyText",
job_classification: "Job Classification",
min_salary: 2,
max_salary: 3,
job_application: nil
job_application: job_application
))
end

Expand Down