2017-01-27 12:42:39 -06:00
|
|
|
require 'rails_helper'
|
2017-10-03 19:47:53 -05:00
|
|
|
require 'highline/import'
|
|
|
|
require 'highline/simulate'
|
2017-01-27 12:42:39 -06:00
|
|
|
|
|
|
|
RSpec.describe "Post rake tasks" do
|
|
|
|
before do
|
2017-10-03 19:47:53 -05:00
|
|
|
Rake::Task.clear
|
2017-01-27 12:42:39 -06:00
|
|
|
Discourse::Application.load_tasks
|
2017-01-27 23:34:47 -06:00
|
|
|
IO.any_instance.stubs(:puts)
|
2017-01-27 12:42:39 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'remap' do
|
2017-10-03 19:47:53 -05:00
|
|
|
let!(:tricky_post) { Fabricate(:post, raw: 'Today ^Today') }
|
|
|
|
|
2017-01-27 12:42:39 -06:00
|
|
|
it 'should remap posts' do
|
|
|
|
post = Fabricate(:post, raw: "The quick brown fox jumps over the lazy dog")
|
|
|
|
|
2017-10-03 19:47:53 -05:00
|
|
|
HighLine::Simulate.with('y') do
|
|
|
|
Rake::Task['posts:remap'].invoke("brown", "red")
|
|
|
|
end
|
|
|
|
|
2017-01-27 12:42:39 -06:00
|
|
|
post.reload
|
|
|
|
expect(post.raw).to eq('The quick red fox jumps over the lazy dog')
|
|
|
|
end
|
2017-10-03 19:47:53 -05:00
|
|
|
|
|
|
|
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
|
2017-01-27 12:42:39 -06:00
|
|
|
end
|
|
|
|
end
|