gnoso-fafactory 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ if Rails.env == "test"
2
+ class FafactoriesController < ApplicationController
3
+
4
+ # POST a new instance of the type of model requested
5
+ #
6
+ # ==== Parameters
7
+ # model<String>:: The model to create a new instance of
8
+ # data<Hash>:: A hash of the attributes for the model
9
+ def create_instance
10
+ obj = Module.const_get(params["hash"]["model"].to_sym).new
11
+
12
+ params["hash"]["data"].each do |key, value|
13
+ obj.send(:"#{key}=", value)
14
+ end
15
+
16
+ obj.save!
17
+
18
+ respond_to do |format|
19
+ format.xml do
20
+ render :xml => obj, :status => :created, :location => obj
21
+ end
22
+ end
23
+ end
24
+
25
+ # Purges the test database
26
+ def purge
27
+
28
+ # We have to disconnect the connection for active record because the
29
+ # connection doesn't make it through the fork, and the rake task will
30
+ # do it's own database load, etc anyway
31
+ dbconfig = ActiveRecord::Base.remove_connection
32
+ pid = fork do
33
+
34
+ require 'rake'
35
+ require 'rake/testtask'
36
+ require 'rake/rdoctask'
37
+
38
+ require 'tasks/rails'
39
+
40
+
41
+ Rake::Task['db:test:load'].invoke
42
+ end
43
+ ActiveRecord::Base.establish_connection(dbconfig)
44
+ Process.wait(pid)
45
+
46
+ respond_to do |format|
47
+ format.xml { head :ok }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ # Starts the rails apps configured in config/fafactory.yml in test mode on
2
+ # the given ports
3
+
4
+ def log(msg)
5
+ puts "* [Fafactory] #{msg}"
6
+ end
7
+
8
+ config = YAML.load_file('config/fafactory.yml')
9
+
10
+ config.each do |service, settings|
11
+ exec_args = []
12
+ if settings["port"]
13
+ exec_args << "--port=#{settings["port"]}"
14
+ end
15
+ exec_args << "--environment=test"
16
+
17
+ log "Starting application at #{settings["path"]}..."
18
+ fork { exec "#{settings["path"]}/script/server", *exec_args }
19
+ end
20
+
21
+ Signal.trap("TERM") do
22
+ log "Terminating..."
23
+ exit
24
+ end
25
+ Signal.trap("INT") do
26
+ log "Terminating..."
27
+ exit
28
+ end
29
+
30
+ begin
31
+ Process.waitall
32
+ rescue
33
+ end
34
+
35
+ log "All apps exited."
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ if Rails.env == "test"
3
+ map.resources :fafactories, :only => [:none],
4
+ :collection => { :create_instance => :post, :purge => :delete }
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_resource'
2
+
3
+ class Fafactory < ActiveResource::Base
4
+
5
+ # Creates a new instance of a remote model using the data provided.
6
+ def self.create_instance(service, model, data)
7
+ Fafactory.configure_site(service)
8
+ result = Fafactory.post :create_instance, nil,
9
+ { :model => model, :data => data }.to_xml
10
+
11
+ return Hash.from_xml(result.body)
12
+ end
13
+
14
+ def self.purge(*services)
15
+ services.each do |service|
16
+ Fafactory.configure_site(service)
17
+ Fafactory.delete(:purge)
18
+ end
19
+
20
+ nil
21
+ end
22
+
23
+ private
24
+ def self.configure_site(service)
25
+ @@fafactory_config ||= YAML.load_file('config/fafactory.yml')
26
+
27
+ self.site = "http://0.0.0.0:#{@@fafactory_config[service]["port"]}"
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gnoso-fafactory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gnoso, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activeresource
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ version:
25
+ description: Fafactory (originally Far Away Factory) is a tool for remotely creating instances of ActiveRecord models within a service. This is useful when doing integration tests of services, because it allows you to set up the environment within the remote service from your test, rather than trying to keep an instance of the service in pristine shape.
26
+ email: alan@gnoso.com
27
+ executables:
28
+ - fafactory
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/fafactory.rb
35
+ - app/controllers/fafactories_controller.rb
36
+ - bin/fafactory
37
+ - config/routes.rb
38
+ has_rdoc: true
39
+ homepage: http://www.gnoso.com
40
+ licenses:
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Framework for creating objects in remote services.
65
+ test_files: []
66
+