fabrication 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -8,7 +8,7 @@ Currently supported object types are...
8
8
  * ActiveRecord objects
9
9
  * Mongoid Documents
10
10
 
11
- By default it will lazily generate active record associations. So if you have a has_many :widgets defined, it will not actually generate the widgets until the association is accessed. You can override this by passing :force => true when defining the field in the Fabricator.
11
+ By default it will lazily generate active record associations. So if you have a has_many :widgets defined, it will not actually generate the widgets until the association is accessed. You can override this by appending "!" to the name of the parameter when defining the field in the Fabricator.
12
12
 
13
13
  ### Installation ###
14
14
 
@@ -33,7 +33,7 @@ Define your fabricators.
33
33
  Fabricator(:company) do
34
34
  name "Fun Factory"
35
35
  employees(:count => 20) { |company, i| Fabricate(:drone, :company => company, :name => "Drone #{i}") }
36
- location(:force => true) { Fabricate(:location) }
36
+ location! { Fabricate(:location) }
37
37
  after_create { |company| company.update_attribute(:ceo, Fabricate(:drone, :name => 'Lead Drone') }
38
38
  end
39
39
 
@@ -41,7 +41,7 @@ Breaking down the above, we are defining a "company" fabricator, which will gene
41
41
 
42
42
  * The object has a name field, which is statically filled with "Fun Factory".
43
43
  * It has a has_many association to employees and will generate an array of 20 records as indicated by the :count => 20. The block is passed the company object being fabricated and index of the array being created.
44
- * It has a belongs_to association to location and this will be generated immediately with the company object. This is because of the :force => true parameter being passed in.
44
+ * It has a belongs_to association to location and this will be generated immediately with the company object. This is because of the "!" after the association name.
45
45
  * After the object is created, it will update the "ceo" association with a new "drone" record.
46
46
 
47
47
  Alternatively, you can Fabricate(:company) without first defining the Fabricator. Doing so will create an empty Fabricator called ":company" and prevent you from defining the Fabricator explicitly later.
@@ -67,7 +67,7 @@ That will return an instance of the LLC using the fields defined in the Fabricat
67
67
  If you need to do something more complex, you can also pass a block to Fabricate. You can use all the features available to you when defining Fabricators, but they only apply to the object generated by this Fabricate call.
68
68
 
69
69
  llc = Fabricate(:llc, :name => "Awesome, Inc.") do
70
- location(:force => true, :count => 2) { Faker::Address.city }
70
+ location!(:count => 2) { Faker::Address.city }
71
71
  end
72
72
 
73
73
  ### Contributing ###
@@ -34,6 +34,7 @@ class Fabrication::Schematic
34
34
  end
35
35
 
36
36
  def method_missing(method_name, *args, &block)
37
+ method_name = parse_method_name(method_name, args)
37
38
  if (attr = attribute(method_name)).present?
38
39
  if block_given?
39
40
  attr.params = args.first
@@ -51,6 +52,15 @@ class Fabrication::Schematic
51
52
  end
52
53
  end
53
54
 
55
+ def parse_method_name(method_name, args)
56
+ if method_name.to_s.end_with?("!")
57
+ method_name = method_name.to_s.chomp("!").to_sym
58
+ args[0] ||= {}
59
+ args[0][:force] = true
60
+ end
61
+ method_name
62
+ end
63
+
54
64
  class Attribute
55
65
  attr_accessor :name, :params, :value
56
66
 
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -117,7 +117,7 @@ describe Fabrication do
117
117
  before(:all) do
118
118
  Fabricator(:company) do
119
119
  name { Faker::Company.name }
120
- divisions(:force => true, :count => 4) { Fabricate(:division) }
120
+ divisions!(:count => 4) { Fabricate(:division) }
121
121
  after_create { |o| o.update_attribute(:city, "Jacksonville Beach") }
122
122
  end
123
123
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrication
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Elliott
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-20 00:00:00 -04:00
18
+ date: 2010-07-23 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -83,9 +83,25 @@ dependencies:
83
83
  type: :development
84
84
  version_requirements: *id004
85
85
  - !ruby/object:Gem::Dependency
86
- name: mongoid
86
+ name: bson_ext
87
87
  prerelease: false
88
88
  requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 21
94
+ segments:
95
+ - 1
96
+ - 0
97
+ - 1
98
+ version: 1.0.1
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: mongoid
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
107
  - - ">="
@@ -97,7 +113,7 @@ dependencies:
97
113
  - 1
98
114
  version: 1.9.1
99
115
  type: :development
100
- version_requirements: *id005
116
+ version_requirements: *id006
101
117
  description: Fabrication is an object generation framework for ActiveRecord and Mongoid. It has a flexible syntax and lazily generates ActiveRecord associations!
102
118
  email:
103
119
  - paul@hashrocket.com