diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/groups/group_settings_spec.rb | 36 | ||||
-rw-r--r-- | spec/features/projects/settings/visibility_settings_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/deprecated_highlight_cache_spec.rb | 70 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/highlight_cache_spec.rb | 82 | ||||
-rw-r--r-- | spec/requests/api/internal/pages_spec.rb | 7 | ||||
-rw-r--r-- | spec/services/merge_requests/reload_diffs_service_spec.rb | 31 | ||||
-rw-r--r-- | spec/services/notes/create_service_spec.rb | 24 |
8 files changed, 245 insertions, 39 deletions
diff --git a/spec/features/groups/group_settings_spec.rb b/spec/features/groups/group_settings_spec.rb index 41ecd21a386..d686e0ed9d2 100644 --- a/spec/features/groups/group_settings_spec.rb +++ b/spec/features/groups/group_settings_spec.rb @@ -19,6 +19,7 @@ describe 'Edit group settings' do it 'the group is accessible via the new path' do update_path(new_group_path) visit new_group_full_path + expect(current_path).to eq(new_group_full_path) expect(find('h1.home-panel-title')).to have_content(group.name) end @@ -26,6 +27,7 @@ describe 'Edit group settings' do it 'the old group path redirects to the new path' do update_path(new_group_path) visit old_group_full_path + expect(current_path).to eq(new_group_full_path) expect(find('h1.home-panel-title')).to have_content(group.name) end @@ -38,6 +40,7 @@ describe 'Edit group settings' do it 'the subgroup is accessible via the new path' do update_path(new_group_path) visit new_subgroup_full_path + expect(current_path).to eq(new_subgroup_full_path) expect(find('h1.home-panel-title')).to have_content(subgroup.name) end @@ -45,6 +48,7 @@ describe 'Edit group settings' do it 'the old subgroup path redirects to the new path' do update_path(new_group_path) visit old_subgroup_full_path + expect(current_path).to eq(new_subgroup_full_path) expect(find('h1.home-panel-title')).to have_content(subgroup.name) end @@ -66,6 +70,7 @@ describe 'Edit group settings' do it 'the project is accessible via the new path' do update_path(new_group_path) visit new_project_full_path + expect(current_path).to eq(new_project_full_path) expect(find('.breadcrumbs')).to have_content(project.path) end @@ -73,6 +78,7 @@ describe 'Edit group settings' do it 'the old project path redirects to the new path' do update_path(new_group_path) visit old_project_full_path + expect(current_path).to eq(new_project_full_path) expect(find('.breadcrumbs')).to have_content(project.path) end @@ -101,7 +107,7 @@ describe 'Edit group settings' do attach_file(:group_avatar, Rails.root.join('spec', 'fixtures', 'banana_sample.gif')) - expect { save_group }.to change { group.reload.avatar? }.to(true) + expect { save_general_group }.to change { group.reload.avatar? }.to(true) end it 'uploads new group avatar' do @@ -132,6 +138,21 @@ describe 'Edit group settings' do end end + context 'disable email notifications' do + it 'is visible' do + visit edit_group_path(group) + + expect(page).to have_selector('#group_emails_disabled', visible: true) + end + + it 'accepts the changed state' do + visit edit_group_path(group) + check 'group_emails_disabled' + + expect { save_permissions_group }.to change { updated_emails_disabled? }.to(true) + end + end + def update_path(new_group_path) visit edit_group_path(group) @@ -141,9 +162,20 @@ describe 'Edit group settings' do end end - def save_group + def save_general_group page.within('.gs-general') do click_button 'Save changes' end end + + def save_permissions_group + page.within('.gs-permissions') do + click_button 'Save changes' + end + end + + def updated_emails_disabled? + group.reload.clear_memoization(:emails_disabled) + group.emails_disabled? + end end diff --git a/spec/features/projects/settings/visibility_settings_spec.rb b/spec/features/projects/settings/visibility_settings_spec.rb index 0e757e647a0..a2b36874aea 100644 --- a/spec/features/projects/settings/visibility_settings_spec.rb +++ b/spec/features/projects/settings/visibility_settings_spec.rb @@ -64,6 +64,12 @@ describe 'Projects > Settings > Visibility settings', :js do it 'is visible' do expect(page).to have_selector('.js-emails-disabled', visible: true) end + + it 'accepts the changed state' do + find('.js-emails-disabled input[type="checkbox"]').click + + expect { save_permissions_group }.to change { updated_emails_disabled? }.to(true) + end end end @@ -89,4 +95,16 @@ describe 'Projects > Settings > Visibility settings', :js do end end end + + def save_permissions_group + page.within('.sharing-permissions') do + click_button 'Save changes' + wait_for_requests + end + end + + def updated_emails_disabled? + project.reload.clear_memoization(:emails_disabled) + project.emails_disabled? + end end diff --git a/spec/lib/gitlab/diff/deprecated_highlight_cache_spec.rb b/spec/lib/gitlab/diff/deprecated_highlight_cache_spec.rb new file mode 100644 index 00000000000..7e46632ea77 --- /dev/null +++ b/spec/lib/gitlab/diff/deprecated_highlight_cache_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Diff::DeprecatedHighlightCache do + let(:merge_request) { create(:merge_request_with_diffs) } + + subject(:cache) { described_class.new(merge_request.diffs, backend: backend) } + + describe '#decorate' do + let(:backend) { double('backend').as_null_object } + + # Manually creates a Diff::File object to avoid triggering the cache on + # the FileCollection::MergeRequestDiff + let(:diff_file) do + diffs = merge_request.diffs + raw_diff = diffs.diffable.raw_diffs(diffs.diff_options.merge(paths: ['CHANGELOG'])).first + Gitlab::Diff::File.new(raw_diff, + repository: diffs.project.repository, + diff_refs: diffs.diff_refs, + fallback_diff_refs: diffs.fallback_diff_refs) + end + + it 'does not calculate highlighting when reading from cache' do + cache.write_if_empty + cache.decorate(diff_file) + + expect_any_instance_of(Gitlab::Diff::Highlight).not_to receive(:highlight) + + diff_file.highlighted_diff_lines + end + + it 'assigns highlighted diff lines to the DiffFile' do + cache.write_if_empty + cache.decorate(diff_file) + + expect(diff_file.highlighted_diff_lines.size).to be > 5 + end + + it 'submits a single reading from the cache' do + cache.decorate(diff_file) + cache.decorate(diff_file) + + expect(backend).to have_received(:read).with(cache.key).once + end + end + + describe '#write_if_empty' do + let(:backend) { double('backend', read: {}).as_null_object } + + it 'submits a single writing to the cache' do + cache.write_if_empty + cache.write_if_empty + + expect(backend).to have_received(:write).with(cache.key, + hash_including('CHANGELOG-false-false-false'), + expires_in: 1.week).once + end + end + + describe '#clear' do + let(:backend) { double('backend').as_null_object } + + it 'clears cache' do + cache.clear + + expect(backend).to have_received(:delete).with(cache.key) + end + end +end diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index d89be6fef4e..7f207d5d2ee 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -29,13 +29,19 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:diffable) { merge_request.merge_request_diff } end - it 'uses a different cache key if diff line keys change' do - mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil) - key = mr_diff.cache_key + context 'using Gitlab::Diff::DeprecatedHighlightCache' do + before do + stub_feature_flags(hset_redis_diff_caching: false) + end + + it 'uses a different cache key if diff line keys change' do + mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil) + key = mr_diff.cache_key - stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo]) + stub_const('Gitlab::Diff::Line::SERIALIZE_KEYS', [:foo]) - expect(mr_diff.cache_key).not_to eq(key) + expect(mr_diff.cache_key).not_to eq(key) + end end it_behaves_like 'diff statistics' do diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb index bfcfed4231f..97ebe6ae0e4 100644 --- a/spec/lib/gitlab/diff/highlight_cache_spec.rb +++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb @@ -2,14 +2,46 @@ require 'spec_helper' -describe Gitlab::Diff::HighlightCache do +describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do let(:merge_request) { create(:merge_request_with_diffs) } + let(:diff_hash) do + { ".gitignore-false-false-false" => + [{ line_code: nil, rich_text: nil, text: "@@ -17,3 +17,4 @@ rerun.txt", type: "match", index: 0, old_pos: 17, new_pos: 17 }, + { line_code: "a5cc2925ca8258af241be7e5b0381edf30266302_17_17", + rich_text: " <span id=\"LC17\" class=\"line\" lang=\"plaintext\">pickle-email-*.html</span>\n", + text: " pickle-email-*.html", + type: nil, + index: 1, + old_pos: 17, + new_pos: 17 }, + { line_code: "a5cc2925ca8258af241be7e5b0381edf30266302_18_18", + rich_text: " <span id=\"LC18\" class=\"line\" lang=\"plaintext\">.project</span>\n", + text: " .project", + type: nil, + index: 2, + old_pos: 18, + new_pos: 18 }, + { line_code: "a5cc2925ca8258af241be7e5b0381edf30266302_19_19", + rich_text: " <span id=\"LC19\" class=\"line\" lang=\"plaintext\">config/initializers/secret_token.rb</span>\n", + text: " config/initializers/secret_token.rb", + type: nil, + index: 3, + old_pos: 19, + new_pos: 19 }, + { line_code: "a5cc2925ca8258af241be7e5b0381edf30266302_20_20", + rich_text: "+<span id=\"LC20\" class=\"line\" lang=\"plaintext\">.DS_Store</span>", + text: "+.DS_Store", + type: "new", + index: 4, + old_pos: 20, + new_pos: 20 }] } + end - subject(:cache) { described_class.new(merge_request.diffs, backend: backend) } + let(:cache_key) { cache.key } - describe '#decorate' do - let(:backend) { double('backend').as_null_object } + subject(:cache) { described_class.new(merge_request.diffs) } + describe '#decorate' do # Manually creates a Diff::File object to avoid triggering the cache on # the FileCollection::MergeRequestDiff let(:diff_file) do @@ -36,35 +68,43 @@ describe Gitlab::Diff::HighlightCache do expect(diff_file.highlighted_diff_lines.size).to be > 5 end + end - it 'submits a single reading from the cache' do - cache.decorate(diff_file) - cache.decorate(diff_file) + describe '#write_if_empty' do + it 'filters the key/value list of entries to be caches for each invocation' do + expect(cache).to receive(:write_to_redis_hash) + .once.with(hash_including(".gitignore")).and_call_original + expect(cache).to receive(:write_to_redis_hash).once.with({}).and_call_original - expect(backend).to have_received(:read).with(cache.key).once + 2.times { cache.write_if_empty } end - end - describe '#write_if_empty' do - let(:backend) { double('backend', read: {}).as_null_object } + context 'different diff_collections for the same diffable' do + before do + cache.write_if_empty + end - it 'submits a single writing to the cache' do - cache.write_if_empty - cache.write_if_empty + it 'writes an uncached files in the collection to the same redis hash' do + Gitlab::Redis::Cache.with { |r| r.hdel(cache_key, "files/whitespace") } - expect(backend).to have_received(:write).with(cache.key, - hash_including('CHANGELOG-false-false-false'), - expires_in: 1.week).once + expect { cache.write_if_empty } + .to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } } + end end end - describe '#clear' do - let(:backend) { double('backend').as_null_object } + describe '#write_to_redis_hash' do + it 'creates or updates a Redis hash' do + expect { cache.send(:write_to_redis_hash, diff_hash) } + .to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } } + end + end + describe '#clear' do it 'clears cache' do - cache.clear + expect_any_instance_of(Redis).to receive(:del).with(cache_key) - expect(backend).to have_received(:delete).with(cache.key) + cache.clear end end end diff --git a/spec/requests/api/internal/pages_spec.rb b/spec/requests/api/internal/pages_spec.rb index 23bbd0681d6..2887163fe58 100644 --- a/spec/requests/api/internal/pages_spec.rb +++ b/spec/requests/api/internal/pages_spec.rb @@ -47,11 +47,12 @@ describe API::Internal::Pages do project.mark_pages_as_deployed end - context 'not existing host' do - it 'responds with 404 Not Found' do + context 'domain does not exist' do + it 'responds with 204 no content' do query_host('pages.gitlab.io') - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(204) + expect(response.body).to be_empty end end diff --git a/spec/services/merge_requests/reload_diffs_service_spec.rb b/spec/services/merge_requests/reload_diffs_service_spec.rb index cc21348ab11..c450fc0a7dc 100644 --- a/spec/services/merge_requests/reload_diffs_service_spec.rb +++ b/spec/services/merge_requests/reload_diffs_service_spec.rb @@ -33,13 +33,34 @@ describe MergeRequests::ReloadDiffsService, :use_clean_rails_memory_store_cachin end context 'cache clearing' do - it 'clears the cache for older diffs on the merge request' do - old_diff = merge_request.merge_request_diff - old_cache_key = old_diff.diffs_collection.cache_key + context 'using Gitlab::Diff::DeprecatedHighlightCache' do + before do + stub_feature_flags(hset_redis_diff_caching: false) + end - expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original + it 'clears the cache for older diffs on the merge request' do + old_diff = merge_request.merge_request_diff + old_cache_key = old_diff.diffs_collection.cache_key - subject.execute + expect(Rails.cache).to receive(:delete).with(old_cache_key).and_call_original + + subject.execute + end + end + + context 'using Gitlab::Diff::HighlightCache' do + before do + stub_feature_flags(hset_redis_diff_caching: true) + end + + it 'clears the cache for older diffs on the merge request' do + old_diff = merge_request.merge_request_diff + old_cache_key = old_diff.diffs_collection.cache_key + + expect_any_instance_of(Redis).to receive(:del).with(old_cache_key).and_call_original + + subject.execute + end end it 'avoids N+1 queries', :request_store do diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index cd4ea9c401d..79ea8f48a58 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -87,10 +87,28 @@ describe Notes::CreateService do .to receive(:unfolded_diff?) { true } end - it 'clears noteable diff cache when it was unfolded for the note position' do - expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear) + context 'using Gitlab::Diff::DeprecatedHighlightCache' do + before do + stub_feature_flags(hset_redis_diff_caching: false) + end + + it 'clears noteable diff cache when it was unfolded for the note position' do + expect_any_instance_of(Gitlab::Diff::DeprecatedHighlightCache).to receive(:clear) + + described_class.new(project_with_repo, user, new_opts).execute + end + end - described_class.new(project_with_repo, user, new_opts).execute + context 'using Gitlab::Diff::HighlightCache' do + before do + stub_feature_flags(hset_redis_diff_caching: true) + end + + it 'clears noteable diff cache when it was unfolded for the note position' do + expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear) + + described_class.new(project_with_repo, user, new_opts).execute + end end it 'does not clear cache when note is not the first of the discussion' do |