BigW Consortium Gitlab

milestone_tabs_examples.rb 2.08 KB
Newer Older
Phil Hughes committed
1 2
shared_examples 'milestone tabs' do
  def go(path, extra_params = {})
3 4 5 6 7 8 9 10 11
    params =
      case milestone
      when DashboardMilestone
        { id: milestone.safe_title, title: milestone.title }
      when GroupMilestone
        { group_id: group.to_param, id: milestone.safe_title, title: milestone.title }
      else
        { namespace_id: project.namespace.to_param, project_id: project, id: milestone.iid }
      end
Phil Hughes committed
12 13 14

    get path, params.merge(extra_params)
  end
15

Phil Hughes committed
16 17
  describe '#merge_requests' do
    context 'as html' do
18 19 20
      before do
        go(:merge_requests, format: 'html')
      end
Phil Hughes committed
21 22 23 24 25 26 27

      it 'redirects to milestone#show' do
        expect(response).to redirect_to(milestone_path)
      end
    end

    context 'as json' do
28 29 30
      before do
        go(:merge_requests, format: 'json')
      end
Phil Hughes committed
31 32 33 34 35 36 37 38 39 40

      it 'renders the merge requests tab template to a string' do
        expect(response).to render_template('shared/milestones/_merge_requests_tab')
        expect(json_response).to have_key('html')
      end
    end
  end

  describe '#participants' do
    context 'as html' do
41 42 43
      before do
        go(:participants, format: 'html')
      end
Phil Hughes committed
44 45 46 47 48 49 50

      it 'redirects to milestone#show' do
        expect(response).to redirect_to(milestone_path)
      end
    end

    context 'as json' do
51 52 53
      before do
        go(:participants, format: 'json')
      end
Phil Hughes committed
54 55 56 57 58 59 60 61 62 63

      it 'renders the participants tab template to a string' do
        expect(response).to render_template('shared/milestones/_participants_tab')
        expect(json_response).to have_key('html')
      end
    end
  end

  describe '#labels' do
    context 'as html' do
64 65 66
      before do
        go(:labels, format: 'html')
      end
Phil Hughes committed
67 68 69 70 71 72 73

      it 'redirects to milestone#show' do
        expect(response).to redirect_to(milestone_path)
      end
    end

    context 'as json' do
74 75 76
      before do
        go(:labels, format: 'json')
      end
Phil Hughes committed
77 78 79 80 81 82 83 84

      it 'renders the labels tab template to a string' do
        expect(response).to render_template('shared/milestones/_labels_tab')
        expect(json_response).to have_key('html')
      end
    end
  end
end