mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:31:10 +08:00
FEATURE: support regex in rake post:remap (#5201)
This commit is contained in:
@ -1,18 +1,46 @@
|
||||
require 'rails_helper'
|
||||
require 'highline/import'
|
||||
require 'highline/simulate'
|
||||
|
||||
RSpec.describe "Post rake tasks" do
|
||||
before do
|
||||
Rake::Task.clear
|
||||
Discourse::Application.load_tasks
|
||||
IO.any_instance.stubs(:puts)
|
||||
end
|
||||
|
||||
describe 'remap' do
|
||||
let!(:tricky_post) { Fabricate(:post, raw: 'Today ^Today') }
|
||||
|
||||
it 'should remap posts' do
|
||||
post = Fabricate(:post, raw: "The quick brown fox jumps over the lazy dog")
|
||||
|
||||
Rake::Task['posts:remap'].invoke("brown", "red")
|
||||
HighLine::Simulate.with('y') do
|
||||
Rake::Task['posts:remap'].invoke("brown", "red")
|
||||
end
|
||||
|
||||
post.reload
|
||||
expect(post.raw).to eq('The quick red fox jumps over the lazy dog')
|
||||
end
|
||||
|
||||
context 'when type == string' do
|
||||
it 'remaps input as string' do
|
||||
HighLine::Simulate.with('y') do
|
||||
Rake::Task['posts:remap'].invoke('^Today', 'Yesterday', 'string')
|
||||
end
|
||||
|
||||
expect(tricky_post.reload.raw).to eq('Today Yesterday')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when type == regex' do
|
||||
it 'remaps input as regex' do
|
||||
HighLine::Simulate.with('y') do
|
||||
Rake::Task['posts:remap'].invoke('^Today', 'Yesterday', 'regex')
|
||||
end
|
||||
|
||||
expect(tricky_post.reload.raw).to eq('Yesterday ^Today')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user