diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/models/design_management | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/models/design_management')
-rw-r--r-- | spec/models/design_management/design_collection_spec.rb | 60 | ||||
-rw-r--r-- | spec/models/design_management/design_spec.rb | 26 |
2 files changed, 62 insertions, 24 deletions
diff --git a/spec/models/design_management/design_collection_spec.rb b/spec/models/design_management/design_collection_spec.rb index de766d5ce09..8575cc80b5b 100644 --- a/spec/models/design_management/design_collection_spec.rb +++ b/spec/models/design_management/design_collection_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' RSpec.describe DesignManagement::DesignCollection do include DesignManagementTestHelpers + using RSpec::Parameterized::TableSyntax - let_it_be(:issue, reload: true) { create(:issue) } + let_it_be(:issue, refind: true) { create(:issue) } subject(:collection) { described_class.new(issue) } @@ -41,7 +42,62 @@ RSpec.describe DesignManagement::DesignCollection do design2 = collection.find_or_create_design!(filename: 'design2.jpg') - expect(collection.designs.ordered(issue.project)).to eq([design1, design2]) + expect(collection.designs.ordered).to eq([design1, design2]) + end + end + + describe "#copy_state", :clean_gitlab_redis_shared_state do + it "defaults to ready" do + expect(collection).to be_copy_ready + end + + it "persists its state changes between initializations" do + collection.start_copy! + + expect(described_class.new(issue)).to be_copy_in_progress + end + + where(:state, :can_start, :can_end, :can_error, :can_reset) do + "ready" | true | false | true | true + "in_progress" | false | true | true | true + "error" | false | false | false | true + end + + with_them do + it "maintains state machine transition rules", :aggregate_failures do + collection.copy_state = state + + expect(collection.can_start_copy?).to eq(can_start) + expect(collection.can_end_copy?).to eq(can_end) + end + end + + describe "clearing the redis cached state when state changes back to ready" do + def redis_copy_state + Gitlab::Redis::SharedState.with do |redis| + redis.get(collection.send(:copy_state_cache_key)) + end + end + + def fire_state_events(*events) + events.each do |event| + collection.fire_copy_state_event(event) + end + end + + it "clears the cached state on end_copy!", :aggregate_failures do + fire_state_events(:start) + + expect { collection.end_copy! }.to change { redis_copy_state }.from("in_progress").to(nil) + expect(collection).to be_copy_ready + end + + it "clears the cached state on reset_copy!", :aggregate_failures do + fire_state_events(:start, :error) + + expect { collection.reset_copy! }.to change { redis_copy_state }.from("error").to(nil) + expect(collection).to be_copy_ready + end end end diff --git a/spec/models/design_management/design_spec.rb b/spec/models/design_management/design_spec.rb index 2c129f883b9..d4adc0d42d0 100644 --- a/spec/models/design_management/design_spec.rb +++ b/spec/models/design_management/design_spec.rb @@ -12,8 +12,10 @@ RSpec.describe DesignManagement::Design do let_it_be(:deleted_design) { create(:design, :with_versions, deleted: true) } it_behaves_like 'a class that supports relative positioning' do + let_it_be(:relative_parent) { create(:issue) } + let(:factory) { :design } - let(:default_params) { { issue: issue } } + let(:default_params) { { issue: relative_parent } } end describe 'relations' do @@ -161,27 +163,7 @@ RSpec.describe DesignManagement::Design do end it 'sorts by relative position and ID in ascending order' do - expect(described_class.ordered(issue.project)).to eq([design2, design1, design3, deleted_design]) - end - - context 'when the :reorder_designs feature is enabled for the project' do - before do - stub_feature_flags(reorder_designs: issue.project) - end - - it 'sorts by relative position and ID in ascending order' do - expect(described_class.ordered(issue.project)).to eq([design2, design1, design3, deleted_design]) - end - end - - context 'when the :reorder_designs feature is disabled' do - before do - stub_feature_flags(reorder_designs: false) - end - - it 'sorts by ID in ascending order' do - expect(described_class.ordered(issue.project)).to eq([design1, design2, design3, deleted_design]) - end + expect(described_class.ordered).to eq([design2, design1, design3, deleted_design]) end end |