rahoulb-object-factory 0.1.1 → 0.1.2

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.
data/README.rdoc CHANGED
@@ -10,14 +10,14 @@ If you don't use the a_saved method then it should work with any type of model,
10
10
 
11
11
  == Usage
12
12
 
13
- See the wiki page at http://github.com/rahoulb/object-factory/wikis/home for the latest docs.
13
+ See the wiki page at http://github.com/rahoulb/object-factory/wikis/home for the latest docs.
14
14
 
15
15
  However, it works something like this:
16
16
 
17
- Object.factory.when_creating_a Person, :auto_generate => :employee_code
17
+ when_creating_a Person, :auto_generate => :employee_code
18
18
 
19
- @person = a Person, :first_name => 'John', :last_name => 'Smith', :employee_code => '12345'
20
- puts @person.employee_code # will show 12345
19
+ @person = a Person, :first_name => 'John', :last_name => 'Smith'
20
+ puts @person.employee_code # will show a unique auto-generated value
21
21
 
22
22
  And your options are:
23
23
 
@@ -27,6 +27,12 @@ And your options are:
27
27
  * :set => { :field3 => 'value3', :field4 => 'value4' }: sets the given fields to the supplied static values
28
28
  * :generate => { :field5 => lambda { Date.today } }: sets the given fields to the supplied dynamic values
29
29
 
30
+ == Rails
31
+
32
+ To use this with rails, stick the following in your +environment.rb+:
33
+
34
+ config.gem "rahoulb-object-factory", :lib => "object_factory", :source => "http://gems.github.com"
35
+
30
36
  == Released under the MIT Licence
31
37
 
32
38
  Copyright (c) 2008 Brightbox Systems Ltd
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('object-factory', '0.1.1') do | config |
5
+ Echoe.new('object-factory', '0.1.2') do | config |
6
6
  config.description = 'A simple object factory to help you build valid objects in your tests'
7
7
  config.url = 'http://github.com/rahoub/object-factory'
8
8
  config.author = 'Brightbox Systems Ltd'
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # placeholder to make this a rails plugin
@@ -4,7 +4,7 @@ require 'rujitsu'
4
4
  class Object
5
5
  # return an instance of an Object::Factory
6
6
  def self.factory
7
- @@object_factory ||= Factory.new
7
+ THE_OBJECT_FACTORY_INSTANCE
8
8
  end
9
9
 
10
10
  # Factory allows test suites to build new instances of objects, specifying some simple constraints on certain fields
@@ -86,6 +86,16 @@ class Object
86
86
  #�Error raised when create_and_save_a cannot save the object
87
87
  class CannotSaveError < RuntimeError; end
88
88
 
89
+ # print the rules for a given class
90
+ def print_configuration_for klass
91
+ fields_and_generators = @generators[symbol_for(klass)]
92
+ unless fields_and_generators.nil?
93
+ fields_and_generators.each do | field_name, generator |
94
+ puts "#{field_name} uses a lambda"
95
+ end
96
+ end
97
+ end
98
+
89
99
  private
90
100
 
91
101
  def symbol_for object
@@ -149,6 +159,7 @@ class Object
149
159
  end
150
160
  end
151
161
  end
162
+
152
163
  end
153
164
 
154
165
  # Short-cut method for Object::Factory#create_a
@@ -172,3 +183,5 @@ def when_creating_a klass, options = {}
172
183
  end
173
184
 
174
185
  alias when_creating_an when_creating_a
186
+
187
+ THE_OBJECT_FACTORY_INSTANCE = Object::Factory.new
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{object-factory}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brightbox Systems Ltd"]
9
- s.date = %q{2008-11-24}
9
+ s.date = %q{2008-11-28}
10
10
  s.description = %q{A simple object factory to help you build valid objects in your tests}
11
11
  s.email = %q{hello@brightbox.co.uk}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/object_factory.rb", "README.rdoc", "tasks/rspec.rake"]
13
- s.files = ["CHANGELOG", "lib/object_factory.rb", "Manifest", "object-factory.gemspec", "Rakefile", "README.rdoc", "spec/object_spec.rb", "spec/spec.opts", "tasks/rspec.rake"]
13
+ s.files = ["CHANGELOG", "init.rb", "lib/object_factory.rb", "Manifest", "rahoulb-object-factory.gemspec", "Rakefile", "README.rdoc", "spec/object_spec.rb", "spec/spec.opts", "tasks/rspec.rake", "object-factory.gemspec"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/rahoub/object-factory}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Object-factory", "--main", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rahoulb-object-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brightbox Systems Ltd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-24 00:00:00 -08:00
12
+ date: 2008-11-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,14 +34,16 @@ extra_rdoc_files:
34
34
  - tasks/rspec.rake
35
35
  files:
36
36
  - CHANGELOG
37
+ - init.rb
37
38
  - lib/object_factory.rb
38
39
  - Manifest
39
- - object-factory.gemspec
40
+ - rahoulb-object-factory.gemspec
40
41
  - Rakefile
41
42
  - README.rdoc
42
43
  - spec/object_spec.rb
43
44
  - spec/spec.opts
44
45
  - tasks/rspec.rake
46
+ - object-factory.gemspec
45
47
  has_rdoc: true
46
48
  homepage: http://github.com/rahoub/object-factory
47
49
  post_install_message: