todos_controller_spec.rb 1.59 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1 2 3
require('spec_helper')

describe Projects::TodosController do
4
  let(:user)          { create(:user) }
5
  let(:project)       { create(:project) }
6 7
  let(:issue)         { create(:issue, project: project) }
  let(:merge_request) { create(:merge_request, source_project: project) }
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  let(:parent)        { project }

  shared_examples 'project todos actions' do
    it_behaves_like 'todos actions'

    context 'when not authorized for resource' do
      before do
        project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
        project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
        project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
        sign_in(user)
      end

      it "doesn't create todo" do
        expect { post_create }.not_to change { user.todos.count }
        expect(response).to have_gitlab_http_status(404)
      end
    end
  end
27 28

  context 'Issues' do
Phil Hughes's avatar
Phil Hughes committed
29
    describe 'POST create' do
30
      def post_create
31
        post :create,
32 33
          namespace_id: project.namespace,
          project_id: project,
34 35 36 37 38
          issuable_id: issue.id,
          issuable_type: 'issue',
          format: 'html'
      end

39
      it_behaves_like 'project todos actions'
Phil Hughes's avatar
Phil Hughes committed
40 41 42
    end
  end

43
  context 'Merge Requests' do
Phil Hughes's avatar
Phil Hughes committed
44
    describe 'POST create' do
45
      def post_create
46
        post :create,
47 48
          namespace_id: project.namespace,
          project_id: project,
49 50 51 52 53
          issuable_id: merge_request.id,
          issuable_type: 'merge_request',
          format: 'html'
      end

54
      it_behaves_like 'project todos actions'
55 56
    end
  end
Phil Hughes's avatar
Phil Hughes committed
57
end