Make Service.external_wikis return only active external wikis
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
8ed9705483
commit
f8afe47a87
4 changed files with 52 additions and 29 deletions
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
it 'sets :has_external_wiki as true' do
|
||||
expect(project.has_external_wiki).to be(true)
|
||||
end
|
||||
|
||||
it 'sets :has_external_wiki as false if an external wiki service is destroyed later' do
|
||||
expect(project.has_external_wiki).to be(true)
|
||||
|
||||
project.services.external_wikis.first.destroy
|
||||
|
||||
expect(project.has_external_wiki).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
it "stores false if there is no external wiki" do
|
||||
services = double(:service, external_wikis: [])
|
||||
expect(project).to receive(:services).and_return(services)
|
||||
context 'with an inactive external wiki' do
|
||||
before do
|
||||
create(:service, project: project, type: 'ExternalWikiService', active: false)
|
||||
end
|
||||
|
||||
expect do
|
||||
project.cache_has_external_wiki
|
||||
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
|
||||
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 no external wiki' do
|
||||
before do
|
||||
project.external_wiki
|
||||
end
|
||||
|
||||
expect do
|
||||
create(:service, type: "ExternalWikiService", project: project)
|
||||
end.to change { project.has_external_wiki }.to(true)
|
||||
end
|
||||
it 'sets :has_external_wiki as false' do
|
||||
expect(project.has_external_wiki).to be(false)
|
||||
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
|
||||
it 'sets :has_external_wiki as true if an external wiki service is created later' do
|
||||
expect(project.has_external_wiki).to be(false)
|
||||
|
||||
expect do
|
||||
service.destroy
|
||||
end.to change { project.has_external_wiki }.to(false)
|
||||
create(:service, project: project, type: 'ExternalWikiService', active: true)
|
||||
|
||||
expect(project.has_external_wiki).to be(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue