2017-01-28 02:42:39 +08:00
|
|
|
require 'rails_helper'
|
2017-10-04 08:47:53 +08:00
|
|
|
require 'highline/import'
|
|
|
|
require 'highline/simulate'
|
2017-01-28 02:42:39 +08:00
|
|
|
|
|
|
|
RSpec.describe "Post rake tasks" do
|
2017-10-25 02:49:00 +08:00
|
|
|
let!(:post) { Fabricate(:post, raw: 'The quick brown fox jumps over the lazy dog') }
|
|
|
|
let!(:tricky_post) { Fabricate(:post, raw: 'Today ^Today') }
|
|
|
|
|
2017-01-28 02:42:39 +08:00
|
|
|
before do
|
2017-10-04 08:47:53 +08:00
|
|
|
Rake::Task.clear
|
2017-01-28 02:42:39 +08:00
|
|
|
Discourse::Application.load_tasks
|
2017-01-28 13:34:47 +08:00
|
|
|
IO.any_instance.stubs(:puts)
|
2017-01-28 02:42:39 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'remap' do
|
|
|
|
it 'should remap posts' do
|
2017-10-04 08:47:53 +08:00
|
|
|
HighLine::Simulate.with('y') do
|
|
|
|
Rake::Task['posts:remap'].invoke("brown", "red")
|
|
|
|
end
|
|
|
|
|
2017-01-28 02:42:39 +08:00
|
|
|
post.reload
|
|
|
|
expect(post.raw).to eq('The quick red fox jumps over the lazy dog')
|
|
|
|
end
|
2017-10-04 08:47:53 +08: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-28 02:42:39 +08:00
|
|
|
end
|
2017-10-25 02:49:00 +08:00
|
|
|
|
|
|
|
describe 'rebake_match' do
|
|
|
|
it 'rebakes matched posts' do
|
|
|
|
post.update_attributes(cooked: '')
|
|
|
|
|
|
|
|
HighLine::Simulate.with('y') do
|
|
|
|
Rake::Task['posts:rebake_match'].invoke('brown')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(post.reload.cooked).to eq('<p>The quick brown fox jumps over the lazy dog</p>')
|
|
|
|
end
|
|
|
|
end
|
2017-01-28 02:42:39 +08:00
|
|
|
end
|