discourse/spec/tasks/posts_spec.rb

47 lines
1.2 KiB
Ruby
Raw Normal View History

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