diff options
| author | Alex Ives <alex@ives.mn> | 2017-07-24 22:11:22 -0500 |
|---|---|---|
| committer | Alex Ives <alex@ives.mn> | 2017-07-28 14:37:44 -0500 |
| commit | a07fe9d7f8f922020472ed54b060430a6da3da69 (patch) | |
| tree | 0dec18fd2ed81985112ce1a2cee1bcde37e12155 /spec/lib | |
| parent | da967803cce971b184873dbe5d65d07215de0b0a (diff) | |
| download | gitlab-ce-a07fe9d7f8f922020472ed54b060430a6da3da69.tar.gz | |
Fixes #29385: Add /shrug and /tableflip commands
- Updated DSL to support substitution definitions
- Added substitution definition, inherits from command definition
- Added tabelflip and shrug substitutions to interpret service
- Added support for substitution definitions to the extractor for preview mode.
- Added substitution handling in the interpret service
Signed-off-by: Alex Ives <alex@ives.mn>
Diffstat (limited to 'spec/lib')
| -rw-r--r-- | spec/lib/gitlab/quick_actions/dsl_spec.rb | 16 | ||||
| -rw-r--r-- | spec/lib/gitlab/quick_actions/extractor_spec.rb | 37 | ||||
| -rw-r--r-- | spec/lib/gitlab/quick_actions/substitution_definition_spec.rb | 42 |
3 files changed, 94 insertions, 1 deletions
diff --git a/spec/lib/gitlab/quick_actions/dsl_spec.rb b/spec/lib/gitlab/quick_actions/dsl_spec.rb index a4bb3f911d7..ff59dc48bcb 100644 --- a/spec/lib/gitlab/quick_actions/dsl_spec.rb +++ b/spec/lib/gitlab/quick_actions/dsl_spec.rb @@ -42,13 +42,18 @@ describe Gitlab::QuickActions::Dsl do command :with_params_parsing do |parsed| parsed end + + params '<Comment>' + substitution :something do |text| + "#{text} Some complicated thing you want in here" + end end end describe '.command_definitions' do it 'returns an array with commands definitions' do no_args_def, explanation_with_aliases_def, dynamic_description_def, - cc_def, cond_action_def, with_params_parsing_def = + cc_def, cond_action_def, with_params_parsing_def, substitution_def = DummyClass.command_definitions expect(no_args_def.name).to eq(:no_args) @@ -104,6 +109,15 @@ describe Gitlab::QuickActions::Dsl do expect(with_params_parsing_def.condition_block).to be_nil expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc) expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc) + + expect(substitution_def.name).to eq(:something) + expect(substitution_def.aliases).to eq([]) + expect(substitution_def.description).to eq('') + expect(substitution_def.explanation).to eq('') + expect(substitution_def.params).to eq(['<Comment>']) + expect(substitution_def.condition_block).to be_nil + expect(substitution_def.action_block.call('text')).to eq('text Some complicated thing you want in here') + expect(substitution_def.parse_params_block).to be_nil end end end diff --git a/spec/lib/gitlab/quick_actions/extractor_spec.rb b/spec/lib/gitlab/quick_actions/extractor_spec.rb index 9d32938e155..f7c288f2393 100644 --- a/spec/lib/gitlab/quick_actions/extractor_spec.rb +++ b/spec/lib/gitlab/quick_actions/extractor_spec.rb @@ -9,6 +9,11 @@ describe Gitlab::QuickActions::Extractor do command(:assign) { } command(:labels) { } command(:power) { } + command(:noop_command) + substitution(:substitution) { 'foo' } + substitution :shrug do |comment| + "#{comment} SHRUG" + end end.command_definitions end @@ -177,6 +182,38 @@ describe Gitlab::QuickActions::Extractor do expect(msg).to eq "hello\nworld" end + it 'does not extract noop commands' do + msg = %(hello\nworld\n/reopen\n/noop_command) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['reopen']] + expect(msg).to eq "hello\nworld\n/noop_command" + end + + it 'extracts and performs substitution commands' do + msg = %(hello\nworld\n/reopen\n/substitution) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['reopen'], ['substitution']] + expect(msg).to eq "hello\nworld\nfoo" + end + + it 'extracts and performs substitution commands' do + msg = %(hello\nworld\n/reopen\n/shrug this is great?) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['reopen'], ['shrug', 'this is great?']] + expect(msg).to eq "hello\nworld\nthis is great? SHRUG" + end + + it 'extracts and performs substitution commands with comments' do + msg = %(hello\nworld\n/reopen\n/substitution wow this is a thing.) + msg, commands = extractor.extract_commands(msg) + + expect(commands).to eq [['reopen'], ['substitution', 'wow this is a thing.']] + expect(msg).to eq "hello\nworld\nfoo" + end + it 'extracts multiple commands' do msg = %(hello\n/power @user.name %9.10 ~"bar baz.2" label\nworld\n/reopen) msg, commands = extractor.extract_commands(msg) diff --git a/spec/lib/gitlab/quick_actions/substitution_definition_spec.rb b/spec/lib/gitlab/quick_actions/substitution_definition_spec.rb new file mode 100644 index 00000000000..1bb8bc51c96 --- /dev/null +++ b/spec/lib/gitlab/quick_actions/substitution_definition_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Gitlab::QuickActions::SubstitutionDefinition do + let(:content) do + <<EOF +Hello! Let's do this! +/sub_name I like this stuff +EOF + end + subject do + described_class.new(:sub_name, action_block: proc { |text| "#{text} foo" }) + end + + describe '#perform_substitution!' do + it 'returns nil if content is nil' do + expect(subject.perform_substitution(self, nil)).to be_nil + end + + it 'performs the substitution by default' do + expect(subject.perform_substitution(self, content)).to eq <<EOF +Hello! Let's do this! +I like this stuff foo +EOF + end + end + + describe '#match' do + it 'checks the content for the command' do + expect(subject.match(content)).to be_truthy + end + + it 'returns the match data' do + data = subject.match(content) + expect(data).to be_a(MatchData) + expect(data[1]).to eq('I like this stuff') + end + + it 'is nil if content does not have the command' do + expect(subject.match('blah')).to be_falsey + end + end +end |
