started implementing teams
This commit is contained in:
93
spec/controllers/teams_controller_spec.rb
Normal file
93
spec/controllers/teams_controller_spec.rb
Normal file
@@ -0,0 +1,93 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TeamsController do
|
||||
let(:team) { FactoryGirl.create(:team) }
|
||||
let(:user) { FactoryGirl.create(:admin) }
|
||||
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with a valid team' do
|
||||
let(:request) { Proc.new { post :create, team: FactoryGirl.attributes_for(:team) } }
|
||||
before(:each) { request.call }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
|
||||
it 'creates the team' do
|
||||
expect { request.call }.to change(Team, :count).by(1)
|
||||
end
|
||||
|
||||
expect_redirect
|
||||
end
|
||||
|
||||
context 'with an invalid team' do
|
||||
before(:each) { post :create, team: {} }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
expect_status(200)
|
||||
expect_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before(:each) { delete :destroy, id: team.id }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
|
||||
it 'destroys the team' do
|
||||
team = FactoryGirl.create(:team)
|
||||
expect { delete :destroy, id: team.id }.to change(Team, :count).by(-1)
|
||||
end
|
||||
|
||||
expect_redirect(:teams)
|
||||
end
|
||||
|
||||
describe 'GET #edit' do
|
||||
before(:each) { get :edit, id: team.id }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
expect_status(200)
|
||||
expect_template(:edit)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:teams) { FactoryGirl.create_pair(:team) }
|
||||
before(:each) { get :index }
|
||||
|
||||
expect_assigns(teams: Team.all)
|
||||
expect_status(200)
|
||||
expect_template(:index)
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before(:each) { get :new }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
expect_status(200)
|
||||
expect_template(:new)
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
before(:each) { get :show, id: team.id }
|
||||
|
||||
expect_assigns(team: :team)
|
||||
expect_status(200)
|
||||
expect_template(:show)
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
context 'with a valid team' do
|
||||
before(:each) { put :update, team: FactoryGirl.attributes_for(:team), id: team.id }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
expect_redirect
|
||||
end
|
||||
|
||||
context 'with an invalid team' do
|
||||
before(:each) { put :update, team: {name: ''}, id: team.id }
|
||||
|
||||
expect_assigns(team: Team)
|
||||
expect_status(200)
|
||||
expect_template(:edit)
|
||||
end
|
||||
end
|
||||
end
|
6
spec/factories/team.rb
Normal file
6
spec/factories/team.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory :team do
|
||||
internal_users { build_list :teacher, 10 }
|
||||
name 'A-Team'
|
||||
end
|
||||
end
|
9
spec/models/team_spec.rb
Normal file
9
spec/models/team_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Team do
|
||||
let(:team) { Team.create }
|
||||
|
||||
it 'validates the presence of a name' do
|
||||
expect(team.errors[:name]).to be_present
|
||||
end
|
||||
end
|
41
spec/policies/team_policy_spec.rb
Normal file
41
spec/policies/team_policy_spec.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TeamPolicy do
|
||||
subject { TeamPolicy }
|
||||
|
||||
let(:team) { FactoryGirl.build(:team) }
|
||||
|
||||
[:create?, :index?, :new?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), team)
|
||||
end
|
||||
|
||||
it 'grants access to teachers' do
|
||||
expect(subject).to permit(FactoryGirl.build(:teacher), team)
|
||||
end
|
||||
|
||||
it 'does not grant access to external users' do
|
||||
expect(subject).not_to permit(FactoryGirl.build(:external_user), team)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
[:destroy?, :edit?, :show?, :update?].each do |action|
|
||||
permissions(action) do
|
||||
it 'grants access to admins' do
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), team)
|
||||
end
|
||||
|
||||
it 'grants access to members' do
|
||||
expect(subject).to permit(team.members.last, team)
|
||||
end
|
||||
|
||||
it 'does not grant access to all other users' do
|
||||
[:external_user, :teacher].each do |factory_name|
|
||||
expect(subject).not_to permit(FactoryGirl.build(factory_name), team)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user