fabrication 2.2.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,7 +62,7 @@ class Fabricate
62
62
  end
63
63
  end
64
64
 
65
- def self.sequence(name=Fabrication::Sequencer::DEFAULT, start=0, &block)
65
+ def self.sequence(name=Fabrication::Sequencer::DEFAULT, start=nil, &block)
66
66
  Fabrication::Sequencer.sequence(name, start, &block)
67
67
  end
68
68
  end
@@ -5,7 +5,11 @@ module Fabrication
5
5
  def configure; yield self end
6
6
 
7
7
  def reset_defaults
8
- @fabricator_path = @path_prefix = @active_support = nil
8
+ @fabricator_path =
9
+ @path_prefix =
10
+ @active_support =
11
+ @sequence_start =
12
+ nil
9
13
  end
10
14
 
11
15
  def fabricator_path
@@ -18,6 +22,9 @@ module Fabrication
18
22
  end
19
23
  alias fabricator_dir= fabricator_path=
20
24
 
25
+ attr_writer :sequence_start
26
+ def sequence_start; @sequence_start ||= 0 end
27
+
21
28
  attr_writer :path_prefix
22
29
  def path_prefix
23
30
  @path_prefix ||= defined?(Rails) ? Rails.root : "."
@@ -56,7 +56,9 @@ class Fabrication::Schematic::Definition
56
56
  Fabrication.schematics.build_stack << self
57
57
  merge(overrides, &block).instance_eval do
58
58
  generator.new(klass).build(attributes, callbacks)
59
- end.tap { Fabrication.schematics.build_stack.pop }
59
+ end
60
+ ensure
61
+ Fabrication.schematics.build_stack.pop
60
62
  end
61
63
 
62
64
  def fabricate(overrides={}, &block)
@@ -98,7 +100,6 @@ class Fabrication::Schematic::Definition
98
100
  end
99
101
 
100
102
  def method_missing(method_name, *args, &block)
101
- method_name = parse_method_name(method_name)
102
103
  params = Fabrication::Support.extract_options!(args)
103
104
  value = args.first
104
105
  block = generate_value(method_name, params) if args.empty? && !block_given?
@@ -113,21 +114,13 @@ class Fabrication::Schematic::Definition
113
114
  callbacks[:initialize_with] = block
114
115
  end
115
116
 
116
- def parse_method_name(method_name)
117
- if method_name.to_s.end_with?("!")
118
- warn("DEPRECATION WARNING: Using the \"!\" in Fabricators is no longer supported. Please remove all occurrances")
119
- method_name = method_name.to_s.chomp("!").to_sym
120
- end
121
- method_name
122
- end
123
-
124
117
  def transient(*field_names)
125
118
  field_names.each do |field_name|
126
119
  append_or_update_attribute(field_name, nil, transient: true)
127
120
  end
128
121
  end
129
122
 
130
- def sequence(name=Fabrication::Sequencer::DEFAULT, start=0, &block)
123
+ def sequence(name=Fabrication::Sequencer::DEFAULT, start=nil, &block)
131
124
  name = "#{self.klass.to_s.downcase.gsub(/::/, '_')}_#{name}"
132
125
  Fabrication::Sequencer.sequence(name, start, &block)
133
126
  end
@@ -135,13 +128,11 @@ class Fabrication::Schematic::Definition
135
128
  private
136
129
 
137
130
  def generate_value(name, params)
138
- name = name.to_s
139
- name = name.singularize if name.respond_to?(:singularize)
140
- if name != name.to_s
141
- params[:count] ||= 1 if !params[:count]
142
- Proc.new { Fabricate.build(params[:fabricator] || name.to_sym) }
131
+ if params[:count]
132
+ name = name.to_s.singularize if name.to_s.respond_to?(:singularize)
133
+ Proc.new { Fabricate.build(params[:fabricator] || name) }
143
134
  else
144
- Proc.new { Fabricate(params[:fabricator] || name.to_sym) }
135
+ Proc.new { Fabricate(params[:fabricator] || name) }
145
136
  end
146
137
  end
147
138
  end
@@ -2,8 +2,8 @@ class Fabrication::Sequencer
2
2
 
3
3
  DEFAULT = :_default
4
4
 
5
- def self.sequence(name=DEFAULT, start=0, &block)
6
- idx = sequences[name] ||= start
5
+ def self.sequence(name=DEFAULT, start=nil, &block)
6
+ idx = sequences[name] ||= start || Fabrication::Config.sequence_start
7
7
  if block_given?
8
8
  sequence_blocks[name] = block.to_proc
9
9
  else
@@ -20,4 +20,10 @@ class Fabrication::Sequencer
20
20
  def self.sequence_blocks
21
21
  @sequence_blocks ||= {}
22
22
  end
23
+
24
+ def self.reset
25
+ Fabrication::Config.sequence_start = nil
26
+ @sequences = nil
27
+ @sequence_blocks = nil
28
+ end
23
29
  end
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.2.3'
2
+ VERSION = '2.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabrication
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-23 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord