From 2bb1362520bda92423d6d3750af350c79e6451d7 Mon Sep 17 00:00:00 2001 From: yqbk Date: Mon, 4 Jul 2016 16:59:30 +0200 Subject: [PATCH] further delete (spec files) --- db/migrate/20160704143402_remove_teams.rb | 2 +- db/seeds/development.rb | 3 - spec/controllers/teams_controller_spec.rb | 93 ----------------------- spec/factories/team.rb | 6 -- spec/features/authorization_spec.rb | 6 +- spec/models/team_spec.rb | 9 --- spec/policies/exercise_policy_spec.rb | 20 +---- spec/policies/team_policy_spec.rb | 41 ---------- 8 files changed, 6 insertions(+), 174 deletions(-) delete mode 100644 spec/controllers/teams_controller_spec.rb delete mode 100644 spec/factories/team.rb delete mode 100644 spec/models/team_spec.rb delete mode 100644 spec/policies/team_policy_spec.rb diff --git a/db/migrate/20160704143402_remove_teams.rb b/db/migrate/20160704143402_remove_teams.rb index 9c01871a..20b8a204 100644 --- a/db/migrate/20160704143402_remove_teams.rb +++ b/db/migrate/20160704143402_remove_teams.rb @@ -1,6 +1,6 @@ class RemoveTeams < ActiveRecord::Migration def change - remove_column :exercises, :team_id, :integer + remove_reference :exercises, :team drop_table :teams drop_table :internal_users_teams end diff --git a/db/seeds/development.rb b/db/seeds/development.rb index 74783d39..6fc8e050 100644 --- a/db/seeds/development.rb +++ b/db/seeds/development.rb @@ -22,6 +22,3 @@ Hint.create_factories # submissions FactoryGirl.create(:submission, exercise: @exercises[:fibonacci]) - -# teams -FactoryGirl.create(:team, internal_users: InternalUser.limit(10)) diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb deleted file mode 100644 index 78dfc60d..00000000 --- a/spec/controllers/teams_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/factories/team.rb b/spec/factories/team.rb deleted file mode 100644 index f34d323e..00000000 --- a/spec/factories/team.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryGirl.define do - factory :team do - internal_users { build_pair :teacher } - name 'The A-Team' - end -end diff --git a/spec/features/authorization_spec.rb b/spec/features/authorization_spec.rb index 6a7eaad0..7f0ff04f 100644 --- a/spec/features/authorization_spec.rb +++ b/spec/features/authorization_spec.rb @@ -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 diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb deleted file mode 100644 index 777efd32..00000000 --- a/spec/models/team_spec.rb +++ /dev/null @@ -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 diff --git a/spec/policies/exercise_policy_spec.rb b/spec/policies/exercise_policy_spec.rb index c9762f9e..1b25fbca 100644 --- a/spec/policies/exercise_policy_spec.rb +++ b/spec/policies/exercise_policy_spec.rb @@ -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 diff --git a/spec/policies/team_policy_spec.rb b/spec/policies/team_policy_spec.rb deleted file mode 100644 index aa3ba1d8..00000000 --- a/spec/policies/team_policy_spec.rb +++ /dev/null @@ -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