[refs #374] Finished REST API projects,reps,pls read specs

This commit is contained in:
konstantin.grabar 2012-08-22 17:44:01 +04:00
parent fb83011d57
commit 4727be33e4
3 changed files with 148 additions and 17 deletions

View File

@ -1,18 +1,45 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
shared_examples_for 'api platform viewer' do
shared_examples_for 'api platform user with reader rights' do
include_examples "api platform user with show rights"
it 'should be able to perform index action' do
get :index, :format => :json
response.should render_template(:index)
end
end
shared_examples_for 'api platform user with reader rights for hidden platform' do
before(:each) do
@platform.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api platform user with show rights'
end
shared_examples_for 'api platform user without reader rights for hidden platform' do
before(:each) do
@platform.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api platform user without show rights'
end
shared_examples_for "api platform user with show rights" do
it 'should be able to perform show action' do
get :show, :id => @platform.id, :format => :json
response.should render_template(:show)
end
end
shared_examples_for "api platform user without show rights" do
it 'should not be able to perform show action' do
get :show, :id => @platform.id, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
end
end
describe Api::V1::PlatformsController do
before(:each) do
stub_symlink_methods
@ -25,12 +52,12 @@ describe Api::V1::PlatformsController do
context 'for guest' do
it "should not be able to perform index action" do
get :index, :format => :json
response.should redirect_to(new_user_session_path)
response.status.should == 401
end
it "should not be able to perform show action" do
get :show, :id => @platform.id, :format => :json
response.should redirect_to(new_user_session_path)
response.status.should == 401
end
end
@ -41,7 +68,8 @@ describe Api::V1::PlatformsController do
set_session_for(@admin)
end
it_should_behave_like 'api platform viewer'
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user with reader rights for hidden platform'
end
context 'for owner user' do
@ -52,7 +80,8 @@ describe Api::V1::PlatformsController do
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'api platform viewer'
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user with reader rights for hidden platform'
end
context 'for reader user' do
@ -62,6 +91,17 @@ describe Api::V1::PlatformsController do
@platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'reader')
end
it_should_behave_like 'api platform viewer'
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user with reader rights for hidden platform'
end
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
it_should_behave_like 'api platform user with reader rights'
it_should_behave_like 'api platform user without reader rights for hidden platform'
end
end

View File

@ -2,13 +2,40 @@
require 'spec_helper'
shared_examples_for "api projects user with reader rights" do
include_examples "api projects user with show rights"
it "should render index template" do
get :index, :format => :json
render_template(:index)
end
end
it "should render show template" do
get :show, :id => @project, :format => :json
shared_examples_for "api projects user with reader rights for hidden project" do
before(:each) do
@project.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api projects user with show rights'
end
shared_examples_for "api projects user without reader rights for hidden project" do
before(:each) do
@project.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api projects user without show rights'
end
shared_examples_for "api projects user without show rights" do
it "should not show project data" do
get :show, :id => @project.id, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
end
end
shared_examples_for "api projects user with show rights" do
it "should show project data" do
get :show, :id => @project.id, :format => :json
render_template(:show)
end
end
@ -19,15 +46,31 @@ describe Api::V1::ProjectsController do
stub_symlink_methods
@project = FactoryGirl.create(:project)
@hidden_project = FactoryGirl.create(:project)
@another_user = FactoryGirl.create(:user)
end
#TODO: Find out how it works (why it only sets 401 status without redirect on .json)
context 'for guest' do
it 'should not be able to perform index action' do
get :index, :format => :json
#response.should redirect_to(new_user_session_path)
response.body.should == {"message" => "Access violation to this page!"}.to_json
response.status.should == 401
end
it 'should not be able to perform show action' do
get :show, :id => @project.id, :format => :json
response.status.should == 401
end
end
context 'for simple user' do
before(:each) do
@user = FactoryGirl.create(:user)
set_session_for(@user)
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user without reader rights for hidden project'
end
context 'for admin' do
@ -37,6 +80,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'for owner user' do
@ -48,6 +92,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'for reader user' do
@ -58,6 +103,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'for writer user' do
@ -68,7 +114,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'for group' do
@ -79,6 +125,11 @@ describe Api::V1::ProjectsController do
set_session_for(@group_user)
end
context 'with no relations to project' do
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user without reader rights for hidden project'
end
context 'owner of the project' do
before(:each) do
@project.owner = @group; @project.save
@ -91,6 +142,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'admin user' do
@ -99,6 +151,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
end
@ -114,6 +167,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
context 'admin user' do
@ -122,6 +176,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
end
@ -136,6 +191,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
context 'user should has best role' do
before(:each) do
@ -151,6 +207,7 @@ describe Api::V1::ProjectsController do
end
it_should_behave_like 'api projects user with reader rights'
it_should_behave_like 'api projects user with reader rights for hidden project'
end
end
end

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
shared_examples_for 'api repositories view rights' do
shared_examples_for 'api repository user with reader rights' do
it 'should be able to perform index action' do
get :index, :platform_id => @platform.id, :format => :json
response.should render_template(:index)
@ -13,6 +13,36 @@ shared_examples_for 'api repositories view rights' do
end
end
shared_examples_for 'api repository user with reader rights for hidden platform' do
before(:each) do
@platform.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api repository user with show rights'
end
shared_examples_for 'api repository user without reader rights for hidden platform' do
before(:each) do
@platform.update_column(:visibility, 'hidden')
end
it_should_behave_like 'api repository user without show rights'
end
shared_examples_for "api repository user with show rights" do
it 'should be able to perform show action' do
get :show, :id => @repository.id, :format => :json
response.should render_template(:show)
end
end
shared_examples_for "api repository user without show rights" do
it 'should not be able to perform show action' do
get :show, :id => @repository.id, :format => :json
response.body.should == {"message" => "Access violation to this page!"}.to_json
end
end
describe Api::V1::RepositoriesController do
before(:each) do
stub_symlink_methods
@ -27,12 +57,12 @@ describe Api::V1::RepositoriesController do
context 'for guest' do
it "should not be able to perform index action" do
get :index, :platform_id => @platform, :format => :json
response.should redirect_to(new_user_session_path)
response.status.should == 401
end
it "should not be able to perform show action" do
get :show, :id => @repository.id, :format => :json
response.should redirect_to(new_user_session_path)
response.status.should == 401
end
end
@ -42,7 +72,8 @@ describe Api::V1::RepositoriesController do
set_session_for(@admin)
end
it_should_behave_like 'api repositories view rights'
it_should_behave_like 'api repository user with reader rights'
it_should_behave_like 'api repository user with reader rights for hidden platform'
end
context 'for platform owner user' do
@ -54,7 +85,8 @@ describe Api::V1::RepositoriesController do
@repository.platform.relations.create!(:actor_type => 'User', :actor_id => @user.id, :role => 'admin')
end
it_should_behave_like 'api repositories view rights'
it_should_behave_like 'api repository user with reader rights'
it_should_behave_like 'api repository user with reader rights for hidden platform'
end
context 'for user' do
@ -63,6 +95,8 @@ describe Api::V1::RepositoriesController do
set_session_for(@user)
end
it_should_behave_like 'api repositories view rights'
it_should_behave_like 'api repository user with reader rights'
it_should_behave_like 'api repository user without reader rights for hidden platform'
it_should_behave_like 'api repository user with show rights'
end
end