2020-05-22 05:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe SnippetInputActionCollection do
|
2020-05-22 05:08:09 -04:00
|
|
|
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) }
|
2020-05-26 14:08:20 -04:00
|
|
|
it { is_expected.to delegate_method(:any?).to(:actions) }
|
|
|
|
it { is_expected.to delegate_method(:[]).to(:actions) }
|
2020-05-22 05:08:09 -04:00
|
|
|
|
|
|
|
describe '#to_commit_actions' do
|
2022-08-03 05:12:13 -04:00
|
|
|
subject { described_class.new(data).to_commit_actions }
|
2020-05-22 05:08:09 -04:00
|
|
|
|
|
|
|
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
|
2022-08-03 05:12:13 -04:00
|
|
|
subject { described_class.new(data).valid? }
|
2020-05-22 05:08:09 -04:00
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when any of the actions is invalid' do
|
2022-08-03 05:12:13 -04:00
|
|
|
let(:data) { [action, { action: 'foo' }, action] }
|
2020-05-22 05:08:09 -04:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-16 05:08:27 -04:00
|
|
|
|
|
|
|
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
|
2020-05-22 05:08:09 -04:00
|
|
|
end
|