112 lines
3.3 KiB
Ruby
112 lines
3.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe TeamsController do
|
|
# First create a company to associate with teams
|
|
let(:company) { Company.create!(name: "Test Company", entity: "Corp", id_number: "123456") }
|
|
|
|
let(:valid_attributes) do
|
|
{ name: "Test Team", company_id: company.id }
|
|
end
|
|
|
|
let(:invalid_attributes) do
|
|
{ name: nil, company_id: nil }
|
|
end
|
|
|
|
describe "GET #index" do
|
|
it "returns a success response" do
|
|
Team.create! valid_attributes
|
|
get :index, params: { company_id: company.id }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "GET #show" do
|
|
it "returns a success response" do
|
|
team = Team.create! valid_attributes
|
|
get :show, params: { id: team.to_param, company_id: company.id }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "GET #new" do
|
|
it "returns a success response" do
|
|
get :new, params: { company_id: company.id }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "GET #edit" do
|
|
it "returns a success response" do
|
|
team = Team.create! valid_attributes
|
|
get :edit, params: { id: team.to_param, company_id: company.id }
|
|
expect(response).to be_successful
|
|
end
|
|
end
|
|
|
|
describe "POST #create" do
|
|
context "with valid params" do
|
|
it "creates a new Team" do
|
|
expect do
|
|
post :create, params: { team: valid_attributes, company_id: company.id }
|
|
end.to change(Team, :count).by(1)
|
|
end
|
|
|
|
it "redirects to the created team" do
|
|
post :create, params: { team: valid_attributes, company_id: company.id }
|
|
expect(response).to be_redirect
|
|
end
|
|
end
|
|
|
|
context "with invalid params" do
|
|
it "handles invalid attributes appropriately" do
|
|
post :create, params: { team: invalid_attributes, company_id: company.id }
|
|
expect(response.status).to be_in([200, 302, 422])
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "PUT #update" do
|
|
context "with valid params" do
|
|
let(:new_attributes) do
|
|
{ name: "Updated Team Name" }
|
|
end
|
|
|
|
it "updates the requested team" do
|
|
team = Team.create! valid_attributes
|
|
put :update, params: { id: team.to_param, team: new_attributes, company_id: company.id }
|
|
team.reload
|
|
expect(team.name).to eq("Updated Team Name")
|
|
end
|
|
|
|
it "redirects to the team" do
|
|
team = Team.create! valid_attributes
|
|
put :update, params: { id: team.to_param, team: new_attributes, company_id: company.id }
|
|
expect(response).to be_redirect
|
|
end
|
|
end
|
|
|
|
context "with invalid params" do
|
|
it "handles invalid attributes appropriately" do
|
|
team = Team.create! valid_attributes
|
|
put :update, params: { id: team.to_param, team: invalid_attributes, company_id: company.id }
|
|
expect(response.status).to be_in([200, 302, 422])
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "DELETE #destroy" do
|
|
it "destroys the requested team" do
|
|
team = Team.create! valid_attributes
|
|
expect do
|
|
delete :destroy, params: { id: team.to_param, company_id: company.id }
|
|
end.to change(Team, :count).by(-1)
|
|
end
|
|
|
|
it "redirects after destroy" do
|
|
team = Team.create! valid_attributes
|
|
delete :destroy, params: { id: team.to_param, company_id: company.id }
|
|
expect(response).to be_redirect
|
|
end
|
|
end
|
|
end
|