@ -161,70 +161,79 @@ describe ProjectsController, type: :controller do
end
end
end
end
describe 'index' do
describe 'index.html' do
let ( :project_a ) { FactoryGirl . create ( :project , name : 'Project A' , is_public : false , status : true ) }
let ( :project_b ) { FactoryGirl . create ( :project , name : 'Project B' , is_public : false , status : true ) }
let ( :project_c ) { FactoryGirl . create ( :project , name : 'Project C' , is_public : true , status : true ) }
let ( :project_d ) { FactoryGirl . create ( :project , name : 'Project D' , is_public : true , status : false ) }
let ( :projects ) { [ project_a , project_b , project_c , project_d ] }
before do
before do
@project_a = FactoryGirl . create ( :project , name : 'Project A' , is_public : false , status : true )
Role . anonymous
@project_b = FactoryGirl . create ( :project , name : 'Project B' , is_public : false , status : true )
projects
@project_c = FactoryGirl . create ( :project , name : 'Project C' , is_public : true , status : true )
login_as ( user )
@project_d = FactoryGirl . create ( :project , name : 'Project D' , is_public : true , status : false )
get 'index'
end
end
context 'as admin' do
shared_examples_for 'successful index' do
let ( :user ) { FactoryGirl . build ( :admin ) }
it 'is success' do
before do
allow ( User ) . to receive ( :current ) . and_return user
get 'index'
expect ( response ) . to be_success
expect ( response ) . to be_success
end
it 'renders the index template' do
expect ( response ) . to render_template 'index'
expect ( response ) . to render_template 'index'
end
end
end
context 'as admin' do
let ( :user ) { FactoryGirl . build ( :admin ) }
it_behaves_like 'successful index'
it " shows all active projects " do
it " shows all active projects " do
expect ( assigns ( :projects ) ) . to include ( @project_a )
expect ( assigns [ :projects ] )
expect ( assigns ( :projects ) ) . to include ( @project_b )
. to match_array [ project_a , project_b , project_c ]
expect ( assigns ( :projects ) ) . to include ( @project_c )
expect ( assigns ( :projects ) ) . not_to include ( @project_d )
end
end
end
end
context 'as anonymous user' do
context 'as anonymous user' do
let ( :user ) { User . anonymous }
let ( :user ) { User . anonymous }
before do
it_behaves_like 'successful index'
Role . anonymous
allow ( User ) . to receive ( :current ) . and_return user
get 'index'
expect ( response ) . to be_success
expect ( response ) . to render_template 'index'
end
it " shows only (active) public projects " do
it " shows only (active) public projects " do
expect ( assigns ( :projects ) ) . not_to include ( @project_a )
expect ( assigns [ :projects ] )
expect ( assigns ( :projects ) ) . not_to include ( @project_b )
. to match_array [ project_c ]
expect ( assigns ( :projects ) ) . to include ( @project_c )
expect ( assigns ( :projects ) ) . not_to include ( @project_d )
end
end
end
end
context 'as user' do
context 'as user' do
let ( :user ) { FactoryGirl . build ( :user , member_in_project : @ project_b) }
let ( :user ) { FactoryGirl . build ( :user , member_in_project : project_b ) }
before do
it_behaves_like 'successful index'
allow ( User ) . to receive ( :current ) . and_return user
get 'index'
expect ( response ) . to be_success
expect ( response ) . to render_template 'index'
end
it " shows (active) public projects and those in which the user is member of " do
it " shows (active) public projects and those in which the user is member of " do
expect ( assigns ( :projects ) ) . not_to include ( @project_a )
expect ( assigns [ :projects ] )
expect ( assigns ( :projects ) ) . to include ( @project_b )
. to match_array [ project_b , project_c ]
expect ( assigns ( :projects ) ) . to include ( @project_c )
expect ( assigns ( :projects ) ) . not_to include ( @project_d )
end
end
end
end
end
end
describe 'index.html' do
let ( :user ) { FactoryGirl . build ( :admin ) }
before do
login_as ( user )
get 'index' , format : 'atom'
end
it 'is 410 GONE' do
expect ( response . response_code )
. to eql 410
end
end
describe 'settings' do
describe 'settings' do
render_views
render_views