gitlab-org--gitlab-foss/spec/controllers/namespaces_controller_spec.rb

120 lines
3.1 KiB
Ruby
Raw Normal View History

2015-03-27 05:27:13 -04:00
require 'spec_helper'
describe NamespacesController do
let!(:user) { create(:user, :with_avatar) }
2015-03-27 05:27:13 -04:00
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
let!(:group) { create(:group) }
let!(:project) { create(:project, namespace: group) }
context "when the group has public projects" do
before do
project.update_attribute(:visibility_level, Project::PUBLIC)
end
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
context "when the project doesn't have public projects" do
context "when not signed in" do
2015-09-04 14:40:26 -04:00
it "does not redirect to the sign in page" do
2015-03-27 05:27:13 -04:00
get :show, id: group.path
2015-09-04 14:40:26 -04:00
expect(response).not_to redirect_to(new_user_session_path)
2015-03-27 05:27:13 -04:00
end
end
context "when signed in" do
before do
sign_in(user)
end
context "when the user has access to the project" do
before do
project.team << [user, :master]
end
context "when the user is blocked" do
before do
user.block
project.team << [user, :master]
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
context "when the user doesn't have access to the project" do
2015-09-14 08:16:08 -04:00
it "redirects to the group's page" do
2015-03-27 05:27:13 -04:00
get :show, id: group.path
2015-09-14 08:16:08 -04:00
expect(response).to redirect_to(group_path(group))
2015-03-27 05:27:13 -04:00
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