#465: Update specs for Platforms::PlatformsController
This commit is contained in:
parent
d2ea9f03ae
commit
2dc5bb4b97
|
@ -52,6 +52,7 @@ class PlatformPolicy < ApplicationPolicy
|
||||||
def clone?
|
def clone?
|
||||||
record.main? && is_admin?
|
record.main? && is_admin?
|
||||||
end
|
end
|
||||||
|
alias_method :make_clone?, :clone?
|
||||||
|
|
||||||
def add_member?
|
def add_member?
|
||||||
record.main? && ( is_admin? || owner? || local_admin? )
|
record.main? && ( is_admin? || owner? || local_admin? )
|
||||||
|
|
|
@ -6,8 +6,8 @@ shared_examples_for 'platform user with reader rights' do
|
||||||
[:members, :advisories].each do |action|
|
[:members, :advisories].each do |action|
|
||||||
it 'should be able to perform advisories action' do
|
it 'should be able to perform advisories action' do
|
||||||
get action, id: @platform.id
|
get action, id: @platform.id
|
||||||
response.should render_template(action)
|
expect(response).to render_template(action)
|
||||||
response.should be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,11 +20,10 @@ shared_examples_for 'platform user with owner rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform update action' do
|
it 'should be able to perform update action' do
|
||||||
response.should redirect_to(platform_path(@platform))
|
expect(response).to redirect_to(platform_path(@platform))
|
||||||
end
|
end
|
||||||
it 'ensures that platform has been updated' do
|
it 'ensures that platform has been updated' do
|
||||||
@platform.reload
|
expect(@platform.reload.description).to eq 'new description'
|
||||||
@platform.description.should == 'new description'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,29 +34,32 @@ shared_examples_for 'platform user with owner rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform action' do
|
it 'should be able to perform action' do
|
||||||
response.should redirect_to(platform_path(@platform))
|
expect(response).to redirect_to(platform_path(@platform))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ensures that visibility of platform has been changed' do
|
it 'ensures that visibility of platform has been changed' do
|
||||||
@platform.reload
|
expect(@platform.reload.visibility).to_not eq @visibility
|
||||||
@platform.visibility.should_not == @visibility
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'platform user with destroy rights for main platforms only' do
|
context 'platform user with destroy rights for main platforms only' do
|
||||||
it 'should be able to perform destroy action for main platform' do
|
it 'should be able to perform destroy action for main platform' do
|
||||||
delete :destroy, id: @platform.id
|
delete :destroy, id: @platform.id
|
||||||
response.should redirect_to(platforms_path)
|
expect(response).to redirect_to(platforms_path)
|
||||||
end
|
end
|
||||||
it 'ensures that main platform has been destroyed' do
|
it 'ensures that main platform has been destroyed' do
|
||||||
lambda { delete :destroy, id: @platform.id }.should change{ Platform.count }.by(-1)
|
expect do
|
||||||
|
delete :destroy, id: @platform.id
|
||||||
|
end.to change(Platform, :count).by(-1)
|
||||||
end
|
end
|
||||||
it 'should not be able to perform destroy action for personal platform' do
|
it 'should not be able to perform destroy action for personal platform' do
|
||||||
delete :destroy, id: @personal_platform.id
|
delete :destroy, id: @personal_platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'ensures that personal platform has not been destroyed' do
|
it 'ensures that personal platform has not been destroyed' do
|
||||||
lambda { delete :destroy, id: @personal_platform.id }.should change{ Platform.count }.by(0)
|
expect do
|
||||||
|
delete :destroy, id: @personal_platform.id
|
||||||
|
end.to_not change(Platform, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,11 +71,10 @@ shared_examples_for 'platform user without owner rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform update action' do
|
it 'should not be able to perform update action' do
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'ensures that platform has not been updated' do
|
it 'ensures that platform has not been updated' do
|
||||||
@platform.reload
|
expect(@platform.reload.description).to_not eq 'new description'
|
||||||
@platform.description.should_not == 'new description'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,29 +85,32 @@ shared_examples_for 'platform user without owner rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform action' do
|
it 'should not be able to perform action' do
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ensures that visibility of platform has not been changed' do
|
it 'ensures that visibility of platform has not been changed' do
|
||||||
@platform.reload
|
expect(@platform.reload.visibility).to eq @visibility
|
||||||
@platform.visibility.should == @visibility
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'platform user without destroy rights' do
|
context 'platform user without destroy rights' do
|
||||||
it 'should not be able to perform destroy action for main platform' do
|
it 'should not be able to perform destroy action for main platform' do
|
||||||
delete :destroy, id: @platform.id
|
delete :destroy, id: @platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'ensures that main platform has not been destroyed' do
|
it 'ensures that main platform has not been destroyed' do
|
||||||
lambda { delete :destroy, id: @platform.id }.should_not change{ Platform.count }
|
expect do
|
||||||
|
delete :destroy, id: @platform.id
|
||||||
|
end.to_not change(Platform, :count)
|
||||||
end
|
end
|
||||||
it 'should not be able to perform destroy action for personal platform' do
|
it 'should not be able to perform destroy action for personal platform' do
|
||||||
delete :destroy, id: @personal_platform.id
|
delete :destroy, id: @personal_platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'ensures that personal platform has not been destroyed' do
|
it 'ensures that personal platform has not been destroyed' do
|
||||||
lambda { delete :destroy, id: @personal_platform.id }.should_not change{ Platform.count }
|
expect do
|
||||||
|
delete :destroy, id: @personal_platform.id
|
||||||
|
end.to_not change(Platform, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -121,10 +125,10 @@ shared_examples_for 'platform user with member rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform add_member action' do
|
it 'should be able to perform add_member action' do
|
||||||
response.should redirect_to(members_platform_path(@platform))
|
expect(response).to redirect_to(members_platform_path(@platform))
|
||||||
end
|
end
|
||||||
it 'ensures that new member has been added to platform' do
|
it 'ensures that new member has been added to platform' do
|
||||||
@platform.members.should include(member)
|
expect(@platform.members).to include(member)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,10 +140,10 @@ shared_examples_for 'platform user with member rights' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be able to perform remove_members action' do
|
it 'should be able to perform remove_members action' do
|
||||||
response.should redirect_to(members_platform_path(@platform))
|
expect(response).to redirect_to(members_platform_path(@platform))
|
||||||
end
|
end
|
||||||
it 'ensures that member has been removed from platform' do
|
it 'ensures that member has been removed from platform' do
|
||||||
@platform.members.should_not include(member)
|
expect(@platform.members).to_not include(member)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,10 +158,10 @@ shared_examples_for 'platform user without member rights' do |guest = false|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform add_member action' do
|
it 'should not be able to perform add_member action' do
|
||||||
response.should redirect_to(guest ? new_user_session_path : forbidden_path)
|
expect(response).to redirect_to(guest ? new_user_session_path : forbidden_path)
|
||||||
end
|
end
|
||||||
it 'ensures that new member has not been added to platform' do
|
it 'ensures that new member has not been added to platform' do
|
||||||
@platform.members.should_not include(member)
|
expect(@platform.members).to_not include(member)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -169,10 +173,10 @@ shared_examples_for 'platform user without member rights' do |guest = false|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform remove_members action' do
|
it 'should not be able to perform remove_members action' do
|
||||||
response.should redirect_to(guest ? new_user_session_path : forbidden_path)
|
expect(response).to redirect_to(guest ? new_user_session_path : forbidden_path)
|
||||||
end
|
end
|
||||||
it 'ensures that member has not been removed from platform' do
|
it 'ensures that member has not been removed from platform' do
|
||||||
@platform.members.should include(member)
|
expect(@platform.members).to include(member)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,38 +186,40 @@ shared_examples_for 'platform user without global admin rights' do
|
||||||
context 'should not be able to perform clear action' do
|
context 'should not be able to perform clear action' do
|
||||||
it 'for personal platform' do
|
it 'for personal platform' do
|
||||||
put :clear, id: @personal_platform.id
|
put :clear, id: @personal_platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'for main platform' do
|
it 'for main platform' do
|
||||||
put :clear, id: @platform.id
|
put :clear, id: @platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'should not be able to perform clone action' do
|
context 'should not be able to perform clone action' do
|
||||||
it 'for personal platform' do
|
it 'for personal platform' do
|
||||||
get :clone, id: @personal_platform.id
|
get :clone, id: @personal_platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it 'for main platform' do
|
it 'for main platform' do
|
||||||
get :clone, id: @platform.id
|
get :clone, id: @platform.id
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to perform new action' do
|
it 'should not be able to perform new action' do
|
||||||
get :new
|
get :new
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
[:create, :make_clone].each do |action|
|
[:create, :make_clone].each do |action|
|
||||||
context "platform user without #{action} rights" do
|
context "platform user without #{action} rights" do
|
||||||
it "should not be able to perform #{action} action" do
|
it "should not be able to perform #{action} action" do
|
||||||
post action, clone_or_create_params
|
post action, clone_or_create_params
|
||||||
response.should_not be_success
|
expect(response).to_not be_success
|
||||||
end
|
end
|
||||||
it "ensures that platform has not been #{action}d" do
|
it "ensures that platform has not been #{action}d" do
|
||||||
lambda { post action, clone_or_create_params }.should_not change{ Platform.count }
|
expect do
|
||||||
|
post action, clone_or_create_params
|
||||||
|
end.to_not change(Platform, :count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -235,7 +241,7 @@ shared_examples_for 'platform user without reader rights for hidden platform' do
|
||||||
[:show, :members].each do |action|
|
[:show, :members].each do |action|
|
||||||
it "should not be able to perform #{ action } action" do
|
it "should not be able to perform #{ action } action" do
|
||||||
get action, id: @platform.id
|
get action, id: @platform.id
|
||||||
response.should redirect_to(forbidden_path)
|
expect(response).to redirect_to(forbidden_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -243,8 +249,8 @@ end
|
||||||
shared_examples_for 'platform user with show rights' do
|
shared_examples_for 'platform user with show rights' do
|
||||||
it 'should be able to perform show action' do
|
it 'should be able to perform show action' do
|
||||||
get :show, id: @platform.id
|
get :show, id: @platform.id
|
||||||
response.should render_template(:show)
|
expect(response).to render_template(:show)
|
||||||
assigns(:platform).should eq @platform
|
expect(assigns(:platform)).to eq @platform
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -263,13 +269,13 @@ describe Platforms::PlatformsController, type: :controller do
|
||||||
|
|
||||||
it "should not be able to perform index action" do
|
it "should not be able to perform index action" do
|
||||||
get :index
|
get :index
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
[:show, :members, :advisories].each do |action|
|
[:show, :members, :advisories].each do |action|
|
||||||
it "should not be able to perform #{ action } action", anonymous_access: false do
|
it "should not be able to perform #{ action } action", anonymous_access: false do
|
||||||
get action, id: @platform
|
get action, id: @platform
|
||||||
response.should redirect_to(new_user_session_path)
|
expect(response).to redirect_to(new_user_session_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -293,12 +299,12 @@ describe Platforms::PlatformsController, type: :controller do
|
||||||
|
|
||||||
it "should be able to perform new action" do
|
it "should be able to perform new action" do
|
||||||
get :new, id: @platform
|
get :new, id: @platform
|
||||||
response.should render_template(:new)
|
expect(response).to render_template(:new)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to perform clone action" do
|
it "should be able to perform clone action" do
|
||||||
get :clone, id: @platform
|
get :clone, id: @platform
|
||||||
response.should render_template(:clone)
|
expect(response).to render_template(:clone)
|
||||||
end
|
end
|
||||||
|
|
||||||
[:make_clone, :create].each do |action|
|
[:make_clone, :create].each do |action|
|
||||||
|
@ -308,10 +314,12 @@ describe Platforms::PlatformsController, type: :controller do
|
||||||
end
|
end
|
||||||
it "should be able to perform #{action} action" do
|
it "should be able to perform #{action} action" do
|
||||||
post action, clone_or_create_params
|
post action, clone_or_create_params
|
||||||
response.should redirect_to(platform_path(Platform.last))
|
expect(response).to redirect_to(platform_path(Platform.last))
|
||||||
end
|
end
|
||||||
it "ensures that platform has been #{action}d" do
|
it "ensures that platform has been #{action}d" do
|
||||||
lambda { post action, clone_or_create_params }.should change{ Platform.count }.by(1)
|
expect do
|
||||||
|
post action, clone_or_create_params
|
||||||
|
end.to change(Platform, :count).by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -368,7 +376,7 @@ describe Platforms::PlatformsController, type: :controller do
|
||||||
|
|
||||||
it "should be able to perform index action" do
|
it "should be able to perform index action" do
|
||||||
get :index
|
get :index
|
||||||
response.should render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like 'platform user with reader rights'
|
it_should_behave_like 'platform user with reader rights'
|
||||||
|
|
Loading…
Reference in New Issue