summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-07-21 09:12:21 +0000
committerRémy Coutable <remy@rymai.me>2016-07-21 09:12:21 +0000
commit85a539e8ff460559e61bb7b9409864c8e6e3978a (patch)
tree6cf46c0f8c9f2064c04f3452c96cb5224f564780
parent231ba872876590ba6a58111012d8d26d77a07faa (diff)
parentf8afe47a87ca880c95163aa7e731638a730ed14b (diff)
downloadgitlab-ce-85a539e8ff460559e61bb7b9409864c8e6e3978a.tar.gz
Merge branch '20067-wiki-not-visible-from-web' into 'master'
Make Service.external_wikis return only active external wikis Fixes #20067. ## Does this MR meet the acceptance criteria? - [x] No CHANGELOG since it fixes a RC12 regression - Tests - [x] Added for this feature/bug - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5387
-rw-r--r--app/models/service.rb2
-rw-r--r--db/migrate/20160721081015_nullify_has_external_wiki_in_projects.rb13
-rw-r--r--db/schema.rb2
-rw-r--r--spec/models/project_spec.rb64
4 files changed, 52 insertions, 29 deletions
diff --git a/app/models/service.rb b/app/models/service.rb
index a8e1cc2f422..40cd9b861f0 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -26,7 +26,7 @@ class Service < ActiveRecord::Base
scope :visible, -> { where.not(type: ['GitlabIssueTrackerService', 'GitlabCiService']) }
scope :issue_trackers, -> { where(category: 'issue_tracker') }
- scope :external_wikis, -> { where(type: 'ExternalWikiService') }
+ scope :external_wikis, -> { where(type: 'ExternalWikiService').active }
scope :active, -> { where(active: true) }
scope :without_defaults, -> { where(default: false) }
diff --git a/db/migrate/20160721081015_nullify_has_external_wiki_in_projects.rb b/db/migrate/20160721081015_nullify_has_external_wiki_in_projects.rb
new file mode 100644
index 00000000000..4bb5bb79632
--- /dev/null
+++ b/db/migrate/20160721081015_nullify_has_external_wiki_in_projects.rb
@@ -0,0 +1,13 @@
+class NullifyHasExternalWikiInProjects < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def up
+ execute("UPDATE projects SET has_external_wiki = NULL")
+ end
+
+ def down
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c7876426424..d541e1cccb7 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160718153603) do
+ActiveRecord::Schema.define(version: 20160721081015) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index e937beddc46..9b017288488 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -458,44 +458,54 @@ describe Project, models: true do
end
end
- describe "#cache_has_external_wiki" do
+ describe '#external_wiki' do
let(:project) { create(:project) }
- it "stores true if there is an external wiki" do
- services = double(:service, external_wikis: [ExternalWikiService.new])
- expect(project).to receive(:services).and_return(services)
+ context 'with an active external wiki' do
+ before do
+ create(:service, project: project, type: 'ExternalWikiService', active: true)
+ project.external_wiki
+ end
- expect do
- project.cache_has_external_wiki
- end.to change { project.has_external_wiki }.to(true)
- end
+ it 'sets :has_external_wiki as true' do
+ expect(project.has_external_wiki).to be(true)
+ end
- it "stores false if there is no external wiki" do
- services = double(:service, external_wikis: [])
- expect(project).to receive(:services).and_return(services)
+ it 'sets :has_external_wiki as false if an external wiki service is destroyed later' do
+ expect(project.has_external_wiki).to be(true)
- expect do
- project.cache_has_external_wiki
- end.to change { project.has_external_wiki }.to(false)
+ project.services.external_wikis.first.destroy
+
+ expect(project.has_external_wiki).to be(false)
+ end
end
- it "changes to true if an external wiki service is created later" do
- expect do
- project.cache_has_external_wiki
- end.to change { project.has_external_wiki }.to(false)
+ context 'with an inactive external wiki' do
+ before do
+ create(:service, project: project, type: 'ExternalWikiService', active: false)
+ end
- expect do
- create(:service, type: "ExternalWikiService", project: project)
- end.to change { project.has_external_wiki }.to(true)
+ it 'sets :has_external_wiki as false' do
+ expect(project.has_external_wiki).to be(false)
+ end
end
- it "changes to false if an external wiki service is destroyed later" do
- service = create(:service, type: "ExternalWikiService", project: project)
- expect(project.has_external_wiki).to be_truthy
+ context 'with no external wiki' do
+ before do
+ project.external_wiki
+ end
- expect do
- service.destroy
- end.to change { project.has_external_wiki }.to(false)
+ it 'sets :has_external_wiki as false' do
+ expect(project.has_external_wiki).to be(false)
+ end
+
+ it 'sets :has_external_wiki as true if an external wiki service is created later' do
+ expect(project.has_external_wiki).to be(false)
+
+ create(:service, project: project, type: 'ExternalWikiService', active: true)
+
+ expect(project.has_external_wiki).to be(true)
+ end
end
end