From fd9377fa1a4e1eaef280200430c47036d0e58d71 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Sat, 4 Aug 2018 01:02:38 +0200 Subject: Added method to re-populating SiteStatitiscs counter --- spec/models/site_statistic_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec') diff --git a/spec/models/site_statistic_spec.rb b/spec/models/site_statistic_spec.rb index 9b056fbf332..49b54fb6994 100644 --- a/spec/models/site_statistic_spec.rb +++ b/spec/models/site_statistic_spec.rb @@ -80,4 +80,16 @@ describe SiteStatistic do end end end + + describe '.recalculate_counters!' do + it 'recalculates existing counters' do + create(:project) + described_class.fetch.update(repositories_count: 0, wikis_count: 0) + + described_class.recalculate_counters! + + expect(described_class.fetch.repositories_count).to eq(1) + expect(described_class.fetch.wikis_count).to eq(1) + end + end end -- cgit v1.2.1 From 85e83813379bb7be86e266c67dedcfee2cd6d738 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Thu, 9 Aug 2018 20:41:39 +0200 Subject: Add WikiAccessLevel migration from `NULL` to `20` --- .../migrate_null_wiki_access_levels_spec.rb | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/migrations/migrate_null_wiki_access_levels_spec.rb (limited to 'spec') diff --git a/spec/migrations/migrate_null_wiki_access_levels_spec.rb b/spec/migrations/migrate_null_wiki_access_levels_spec.rb new file mode 100644 index 00000000000..f99273072a2 --- /dev/null +++ b/spec/migrations/migrate_null_wiki_access_levels_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20180809195358_migrate_null_wiki_access_levels.rb') + +describe MigrateNullWikiAccessLevels, :migration do + let(:namespaces) { table('namespaces') } + let(:projects) { table(:projects) } + let(:project_features) { table(:project_features) } + let(:migration) { described_class.new } + + before do + namespace = namespaces.create(name: 'foo', path: 'foo') + + projects.create!(id: 1, name: 'gitlab1', path: 'gitlab1', namespace_id: namespace.id) + projects.create!(id: 2, name: 'gitlab2', path: 'gitlab2', namespace_id: namespace.id) + projects.create!(id: 3, name: 'gitlab3', path: 'gitlab3', namespace_id: namespace.id) + + project_features.create!(id: 1, project_id: 1, wiki_access_level: nil) + project_features.create!(id: 2, project_id: 2, wiki_access_level: 10) + project_features.create!(id: 3, project_id: 3, wiki_access_level: 20) + end + + describe '#up' do + it 'migrates existing project_features with wiki_access_level NULL to 20' do + expect { migration.up }.to change { project_features.where(wiki_access_level: 20).count }.by(1) + end + end +end -- cgit v1.2.1 From 696a5fce687364ec718eeef44d923a686c9e1624 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 15 Aug 2018 01:39:59 +0200 Subject: Refactor Rainbow usage in specs We don't test any specific string generated by it yet, so there is no point in keeping it enabled when we are disabling it everywhere we test its output. --- spec/lib/gitlab/bare_repository_import/importer_spec.rb | 4 ---- spec/lib/system_check/simple_executor_spec.rb | 9 --------- spec/spec_helper.rb | 1 + 3 files changed, 1 insertion(+), 13 deletions(-) (limited to 'spec') diff --git a/spec/lib/gitlab/bare_repository_import/importer_spec.rb b/spec/lib/gitlab/bare_repository_import/importer_spec.rb index 6e21c846c0a..3c63e601abc 100644 --- a/spec/lib/gitlab/bare_repository_import/importer_spec.rb +++ b/spec/lib/gitlab/bare_repository_import/importer_spec.rb @@ -10,9 +10,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do subject(:importer) { described_class.new(admin, bare_repository) } before do - @rainbow = Rainbow.enabled - Rainbow.enabled = false - allow(described_class).to receive(:log) end @@ -20,7 +17,6 @@ describe Gitlab::BareRepositoryImport::Importer, :seed_helper do FileUtils.rm_rf(base_dir) TestEnv.clean_test_path ensure_seeds - Rainbow.enabled = @rainbow end shared_examples 'importing a repository' do diff --git a/spec/lib/system_check/simple_executor_spec.rb b/spec/lib/system_check/simple_executor_spec.rb index 9da3648400e..e71e9da369d 100644 --- a/spec/lib/system_check/simple_executor_spec.rb +++ b/spec/lib/system_check/simple_executor_spec.rb @@ -98,15 +98,6 @@ describe SystemCheck::SimpleExecutor do end end - before do - @rainbow = Rainbow.enabled - Rainbow.enabled = false - end - - after do - Rainbow.enabled = @rainbow - end - describe '#component' do it 'returns stored component name' do expect(subject.component).to eq('Test') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f4441a6b700..a15a46a9534 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,6 +29,7 @@ end # require rainbow gem String monkeypatch, so we can test SystemChecks require 'rainbow/ext/string' +Rainbow.enabled = false # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -- cgit v1.2.1 From 1a54986c166fb13a6a27afcafaa055e1a1749e38 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto Date: Wed, 15 Aug 2018 01:40:29 +0200 Subject: Refactor SiteStatistics to extract refresh logic into a rake task --- spec/models/site_statistic_spec.rb | 12 ------------ spec/tasks/gitlab/site_statistics_rake_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 spec/tasks/gitlab/site_statistics_rake_spec.rb (limited to 'spec') diff --git a/spec/models/site_statistic_spec.rb b/spec/models/site_statistic_spec.rb index 49b54fb6994..9b056fbf332 100644 --- a/spec/models/site_statistic_spec.rb +++ b/spec/models/site_statistic_spec.rb @@ -80,16 +80,4 @@ describe SiteStatistic do end end end - - describe '.recalculate_counters!' do - it 'recalculates existing counters' do - create(:project) - described_class.fetch.update(repositories_count: 0, wikis_count: 0) - - described_class.recalculate_counters! - - expect(described_class.fetch.repositories_count).to eq(1) - expect(described_class.fetch.wikis_count).to eq(1) - end - end end diff --git a/spec/tasks/gitlab/site_statistics_rake_spec.rb b/spec/tasks/gitlab/site_statistics_rake_spec.rb new file mode 100644 index 00000000000..20f0df65e63 --- /dev/null +++ b/spec/tasks/gitlab/site_statistics_rake_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true +require 'rake_helper' + +describe 'rake gitlab:refresh_site_statistics' do + before do + Rake.application.rake_require 'tasks/gitlab/site_statistics' + + create(:project) + SiteStatistic.fetch.update(repositories_count: 0, wikis_count: 0) + end + + let(:task) { 'gitlab:refresh_site_statistics' } + + it 'recalculates existing counters' do + run_rake_task(task) + + expect(SiteStatistic.fetch.repositories_count).to eq(1) + expect(SiteStatistic.fetch.wikis_count).to eq(1) + end + + it 'displays message listing counters' do + expect { run_rake_task(task) }.to output(/Updating Site Statistics counters:.* Repositories\.\.\. OK!.* Wikis\.\.\. OK!/m).to_stdout + end +end -- cgit v1.2.1