rosa-build/spec/support/shared_examples/comments.rb

70 lines
2.3 KiB
Ruby
Raw Normal View History

shared_examples_for 'user with create comment ability' do
it 'should be able to perform create action' do
post :create, @create_params
expect(response).to be_success #redirect_to(@return_path+"#comment#{Comment.last.id}")
end
it 'should create comment in the database' do
2015-04-13 11:15:55 +01:00
expect {
post :create, @create_params
2015-04-13 11:15:55 +01:00
}.to change(Comment, :count).by(1)
end
end
shared_examples_for 'user with update own comment ability' do
it 'should be able to perform update action' do
2014-01-21 04:51:49 +00:00
put :update, {id: @own_comment.id}.merge(@update_params)
expect(response).to be_success
end
it 'should update subscribe body' do
2014-01-21 04:51:49 +00:00
put :update, {id: @own_comment.id}.merge(@update_params)
expect(@own_comment.reload.body).to eq 'updated'
end
end
shared_examples_for 'user with update stranger comment ability' do
it 'should be able to perform update action' do
2014-01-21 04:51:49 +00:00
put :update, {id: @comment.id}.merge(@update_params)
expect(response).to be_success
end
it 'should update comment body' do
2014-01-21 04:51:49 +00:00
put :update, {id: @comment.id}.merge(@update_params)
expect(@comment.reload.body).to eq 'updated'
end
end
shared_examples_for 'user without update stranger comment ability' do
it 'should not be able to perform update action' do
2014-01-21 04:51:49 +00:00
put :update, {id: @comment.id}.merge(@update_params)
expect(response).to redirect_to(forbidden_path)
end
it 'should not update comment body' do
2014-01-21 04:51:49 +00:00
put :update, {id: @comment.id}.merge(@update_params)
expect(@comment.reload.body).to_not eq 'updated'
end
end
shared_examples_for 'user with destroy comment ability' do
it 'should be able to perform destroy action' do
delete :destroy, {id: @comment.id, format: :json}.merge(@path)
expect(response).to be_success #redirect_to(@return_path)
end
it 'should delete comment from database' do
expect do
delete :destroy, {id: @comment.id, format: :json}.merge(@path)
end.to change(Comment, :count).by(-1)
end
end
shared_examples_for 'user without destroy comment ability' do
it 'should not be able to perform destroy action' do
delete :destroy, {id: @comment.id, format: :json}.merge(@path)
expect(response).to redirect_to(forbidden_path)
end
it 'should not delete comment from database' do
expect do
delete :destroy, {id: @comment.id, format: :json}.merge(@path)
end.to_not change(Issue, :count)
2012-12-13 11:30:49 +00:00
end
end