Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

whiplashmerch/slicer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Slicer Export related records from one environment and import into another.

Add to your gemfile:

gem 'slicer'

bundle install

Setting up export via Capistrano

  1. Create rake task
#/lib/tasks/slicer.rake

namespace :slicer do
	desc "Export supporting data for an ActiveRecord object"
	task :export => :environment do
		abort "Please specify a MODEL, e.g., MODEL=Order" unless ENV['MODEL']
		abort "Pleaes specify an ID, e.g., ID=1234" unless ENV['ID']
		abort "Unable to locate record" unless obj = ENV['MODEL'].constantize.find(ENV['ID'])
		Slicer.export(obj)
	end
end
  1. Wrap your rake task in a cap task
#/lib/capistrano/tasks/slicer.rake

namespace :slicer do
	task :export do
	  on roles(:all) do
	    within release_path do
	      with rails_env: fetch(:rails_env) do
	        execute :rake, "slicer:export MODEL=#{ENV['MODEL']} ID=#{ENV['ID']}"
	        download! "#{release_path}/test/data/slicer/#{ENV['MODEL']}#{ENV['ID']}.yml", "test/data/slicer"
	      end
	    end 
	  end
	end
end
  1. You can now create an export in a remote environment and download it one step:
$ cap ROLE slicer:export MODEL=Order ID=1234

Importing

Exports can then be used in tests:

require 'test_helper'
class OrdersControllerTest < ActionController::TestCase
	test "should get order 1234" do
	  assert Slicer.import('Order1234')
	  get :show, :id => 1234
	  assert_response :success
	end
end

Console

Exporting can be done directly in the console. This will execute against the console environment's database:

Slicer.export( Order.find(1234) )
=> 'Export saved to /your/rails/root/test/data/slicer/Order1234.yml'

Imports can be made into your console environment's database

Slicer.import( 'Order1234' )
=> true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages