2011-12-26 15:48:57 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
shared_examples_for 'can subscribe' do
|
2011-12-29 17:03:53 +00:00
|
|
|
it 'should be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-04-06 23:44:05 +01:00
|
|
|
expect(response).to redirect_to(project_issue_path(@project, @issue))
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should create subscribe object into db' do
|
2015-04-14 12:06:44 +01:00
|
|
|
expect { post :create, @create_params }.to change(Subscribe, :count).by(1)
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
shared_examples_for 'can not subscribe' do
|
|
|
|
it 'should not be able to perform create action' do
|
|
|
|
post :create, @create_params
|
2015-04-06 23:44:05 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not create subscribe object into db' do
|
2015-04-14 12:06:44 +01:00
|
|
|
expect { post :create, @create_params }.to_not change(Subscribe, :count)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'can unsubscribe' do
|
|
|
|
it 'should be able to perform destroy action' do
|
|
|
|
delete :destroy, @destroy_params
|
|
|
|
|
2015-04-06 23:44:05 +01:00
|
|
|
expect(response).to redirect_to([@project, @issue])
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reduce subscribes count' do
|
2015-04-14 12:06:44 +01:00
|
|
|
expect { delete :destroy, @destroy_params }.to change(Subscribe, :count).by(-1)
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'can not unsubscribe' do
|
2011-12-29 17:03:53 +00:00
|
|
|
it 'should not be able to perform destroy action' do
|
2011-12-30 14:21:08 +00:00
|
|
|
delete :destroy, @destroy_params
|
|
|
|
|
2015-04-06 23:44:05 +01:00
|
|
|
expect(response).to redirect_to(forbidden_path)
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not reduce subscribes count' do
|
2015-04-14 12:06:44 +01:00
|
|
|
expect { delete :destroy, @destroy_params }.to_not change(Subscribe, :count)
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 01:12:08 +00:00
|
|
|
describe Projects::SubscribesController, type: :controller do
|
2011-12-29 17:03:53 +00:00
|
|
|
before(:each) do
|
2012-05-16 16:29:28 +01:00
|
|
|
stub_symlink_methods
|
2011-12-29 17:03:53 +00:00
|
|
|
|
2012-03-29 21:34:22 +01:00
|
|
|
@project = FactoryGirl.create(:project)
|
2014-01-21 04:51:49 +00:00
|
|
|
@issue = FactoryGirl.create(:issue, project_id: @project.id)
|
2011-12-30 14:21:08 +00:00
|
|
|
|
2014-03-19 07:19:03 +00:00
|
|
|
@create_params = { issue_id: @issue.serial_id, name_with_owner: @project.name_with_owner }
|
|
|
|
@destroy_params = { issue_id: @issue.serial_id, name_with_owner: @project.name_with_owner }
|
2011-12-29 17:03:53 +00:00
|
|
|
|
2015-02-19 01:28:02 +00:00
|
|
|
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
|
2011-12-29 17:03:53 +00:00
|
|
|
|
|
|
|
@request.env['HTTP_REFERER'] = project_issue_path(@project, @issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for global admin user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:admin)
|
2011-12-29 17:03:53 +00:00
|
|
|
set_session_for(@user)
|
2014-03-18 09:31:01 +00:00
|
|
|
create_relation(@project, @user, 'admin')
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'subscribed' do
|
|
|
|
before(:each) do
|
2014-03-21 07:53:25 +00:00
|
|
|
ss = @issue.subscribes.build
|
|
|
|
ss.user = @user
|
2011-12-30 14:21:08 +00:00
|
|
|
ss.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'can unsubscribe'
|
|
|
|
it_should_behave_like 'can not subscribe'
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'not subscribed' do
|
|
|
|
it_should_behave_like 'can subscribe'
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
2011-12-30 14:21:08 +00:00
|
|
|
end
|
2011-12-29 17:03:53 +00:00
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'for simple user' do
|
|
|
|
before(:each) do
|
2012-03-29 21:34:22 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
2011-12-30 14:21:08 +00:00
|
|
|
set_session_for(@user)
|
2014-01-21 04:51:49 +00:00
|
|
|
@destroy_params = @destroy_params.merge({id: @user.id})
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'subscribed' do
|
|
|
|
before(:each) do
|
2014-03-21 07:53:25 +00:00
|
|
|
ss = @issue.subscribes.build
|
|
|
|
ss.user = @user
|
2011-12-30 14:21:08 +00:00
|
|
|
ss.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'can unsubscribe'
|
|
|
|
it_should_behave_like 'can not subscribe'
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
|
|
|
|
2011-12-30 14:21:08 +00:00
|
|
|
context 'not subscribed' do
|
|
|
|
it_should_behave_like 'can subscribe'
|
|
|
|
end
|
2011-12-29 17:03:53 +00:00
|
|
|
end
|
2011-12-26 15:48:57 +00:00
|
|
|
end
|