diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-19 12:10:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-19 12:10:32 +0300 |
commit | fcef382cb994b8ecdbff75490bab0425a35f2641 (patch) | |
tree | 1789e9bbda6c4beea4451feb7970705296787445 /spec/support | |
parent | b8f44765693d6f6e4c8df6ab7b7c7b1141f83b26 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
6 files changed, 204 insertions, 22 deletions
diff --git a/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb index 88bcf028b85..2f8ebd0d264 100644 --- a/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_creates_wiki_page_shared_examples.rb @@ -20,15 +20,25 @@ RSpec.shared_examples 'User creates wiki page' do click_link "Create your first page" end - it "shows validation error message" do + it "shows validation error message if the form is force submitted", :js do page.within(".wiki-form") do fill_in(:wiki_content, with: "") - click_on("Create page") + page.execute_script("window.onbeforeunload = null") + page.execute_script("document.querySelector('.wiki-form').submit()") end expect(page).to have_content("The form contains the following error:").and have_content("Content can't be blank") + end + + it "disables the submit button", :js do + page.within(".wiki-form") do + fill_in(:wiki_content, with: "") + expect(page).to have_button('Create page', disabled: true) + end + end + it "makes sure links to unknown pages work correctly", :js do page.within(".wiki-form") do fill_in(:wiki_content, with: "[link test](test)") @@ -42,7 +52,7 @@ RSpec.shared_examples 'User creates wiki page' do expect(page).to have_content("Create New Page") end - it "shows non-escaped link in the pages list" do + it "shows non-escaped link in the pages list", :js do fill_in(:wiki_title, with: "one/two/three-test") page.within(".wiki-form") do @@ -61,7 +71,7 @@ RSpec.shared_examples 'User creates wiki page' do expect(page).to have_field("wiki[message]", with: "Create home") end - it "creates a page from the home page" do + it "creates a page from the home page", :js do fill_in(:wiki_content, with: "[test](test)\n[GitLab API doc](api)\n[Rake tasks](raketasks)\n# Wiki header\n") fill_in(:wiki_message, with: "Adding links to wiki") @@ -142,7 +152,7 @@ RSpec.shared_examples 'User creates wiki page' do end end - it 'creates a wiki page with Org markup', :aggregate_failures do + it 'creates a wiki page with Org markup', :aggregate_failures, :js do org_content = <<~ORG * Heading ** Subheading @@ -170,7 +180,7 @@ RSpec.shared_examples 'User creates wiki page' do visit wiki_path(wiki) end - context "via the `new wiki page` page" do + context "via the `new wiki page` page", :js do it "creates a page with a single word" do click_link("New page") @@ -189,7 +199,7 @@ RSpec.shared_examples 'User creates wiki page' do .and have_content("My awesome wiki!") end - it "creates a page with spaces in the name" do + it "creates a page with spaces in the name", :js do click_link("New page") page.within(".wiki-form") do @@ -207,7 +217,7 @@ RSpec.shared_examples 'User creates wiki page' do .and have_content("My awesome wiki!") end - it "creates a page with hyphens in the name" do + it "creates a page with hyphens in the name", :js do click_link("New page") page.within(".wiki-form") do diff --git a/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb index 20fc91521f9..1e325535e81 100644 --- a/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_updates_wiki_page_shared_examples.rb @@ -90,9 +90,11 @@ RSpec.shared_examples 'User updates wiki page' do expect(page).to have_field('wiki[message]', with: 'Update Wiki title') end - it 'shows a validation error message' do + it 'shows a validation error message if the form is force submitted', :js do fill_in(:wiki_content, with: '') - click_button('Save changes') + + page.execute_script("window.onbeforeunload = null") + page.execute_script("document.querySelector('.wiki-form').submit()") expect(page).to have_selector('.wiki-form') expect(page).to have_content('Edit Page') @@ -101,6 +103,13 @@ RSpec.shared_examples 'User updates wiki page' do expect(find('textarea#wiki_content').value).to eq('') end + it "disables the submit button", :js do + page.within(".wiki-form") do + fill_in(:wiki_content, with: "") + expect(page).to have_button('Save changes', disabled: true) + end + end + it 'shows the emoji autocompletion dropdown', :js do find('#wiki_content').native.send_keys('') fill_in(:wiki_content, with: ':') @@ -108,7 +117,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(page).to have_selector('.atwho-view') end - it 'shows the error message' do + it 'shows the error message', :js do wiki_page.update(content: 'Update') # rubocop:disable Rails/SaveBang click_button('Save changes') @@ -116,7 +125,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(page).to have_content('Someone edited the page the same time you did.') end - it 'updates a page' do + it 'updates a page', :js do fill_in('Content', with: 'Updated Wiki Content') click_on('Save changes') @@ -147,7 +156,7 @@ RSpec.shared_examples 'User updates wiki page' do visit wiki_page_path(wiki, wiki_page, action: :edit) end - it 'moves the page to the root folder' do + it 'moves the page to the root folder', :js do fill_in(:wiki_title, with: "/#{page_name}") click_button('Save changes') @@ -155,7 +164,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(current_path).to eq(wiki_page_path(wiki, page_name)) end - it 'moves the page to other dir' do + it 'moves the page to other dir', :js do new_page_dir = "foo1/bar1/#{page_name}" fill_in(:wiki_title, with: new_page_dir) @@ -165,7 +174,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(current_path).to eq(wiki_page_path(wiki, new_page_dir)) end - it 'remains in the same place if title has not changed' do + it 'remains in the same place if title has not changed', :js do original_path = wiki_page_path(wiki, wiki_page) fill_in(:wiki_title, with: page_name) @@ -175,7 +184,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(current_path).to eq(original_path) end - it 'can be moved to a different dir with a different name' do + it 'can be moved to a different dir with a different name', :js do new_page_dir = "foo1/bar1/new_page_name" fill_in(:wiki_title, with: new_page_dir) @@ -185,7 +194,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(current_path).to eq(wiki_page_path(wiki, new_page_dir)) end - it 'can be renamed and moved to the root folder' do + it 'can be renamed and moved to the root folder', :js do new_name = 'new_page_name' fill_in(:wiki_title, with: "/#{new_name}") @@ -195,7 +204,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(current_path).to eq(wiki_page_path(wiki, new_name)) end - it 'squishes the title before creating the page' do + it 'squishes the title before creating the page', :js do new_page_dir = " foo1 / bar1 / #{page_name} " fill_in(:wiki_title, with: new_page_dir) @@ -224,7 +233,7 @@ RSpec.shared_examples 'User updates wiki page' do expect(page).to have_content('Wiki page was successfully updated.') end - it 'shows a validation error when trying to change the content' do + it 'shows a validation error when trying to change the content', :js do fill_in 'Content', with: 'new content' click_on 'Save changes' diff --git a/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb index d7f5b485a82..14180d503df 100644 --- a/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_views_wiki_empty_shared_examples.rb @@ -53,7 +53,7 @@ RSpec.shared_examples 'User views empty wiki' do if writable element.click_link 'Create your first page' - expect(page).to have_button('Create page') + expect(page).to have_button('Create page', disabled: true) else expect(element).not_to have_link('Create your first page') end diff --git a/spec/support/shared_examples/features/wiki/user_views_wiki_sidebar_shared_examples.rb b/spec/support/shared_examples/features/wiki/user_views_wiki_sidebar_shared_examples.rb index 9be7d739065..639eb3f2b99 100644 --- a/spec/support/shared_examples/features/wiki/user_views_wiki_sidebar_shared_examples.rb +++ b/spec/support/shared_examples/features/wiki/user_views_wiki_sidebar_shared_examples.rb @@ -29,7 +29,7 @@ RSpec.shared_examples 'User views wiki sidebar' do end end - it 'can create a custom sidebar' do + it 'can create a custom sidebar', :js do click_on 'Edit sidebar' fill_in :wiki_content, with: 'My custom sidebar' click_on 'Create page' @@ -55,7 +55,7 @@ RSpec.shared_examples 'User views wiki sidebar' do end end - it 'can edit the custom sidebar' do + it 'can edit the custom sidebar', :js do click_on 'Edit sidebar' expect(page).to have_field(:wiki_content, with: 'My custom sidebar') diff --git a/spec/support/shared_examples/models/concerns/repositories/can_housekeep_repository_shared_examples.rb b/spec/support/shared_examples/models/concerns/repositories/can_housekeep_repository_shared_examples.rb new file mode 100644 index 00000000000..2f0b95427d2 --- /dev/null +++ b/spec/support/shared_examples/models/concerns/repositories/can_housekeep_repository_shared_examples.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'can housekeep repository' do + context 'with a clean redis state', :clean_gitlab_redis_shared_state do + describe '#pushes_since_gc' do + context 'without any pushes' do + it 'returns 0' do + expect(resource.pushes_since_gc).to eq(0) + end + end + + context 'with a number of pushes' do + it 'returns the number of pushes' do + 3.times { resource.increment_pushes_since_gc } + + expect(resource.pushes_since_gc).to eq(3) + end + end + end + + describe '#increment_pushes_since_gc' do + it 'increments the number of pushes since the last GC' do + 3.times { resource.increment_pushes_since_gc } + + expect(resource.pushes_since_gc).to eq(3) + end + end + + describe '#reset_pushes_since_gc' do + it 'resets the number of pushes since the last GC' do + 3.times { resource.increment_pushes_since_gc } + + resource.reset_pushes_since_gc + + expect(resource.pushes_since_gc).to eq(0) + end + end + + describe '#pushes_since_gc_redis_shared_state_key' do + it 'returns the proper redis key format' do + expect(resource.send(:pushes_since_gc_redis_shared_state_key)).to eq("#{resource_key}/#{resource.id}/pushes_since_gc") + end + end + end +end diff --git a/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb new file mode 100644 index 00000000000..a174ae94b75 --- /dev/null +++ b/spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb @@ -0,0 +1,118 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'housekeeps repository' do + subject { described_class.new(resource) } + + context 'with a clean redis state', :clean_gitlab_redis_shared_state do + describe '#execute' do + it 'enqueues a sidekiq job' do + expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid) + expect(subject).to receive(:lease_key).and_return(:the_lease_key) + expect(subject).to receive(:task).and_return(:incremental_repack) + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid).and_call_original + + Sidekiq::Testing.fake! do + expect { subject.execute }.to change(GitGarbageCollectWorker.jobs, :size).by(1) + end + end + + it 'yields the block if given' do + expect do |block| + subject.execute(&block) + end.to yield_with_no_args + end + + it 'resets counter after execution' do + expect(subject).to receive(:try_obtain_lease).and_return(:the_uuid) + allow(subject).to receive(:gc_period).and_return(1) + resource.increment_pushes_since_gc + + perform_enqueued_jobs do + expect { subject.execute }.to change { resource.pushes_since_gc }.to(0) + end + end + + context 'when no lease can be obtained' do + before do + expect(subject).to receive(:try_obtain_lease).and_return(false) + end + + it 'does not enqueue a job' do + expect(GitGarbageCollectWorker).not_to receive(:perform_async) + + expect { subject.execute }.to raise_error(Repositories::HousekeepingService::LeaseTaken) + end + + it 'does not reset pushes_since_gc' do + expect do + expect { subject.execute }.to raise_error(Repositories::HousekeepingService::LeaseTaken) + end.not_to change { resource.pushes_since_gc } + end + + it 'does not yield' do + expect do |block| + expect { subject.execute(&block) } + .to raise_error(Repositories::HousekeepingService::LeaseTaken) + end.not_to yield_with_no_args + end + end + + context 'task type' do + it 'goes through all three housekeeping tasks, executing only the highest task when there is overlap' do + allow(subject).to receive(:try_obtain_lease).and_return(:the_uuid) + allow(subject).to receive(:lease_key).and_return(:the_lease_key) + + # At push 200 + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :gc, :the_lease_key, :the_uuid) + .once + # At push 50, 100, 150 + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :full_repack, :the_lease_key, :the_uuid) + .exactly(3).times + # At push 10, 20, ... (except those above) + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :incremental_repack, :the_lease_key, :the_uuid) + .exactly(16).times + # At push 6, 12, 18, ... (except those above) + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :pack_refs, :the_lease_key, :the_uuid) + .exactly(27).times + + 201.times do + subject.increment! + subject.execute if subject.needed? + end + + expect(resource.pushes_since_gc).to eq(1) + end + end + + it 'runs the task specifically requested' do + housekeeping = described_class.new(resource, :gc) + + allow(housekeeping).to receive(:try_obtain_lease).and_return(:gc_uuid) + allow(housekeeping).to receive(:lease_key).and_return(:gc_lease_key) + + expect(GitGarbageCollectWorker).to receive(:perform_async).with(resource.id, :gc, :gc_lease_key, :gc_uuid).twice + + 2.times do + housekeeping.execute + end + end + end + + describe '#needed?' do + it 'when the count is low enough' do + expect(subject.needed?).to eq(false) + end + + it 'when the count is high enough' do + allow(resource).to receive(:pushes_since_gc).and_return(10) + expect(subject.needed?).to eq(true) + end + end + + describe '#increment!' do + it 'increments the pushes_since_gc counter' do + expect { subject.increment! }.to change { resource.pushes_since_gc }.by(1) + end + end + end +end |