diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/models/snippet_input_action_collection_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/models/snippet_input_action_collection_spec.rb')
-rw-r--r-- | spec/models/snippet_input_action_collection_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/models/snippet_input_action_collection_spec.rb b/spec/models/snippet_input_action_collection_spec.rb new file mode 100644 index 00000000000..ef18ab5a810 --- /dev/null +++ b/spec/models/snippet_input_action_collection_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe SnippetInputActionCollection do + let(:action_name) { 'create' } + let(:action) { { action: action_name, file_path: 'foo', content: 'bar', previous_path: 'foobar' } } + let(:data) { [action, action] } + + it { is_expected.to delegate_method(:empty?).to(:actions) } + it { is_expected.to delegate_method(:any?).to(:actions) } + it { is_expected.to delegate_method(:[]).to(:actions) } + + describe '#to_commit_actions' do + subject { described_class.new(data).to_commit_actions} + + it 'translates all actions to commit actions' do + transformed_action = action.merge(action: action_name.to_sym) + + expect(subject).to eq [transformed_action, transformed_action] + end + end + + describe '#valid?' do + subject { described_class.new(data).valid?} + + it 'returns true' do + expect(subject).to be true + end + + context 'when any of the actions is invalid' do + let(:data) { [action, { action: 'foo' }, action]} + + it 'returns false' do + expect(subject).to be false + end + end + end + + context 'when allowed_actions param is passed' do + it 'builds SnippetInputAction with that param' do + expect(SnippetInputAction).to receive(:new).with(hash_including(allowed_actions: :create)) + + described_class.new([action], allowed_actions: :create) + end + end +end |