From 82c18f6ca32718a481b84dcd4438264956bb499b Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Tue, 24 Oct 2017 14:49:00 -0400 Subject: [PATCH] fix: undefined variable in `post:rebake_match` --- lib/tasks/posts.rake | 4 +++- spec/tasks/posts_spec.rb | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 6c13d53ae4a..144a92e8656 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -58,10 +58,12 @@ task 'posts:rebake_match', [:pattern, :type, :delay] => [:environment] do |_, ar exit 1 end + search = Post.raw_match(pattern, type) + rebaked = 0 total = search.count - Post.raw_match(pattern, type).find_each do |post| + search.find_each do |post| rebake_post(post) print_status(rebaked += 1, total) sleep(delay) if delay diff --git a/spec/tasks/posts_spec.rb b/spec/tasks/posts_spec.rb index 7f3e307f9e1..acaf19c5dc8 100644 --- a/spec/tasks/posts_spec.rb +++ b/spec/tasks/posts_spec.rb @@ -3,6 +3,9 @@ require 'highline/import' require 'highline/simulate' RSpec.describe "Post rake tasks" do + let!(:post) { Fabricate(:post, raw: 'The quick brown fox jumps over the lazy dog') } + let!(:tricky_post) { Fabricate(:post, raw: 'Today ^Today') } + before do Rake::Task.clear Discourse::Application.load_tasks @@ -10,11 +13,7 @@ RSpec.describe "Post rake tasks" do 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") - HighLine::Simulate.with('y') do Rake::Task['posts:remap'].invoke("brown", "red") end @@ -43,4 +42,16 @@ RSpec.describe "Post rake tasks" do end end end + + 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('

The quick brown fox jumps over the lazy dog

') + end + end end