Skip to content

Instantly share code, notes, and snippets.

@onesneakymofo
Last active June 29, 2017 19:37
Show Gist options
  • Save onesneakymofo/e4632aab6e178fec18b804b4a3accf56 to your computer and use it in GitHub Desktop.
Save onesneakymofo/e4632aab6e178fec18b804b4a3accf56 to your computer and use it in GitHub Desktop.
Testing Rake::Task with multiple arguments in minitest
require 'test_helper'
require 'rake'
class TransferDataTest < ActiveSupport::TestCase
def setup
Rails.application.load_tasks if Rake::Task.tasks.empty?
Rake::Task['proctoru:db:transfer_data'].reenable
end
def test_transfer_articles
args = set_args({ type: "articles", batch: 100000 })
article = articles(:one)
assert article.author_id_new.blank?
Rake::Task['proctoru:db:transfer_data'].execute(args)
article.reload
assert article.author_id_new.present?
assert article.author_id_new == article.article_id.to_i
end
def test_transfer_authors
args = set_args({ type: "articles", batch: 100000 })
authors = authors(:one)
assert authors.group_id_new.blank?
Rake::Task['proctoru:db:transfer_data'].execute(args)
authors.reload
assert authors.group_id_new.present?
assert authors.group_id_new == authors.group_id.to_i
end
def set_args(args_hash)
Rake::TaskArguments.new(args_hash.keys, args_hash.values)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment