BigW Consortium Gitlab

users_controller_spec.rb 3.48 KB
Newer Older
1 2 3
require 'spec_helper'

describe UsersController do
4
  let(:user) { create(:user) }
5

6
  describe 'GET #show' do
7 8 9 10 11
    it 'is case-insensitive' do
      user = create(:user, username: 'CamelCaseUser')
      sign_in(user)

      get :show, username: user.username.downcase
12

13 14 15 16 17 18
      expect(response).to be_success
    end

    context 'with rendered views' do
      render_views

19 20 21 22
      describe 'when logged in' do
        before do
          sign_in(user)
        end
23

24 25
        it 'renders the show template' do
          get :show, username: user.username
26

27 28 29 30 31 32 33 34 35
          expect(response).to be_success
          expect(response).to render_template('show')
        end
      end

      describe 'when logged out' do
        it 'renders the show template' do
          get :show, username: user.username

36
          expect(response).to have_http_status(200)
37 38
          expect(response).to render_template('show')
        end
39
      end
40
    end
Felipe Artur committed
41

Felipe Artur committed
42
    context 'when public visibility level is restricted' do
Felipe Artur committed
43 44 45 46 47 48 49
      before do
        stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
      end

      context 'when logged out' do
        it 'renders 404' do
          get :show, username: user.username
50
          expect(response).to have_http_status(404)
Felipe Artur committed
51 52 53 54 55 56
        end
      end

      context 'when logged in' do
        before { sign_in(user) }

Felipe Artur committed
57
        it 'renders show' do
Felipe Artur committed
58
          get :show, username: user.username
59
          expect(response).to have_http_status(200)
Felipe Artur committed
60
          expect(response).to render_template('show')
Felipe Artur committed
61 62 63
        end
      end
    end
64
  end
65

66 67
  describe 'GET #calendar' do
    it 'renders calendar' do
68 69
      sign_in(user)

70
      get :calendar, username: user.username
71

72
      expect(response).to render_template('calendar')
73
    end
74 75

    context 'forked project' do
76 77
      let(:project) { create(:project) }
      let(:forked_project) { Projects::ForkService.new(project, user).execute }
78 79 80 81 82 83 84 85 86 87 88 89 90

      before do
        sign_in(user)
        project.team << [user, :developer]
        EventCreateService.new.push(project, user, [])
        EventCreateService.new.push(forked_project, user, [])
      end

      it 'includes forked projects' do
        get :calendar, username: user.username
        expect(assigns(:contributions_calendar).projects.count).to eq(2)
      end
    end
91 92
  end

93
  describe 'GET #calendar_activities' do
94 95
    let!(:project) { create(:project) }
    let!(:user) { create(:user) }
96 97 98

    before do
      allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id])
99 100

      sign_in(user)
101 102 103 104
      project.team << [user, :developer]
    end

    it 'assigns @calendar_date' do
105
      get :calendar_activities, username: user.username, date: '2014-07-31'
106 107 108 109
      expect(assigns(:calendar_date)).to eq(Date.parse('2014-07-31'))
    end

    it 'renders calendar_activities' do
110
      get :calendar_activities, username: user.username
111 112 113
      expect(response).to render_template('calendar_activities')
    end
  end
114 115 116 117 118 119 120 121 122

  describe 'GET #snippets' do
    before do
      sign_in(user)
    end

    context 'format html' do
      it 'renders snippets page' do
        get :snippets, username: user.username
123
        expect(response).to have_http_status(200)
124 125 126 127 128 129 130
        expect(response).to render_template('show')
      end
    end

    context 'format json' do
      it 'response with snippets json data' do
        get :snippets, username: user.username, format: :json
131
        expect(response).to have_http_status(200)
132 133 134 135
        expect(JSON.parse(response.body)).to have_key('html')
      end
    end
  end
136
end