further delete (spec files)
This commit is contained in:
@ -1,93 +0,0 @@
|
||||
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 { 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(Team.last)
|
||||
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
|
||||
before(:all) { 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(:team)
|
||||
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
|
@ -1,6 +0,0 @@
|
||||
FactoryGirl.define do
|
||||
factory :team do
|
||||
internal_users { build_pair :teacher }
|
||||
name 'The A-Team'
|
||||
end
|
||||
end
|
@ -5,7 +5,7 @@ describe 'Authorization' do
|
||||
let(:user) { FactoryGirl.create(:admin) }
|
||||
before(:each) { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||
|
||||
[Consumer, ExecutionEnvironment, Exercise, FileType, InternalUser, Team].each do |model|
|
||||
[Consumer, ExecutionEnvironment, Exercise, FileType, InternalUser].each do |model|
|
||||
expect_permitted_path(:"new_#{model.model_name.singular}_path")
|
||||
end
|
||||
end
|
||||
@ -14,7 +14,7 @@ describe 'Authorization' do
|
||||
let(:user) { FactoryGirl.create(:external_user) }
|
||||
before(:each) { allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(user) }
|
||||
|
||||
[Consumer, ExecutionEnvironment, Exercise, FileType, InternalUser, Team].each do |model|
|
||||
[Consumer, ExecutionEnvironment, Exercise, FileType, InternalUser].each do |model|
|
||||
expect_forbidden_path(:"new_#{model.model_name.singular}_path")
|
||||
end
|
||||
end
|
||||
@ -27,7 +27,7 @@ describe 'Authorization' do
|
||||
expect_forbidden_path(:"new_#{model.model_name.singular}_path")
|
||||
end
|
||||
|
||||
[ExecutionEnvironment, Exercise, FileType, Team].each do |model|
|
||||
[ExecutionEnvironment, Exercise, FileType].each do |model|
|
||||
expect_permitted_path(:"new_#{model.model_name.singular}_path")
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Team do
|
||||
let(:team) { described_class.create }
|
||||
|
||||
it 'validates the presence of a name' do
|
||||
expect(team.errors[:name]).to be_present
|
||||
end
|
||||
end
|
@ -3,8 +3,6 @@ require 'rails_helper'
|
||||
describe ExercisePolicy do
|
||||
subject { described_class }
|
||||
|
||||
let(:exercise) { FactoryGirl.build(:dummy, team: FactoryGirl.create(:team)) }
|
||||
|
||||
permissions :batch_update? do
|
||||
it 'grants access to admins only' do
|
||||
expect(subject).to permit(FactoryGirl.build(:admin), exercise)
|
||||
@ -40,10 +38,6 @@ describe ExercisePolicy do
|
||||
expect(subject).to permit(exercise.author, exercise)
|
||||
end
|
||||
|
||||
it 'grants access to team members' do
|
||||
expect(subject).to permit(exercise.team.members.first, exercise)
|
||||
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), exercise)
|
||||
@ -71,9 +65,7 @@ describe ExercisePolicy do
|
||||
|
||||
[@admin, @teacher].each do |user|
|
||||
[true, false].each do |public|
|
||||
[@team, nil].each do |team|
|
||||
FactoryGirl.create(:dummy, public: public, team: team, user_id: user.id, user_type: InternalUser.class.name)
|
||||
end
|
||||
FactoryGirl.create(:dummy, public: public, user_id: user.id, user_type: InternalUser.class.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -95,10 +87,6 @@ describe ExercisePolicy do
|
||||
end
|
||||
|
||||
context 'for teachers' do
|
||||
before(:each) do
|
||||
@team = FactoryGirl.create(:team)
|
||||
@team.members << @teacher
|
||||
end
|
||||
|
||||
let(:scope) { Pundit.policy_scope!(@teacher, Exercise) }
|
||||
|
||||
@ -110,12 +98,8 @@ describe ExercisePolicy do
|
||||
expect(scope.map(&:id)).to include(*Exercise.where(public: false, user_id: @teacher.id).map(&:id))
|
||||
end
|
||||
|
||||
it "includes all of team members' non-public exercises" do
|
||||
expect(scope.map(&:id)).to include(*Exercise.where(public: false, team_id: @teacher.teams.first.id).map(&:id))
|
||||
end
|
||||
|
||||
it "does not include other authors' non-public exercises" do
|
||||
expect(scope.map(&:id)).not_to include(*Exercise.where(public: false).where("team_id <> #{@team.id} AND user_id <> #{@teacher.id}").map(&:id))
|
||||
expect(scope.map(&:id)).not_to include(*Exercise.where(public: false).where(user_id <> #{@teacher.id}").map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,41 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TeamPolicy do
|
||||
subject { described_class }
|
||||
|
||||
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