Skip to content

Instantly share code, notes, and snippets.

@nickel
Created December 31, 2008 09:19
Show Gist options
  • Save nickel/41934 to your computer and use it in GitHub Desktop.
Save nickel/41934 to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'active_resource/http_mock'
class Test::Unit::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
def self.all_fixtures
fixtures :all
remote_fixtures
end
def self.get_xml(model_name, name)
path = File.join(RAILS_ROOT, "test", "remote_fixtures",
model_name.to_s, "#{name}.xml")
return nil unless File.exists?(path)
File.read path
end
def self.remote_fixtures
fixtures_files = {:companies => ["flowers", "bitrock"],
:users => ["nickel", "aaron"]}
fixtures_files.each do |models, names|
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/#{models.to_s}/1.xml", {}, get_xml(models, names.first)
mock.get "/#{models.to_s}/2.xml", {}, get_xml(models, names.last)
mock.put "/#{models.to_s}/1.xml", {}, nil, 204
mock.delete "/#{models.to_s}/1.xml", {}, nil, 200
mock.get "/#{models.to_s}/99.xml", {}, nil, 404
end
end
end
def companies(name)
case name
when :flowers
Company.find(1)
when :bitrock
Company.find(2)
else
nil
end
end
def users(name)
case name
when :nickel
User.find(1)
when :aaron
User.find(2)
else
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment