diff options
author | Rémy Coutable <remy@rymai.me> | 2016-08-09 23:47:29 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-08-13 01:06:12 +0300 |
commit | e021604454f1093b7d762b28eae36e30083f0053 (patch) | |
tree | 6f6377cb9d7a92838dae62a7e59e87b9699c2c98 /spec | |
parent | 39f7f63fe951ff861ad151125188e6cdd598b6ff (diff) |
Don't extract slash commands inside blockcode, blockquote or HTML tags
Improve slash command descriptions, support /due tomorrow
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/slash_commands/extractor_spec.rb | 27 | ||||
-rw-r--r-- | spec/services/slash_commands/interpret_service_spec.rb | 14 |
2 files changed, 37 insertions, 4 deletions
diff --git a/spec/lib/gitlab/slash_commands/extractor_spec.rb b/spec/lib/gitlab/slash_commands/extractor_spec.rb index fd1b30052ed..11836b10204 100644 --- a/spec/lib/gitlab/slash_commands/extractor_spec.rb +++ b/spec/lib/gitlab/slash_commands/extractor_spec.rb @@ -173,5 +173,32 @@ describe Gitlab::SlashCommands::Extractor do expect(commands).to be_empty expect(msg).to eq 'Fixes #123' end + + it 'does not extract commands inside a blockcode' do + msg = msg = "Hello\r\n```\r\nThis is some text\r\n/close\r\n/assign @user\r\n```\r\n\r\nWorld" + expected = msg.delete("\r") + commands = extractor.extract_commands!(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end + + it 'does not extract commands inside a blockquote' do + msg = "Hello\r\n>>>\r\nThis is some text\r\n/close\r\n/assign @user\r\n>>>\r\n\r\nWorld" + expected = msg.delete("\r") + commands = extractor.extract_commands!(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end + + it 'does not extract commands inside a HTML tag' do + msg = msg = "Hello\r\n<div>\r\nThis is some text\r\n/close\r\n/assign @user\r\n</div>\r\n\r\nWorld" + expected = msg.delete("\r") + commands = extractor.extract_commands!(msg) + + expect(commands).to be_empty + expect(msg).to eq expected + end end end diff --git a/spec/services/slash_commands/interpret_service_spec.rb b/spec/services/slash_commands/interpret_service_spec.rb index 66ebe091893..620687e3212 100644 --- a/spec/services/slash_commands/interpret_service_spec.rb +++ b/spec/services/slash_commands/interpret_service_spec.rb @@ -27,7 +27,7 @@ describe SlashCommands::InterpretService, services: true do :done, :subscribe, :unsubscribe, - :due_date, + :due_date, :due, :clear_due_date ]) end @@ -119,10 +119,10 @@ describe SlashCommands::InterpretService, services: true do end shared_examples 'todo command' do - it 'populates todo_event: "mark" if content contains /todo' do + it 'populates todo_event: "add" if content contains /todo' do changes = service.execute(content, issuable) - expect(changes).to eq(todo_event: 'mark') + expect(changes).to eq(todo_event: 'add') end end @@ -154,7 +154,7 @@ describe SlashCommands::InterpretService, services: true do it 'populates due_date: Date.new(2016, 8, 28) if content contains /due_date 2016-08-28' do changes = service.execute(content, issuable) - expect(changes).to eq(due_date: Date.new(2016, 8, 28)) + expect(changes).to eq(due_date: defined?(expected_date) ? expected_date : Date.new(2016, 8, 28)) end end @@ -369,6 +369,12 @@ describe SlashCommands::InterpretService, services: true do let(:issuable) { issue } end + it_behaves_like 'due_date command' do + let(:content) { '/due tomorrow' } + let(:issuable) { issue } + let(:expected_date) { Date.tomorrow } + end + it_behaves_like 'empty command' do let(:content) { '/due_date foo bar' } let(:issuable) { issue } |