Commit 7945d196 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'fj-improve-some-wiki-specs' into 'master'

Improve some wiki specs

See merge request gitlab-org/gitlab!63150
parents 72ef8dfa 6a498b31
...@@ -17,6 +17,7 @@ RSpec.describe API::Wikis do ...@@ -17,6 +17,7 @@ RSpec.describe API::Wikis do
include WorkhorseHelpers include WorkhorseHelpers
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group, :internal, :wiki_repo) } let(:group) { create(:group, :internal, :wiki_repo) }
let(:wiki) { create(:group_wiki, container: group, user: user) } let(:wiki) { create(:group_wiki, container: group, user: user) }
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } } let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
...@@ -474,8 +475,8 @@ RSpec.describe API::Wikis do ...@@ -474,8 +475,8 @@ RSpec.describe API::Wikis do
end end
context 'when user is owner of parent group' do context 'when user is owner of parent group' do
let(:namespace) { create(:group).tap { |g| g.add_owner(user) } } let_it_be(:namespace) { create(:group).tap { |g| g.add_owner(user) } }
let(:group) { create(:group, :wiki_repo, parent: namespace) } let_it_be(:group) { create(:group, :wiki_repo, parent: namespace) }
include_examples 'wikis API updates wiki page' include_examples 'wikis API updates wiki page'
end end
...@@ -589,8 +590,8 @@ RSpec.describe API::Wikis do ...@@ -589,8 +590,8 @@ RSpec.describe API::Wikis do
end end
context 'when user is owner of parent group' do context 'when user is owner of parent group' do
let(:namespace) { create(:group).tap { |g| g.add_owner(user) } } let_it_be(:namespace) { create(:group).tap { |g| g.add_owner(user) } }
let(:group) { create(:group, :wiki_repo, parent: namespace) } let_it_be(:group) { create(:group, :wiki_repo, parent: namespace) }
before do before do
delete(api(url, user)) delete(api(url, user))
......
...@@ -3,15 +3,12 @@ ...@@ -3,15 +3,12 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Projects > Wiki > User views wiki in project page' do RSpec.describe 'Projects > Wiki > User views wiki in project page' do
let(:user) { create(:user) }
before do before do
project.add_maintainer(user) sign_in(project.owner)
sign_in(user)
end end
context 'when repository is disabled for project' do context 'when repository is disabled for project' do
let(:project) do let_it_be(:project) do
create(:project, create(:project,
:wiki_repo, :wiki_repo,
:repository_disabled, :repository_disabled,
......
...@@ -16,8 +16,19 @@ RSpec.describe API::Wikis do ...@@ -16,8 +16,19 @@ RSpec.describe API::Wikis do
include WorkhorseHelpers include WorkhorseHelpers
include AfterNextHelpers include AfterNextHelpers
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group).tap { |g| g.add_owner(user) } } let_it_be(:group) { create(:group).tap { |g| g.add_owner(user) } }
let_it_be(:group_project) { create(:project, :wiki_repo, namespace: group) }
let_it_be(:developer) { create(:user) }
let_it_be(:maintainer) { create(:user) }
let_it_be(:project_wiki_disabled) do
create(:project, :wiki_repo, :wiki_disabled).tap do |project|
project.add_developer(developer)
project.add_maintainer(maintainer)
end
end
let(:project_wiki) { create(:project_wiki, project: project, user: user) } let(:project_wiki) { create(:project_wiki, project: project, user: user) }
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } } let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
let(:expected_keys_with_content) { %w(content format slug title) } let(:expected_keys_with_content) { %w(content format slug title) }
...@@ -32,7 +43,7 @@ RSpec.describe API::Wikis do ...@@ -32,7 +43,7 @@ RSpec.describe API::Wikis do
let(:url) { "/projects/#{project.id}/wikis" } let(:url) { "/projects/#{project.id}/wikis" }
context 'when wiki is disabled' do context 'when wiki is disabled' do
let(:project) { create(:project, :wiki_repo, :wiki_disabled) } let(:project) { project_wiki_disabled }
context 'when user is guest' do context 'when user is guest' do
before do before do
...@@ -44,9 +55,7 @@ RSpec.describe API::Wikis do ...@@ -44,9 +55,7 @@ RSpec.describe API::Wikis do
context 'when user is developer' do context 'when user is developer' do
before do before do
project.add_developer(user) get api(url, developer)
get api(url, user)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -54,9 +63,7 @@ RSpec.describe API::Wikis do ...@@ -54,9 +63,7 @@ RSpec.describe API::Wikis do
context 'when user is maintainer' do context 'when user is maintainer' do
before do before do
project.add_maintainer(user) get api(url, maintainer)
get api(url, user)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -125,7 +132,7 @@ RSpec.describe API::Wikis do ...@@ -125,7 +132,7 @@ RSpec.describe API::Wikis do
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" } let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
context 'when wiki is disabled' do context 'when wiki is disabled' do
let(:project) { create(:project, :wiki_repo, :wiki_disabled) } let(:project) { project_wiki_disabled }
context 'when user is guest' do context 'when user is guest' do
before do before do
...@@ -137,9 +144,7 @@ RSpec.describe API::Wikis do ...@@ -137,9 +144,7 @@ RSpec.describe API::Wikis do
context 'when user is developer' do context 'when user is developer' do
before do before do
project.add_developer(user) get api(url, developer)
get api(url, user)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -147,9 +152,7 @@ RSpec.describe API::Wikis do ...@@ -147,9 +152,7 @@ RSpec.describe API::Wikis do
context 'when user is maintainer' do context 'when user is maintainer' do
before do before do
project.add_maintainer(user) get api(url, maintainer)
get api(url, user)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -249,7 +252,7 @@ RSpec.describe API::Wikis do ...@@ -249,7 +252,7 @@ RSpec.describe API::Wikis do
let(:url) { "/projects/#{project.id}/wikis" } let(:url) { "/projects/#{project.id}/wikis" }
context 'when wiki is disabled' do context 'when wiki is disabled' do
let(:project) { create(:project, :wiki_disabled, :wiki_repo) } let(:project) { project_wiki_disabled }
context 'when user is guest' do context 'when user is guest' do
before do before do
...@@ -261,8 +264,7 @@ RSpec.describe API::Wikis do ...@@ -261,8 +264,7 @@ RSpec.describe API::Wikis do
context 'when user is developer' do context 'when user is developer' do
before do before do
project.add_developer(user) post(api(url, developer), params: payload)
post(api(url, user), params: payload)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -270,8 +272,7 @@ RSpec.describe API::Wikis do ...@@ -270,8 +272,7 @@ RSpec.describe API::Wikis do
context 'when user is maintainer' do context 'when user is maintainer' do
before do before do
project.add_maintainer(user) post(api(url, maintainer), params: payload)
post(api(url, user), params: payload)
end end
include_examples 'wiki API 403 Forbidden' include_examples 'wiki API 403 Forbidden'
...@@ -469,7 +470,7 @@ RSpec.describe API::Wikis do ...@@ -469,7 +470,7 @@ RSpec.describe API::Wikis do
end end
context 'when wiki belongs to a group project' do context 'when wiki belongs to a group project' do
let(:project) { create(:project, :wiki_repo, namespace: group) } let(:project) { group_project }
include_examples 'wikis API updates wiki page' include_examples 'wikis API updates wiki page'
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment