2012-10-16 15:44:21 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
shared_examples_for 'api group user with reader rights' do
|
|
|
|
it 'should be able to perform members action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :members, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it_should_behave_like 'api group user with show rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user with show rights' do
|
|
|
|
it 'should be able to perform show action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform index action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user without reader rights' do
|
|
|
|
it 'should not be able to perform members action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :members, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user with admin rights' do
|
|
|
|
|
|
|
|
context 'api group user with update rights' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {group: {description: 'new description'}, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it 'ensures that group has been updated' do
|
|
|
|
@group.reload
|
|
|
|
@group.description.should == 'new description'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user with add_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :add_member, {member_id: member.id, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform add_member action' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it 'ensures that new member has been added to group' do
|
|
|
|
@group.members.should include(member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user with remove_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
|
|
|
@group.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :remove_member, {member_id: member.id, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform remove_member action' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it 'ensures that member has been removed from group' do
|
|
|
|
@group.members.should_not include(member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user with update_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
|
|
|
@group.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update_member, {member_id: member.id, role: 'reader', id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update_member action' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it 'ensures that member role has been updated in group' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.where(actor_id: member, actor_type: 'User').first.
|
2012-10-16 15:44:21 +01:00
|
|
|
role.should == 'reader'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user with owner rights' do
|
|
|
|
context 'api group user with destroy rights' do
|
|
|
|
it 'should be able to perform destroy action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :destroy, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
it 'ensures that group has been destroyed' do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { delete :destroy, id: @group.id, format: :json }.should change{ Group.count }.by(-1)
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user without admin rights' do
|
|
|
|
context 'api group user without update_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
|
|
|
@group.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update_member, {member_id: member.id, role: 'reader', id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update_member action' do
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that member role has not been updated in group' do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group.actors.where(actor_id: member, actor_type: 'User').first.
|
2012-10-16 15:44:21 +01:00
|
|
|
role.should_not == 'reader'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user without update rights' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :update, {group: {description: 'new description'}, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform update action' do
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that platform has not been updated' do
|
|
|
|
@group.reload
|
|
|
|
@group.description.should_not == 'new description'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user without add_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
put :add_member, {member_id: member.id, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to perform add_member action' do
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that new member has not been added to group' do
|
|
|
|
@group.members.should_not include(member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user without remove_member rights' do
|
|
|
|
let(:member) { FactoryGirl.create(:user) }
|
|
|
|
before do
|
|
|
|
@group.add_member(member)
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :remove_member, {member_id: member.id, id: @group.id}, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to perform update action' do
|
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that member has not been removed from group' do
|
|
|
|
@group.members.should include(member)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'api group user without owner rights' do
|
|
|
|
context 'api group user without destroy rights' do
|
|
|
|
it 'should not be able to perform destroy action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
delete :destroy, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that group has not been destroyed' do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { delete :destroy, id: @group.id, format: :json }.should_not change{ Group.count }
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Api::V1::GroupsController do
|
|
|
|
before do
|
|
|
|
stub_symlink_methods
|
|
|
|
|
|
|
|
@group = FactoryGirl.create(:group)
|
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for guest' do
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2012-10-16 15:44:21 +01:00
|
|
|
it "should not be able to perform index action" do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :index, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be able to perform show action", :anonymous_access => false do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.status.should == 401
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to perform show action", :anonymous_access => true do
|
2014-01-21 04:51:49 +00:00
|
|
|
get :show, id: @group.id, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'api group user without create rights' do
|
2014-01-21 04:51:49 +00:00
|
|
|
let(:params) { {group: {uname: 'test_uname'}} }
|
2012-10-16 15:44:21 +01:00
|
|
|
it 'should not be able to perform create action' do
|
2014-01-21 04:51:49 +00:00
|
|
|
post :create, params, format: :json
|
2012-10-16 15:44:21 +01:00
|
|
|
response.should_not be_success
|
|
|
|
end
|
|
|
|
it 'ensures that group has not been created' do
|
2014-01-21 04:51:49 +00:00
|
|
|
lambda { post :create, params, format: :json }.should_not change{ Group.count }
|
2012-10-16 15:44:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api group user without reader rights'
|
|
|
|
it_should_behave_like 'api group user without admin rights'
|
|
|
|
it_should_behave_like 'api group user without owner rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin' do
|
|
|
|
before do
|
|
|
|
@admin = FactoryGirl.create(:admin)
|
|
|
|
http_login(@admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api group user with reader rights'
|
|
|
|
it_should_behave_like 'api group user with admin rights'
|
|
|
|
it_should_behave_like 'api group user with owner rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for owner user' do
|
|
|
|
before do
|
2014-01-21 04:51:49 +00:00
|
|
|
@group = FactoryGirl.create(:group, owner: @user)
|
2012-10-16 15:44:21 +01:00
|
|
|
http_login(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api group user with reader rights'
|
|
|
|
it_should_behave_like 'api group user with admin rights'
|
|
|
|
it_should_behave_like 'api group user with owner rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for admin user' do
|
|
|
|
before do
|
|
|
|
@group.add_member(@user)
|
|
|
|
http_login(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api group user with reader rights'
|
|
|
|
it_should_behave_like 'api group user with admin rights'
|
|
|
|
it_should_behave_like 'api group user without owner rights'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for simple user' do
|
|
|
|
before do
|
|
|
|
http_login(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'api group user with show rights'
|
|
|
|
it_should_behave_like 'api group user without reader rights'
|
|
|
|
it_should_behave_like 'api group user without admin rights'
|
|
|
|
it_should_behave_like 'api group user without owner rights'
|
|
|
|
end
|
|
|
|
end
|