BigW Consortium Gitlab

namespaces_controller_spec.rb 3 KB
Newer Older
Douwe Maan committed
1 2 3
require 'spec_helper'

describe NamespacesController do
4
  let!(:user) { create(:user, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) }
Douwe Maan committed
5 6 7 8 9 10 11 12 13 14 15 16 17

  describe "GET show" do
    context "when the namespace belongs to a user" do
      let!(:other_user) { create(:user) }

      it "redirects to the user's page" do
        get :show, id: other_user.username

        expect(response).to redirect_to(user_path(other_user))
      end
    end

    context "when the namespace belongs to a group" do
18
      let!(:group)   { create(:group) }
Douwe Maan committed
19

20
      context "when the group is public" do
Douwe Maan committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        context "when not signed in" do
          it "redirects to the group's page" do
            get :show, id: group.path

            expect(response).to redirect_to(group_path(group))
          end
        end

        context "when signed in" do
          before do
            sign_in(user)
          end

          it "redirects to the group's page" do
            get :show, id: group.path

            expect(response).to redirect_to(group_path(group))
          end
        end
      end

42
      context "when the group is private" do
Douwe Maan committed
43 44 45 46
        before do
          group.update_attribute(:visibility_level, Group::PRIVATE)
        end

Douwe Maan committed
47
        context "when not signed in" do
Douwe Maan committed
48
          it "redirects to the sign in page" do
Douwe Maan committed
49
            get :show, id: group.path
Douwe Maan committed
50
            expect(response).to redirect_to(new_user_session_path)
Douwe Maan committed
51 52
          end
        end
53

Douwe Maan committed
54 55 56 57 58
        context "when signed in" do
          before do
            sign_in(user)
          end

59
          context "when the user has access to the group" do
Douwe Maan committed
60
            before do
61
              group.add_developer(user)
Douwe Maan committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
            end

            context "when the user is blocked" do
              before do
                user.block
              end

              it "redirects to the sign in page" do
                get :show, id: group.path

                expect(response).to redirect_to(new_user_session_path)
              end
            end

            context "when the user isn't blocked" do
              it "redirects to the group's page" do
                get :show, id: group.path

                expect(response).to redirect_to(group_path(group))
              end
            end
          end

85 86
          context "when the user doesn't have access to the group" do
            it "responds with status 404" do
Douwe Maan committed
87 88
              get :show, id: group.path

89
              expect(response.status).to eq(404)
Douwe Maan committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            end
          end
        end
      end
    end

    context "when the namespace doesn't exist" do
      context "when signed in" do
        before do
          sign_in(user)
        end

        it "responds with status 404" do
          get :show, id: "doesntexist"

          expect(response.status).to eq(404)
        end
      end

      context "when not signed in" do
        it "redirects to the sign in page" do
          get :show, id: "doesntexist"

          expect(response).to redirect_to(new_user_session_path)
        end
      end
    end
  end
end