2015-03-27 05:27:13 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe NamespacesController do
|
2016-03-15 08:20:54 -04:00
|
|
|
let!(:user) { create(:user, avatar: fixture_file_upload(Rails.root + "spec/fixtures/dk.png", "image/png")) }
|
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
|
2016-03-20 16:03:53 -04:00
|
|
|
let!(:group) { create(:group) }
|
2015-03-27 05:27:13 -04:00
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
context "when the group is public" do
|
2015-03-27 05:27:13 -04:00
|
|
|
before do
|
2016-03-20 16:03:53 -04:00
|
|
|
group.update_attribute(:visibility_level, Group::PUBLIC)
|
2015-03-27 05:27:13 -04:00
|
|
|
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
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
context "when the group is private" do
|
2015-03-27 05:27:13 -04:00
|
|
|
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
|
2016-03-20 16:03:53 -04:00
|
|
|
|
2015-03-27 05:27:13 -04:00
|
|
|
context "when signed in" do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
context "when the user has access to the group" do
|
2015-03-27 05:27:13 -04:00
|
|
|
before do
|
2016-03-20 16:03:53 -04:00
|
|
|
group.add_developer(user)
|
2015-03-27 05:27:13 -04:00
|
|
|
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
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
context "when the user doesn't have access to the group" do
|
|
|
|
it "responds with status 404" do
|
2015-03-27 05:27:13 -04:00
|
|
|
get :show, id: group.path
|
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
expect(response.status).to eq(404)
|
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
|