fabrication 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -169,3 +169,4 @@ To run rake successfully:
169
169
  * Christopher Hanks (chanks) - Chained callbacks
170
170
  * monsterlabs - Rails 3 Generators
171
171
  * Brandon Weiss (brandonweiss) - Sequal Model support
172
+ * Tim Pope (tpope) - Singularize generated fabricator names
@@ -28,8 +28,12 @@ class Fabrication::Schematic
28
28
  attributes.select { |a| a.name == name }.first
29
29
  end
30
30
 
31
- def delete_attribute(name)
32
- attributes.reject! { |a| a.name == name }
31
+ def append_or_update_attribute(attribute)
32
+ if index = attributes.index { |a| a.name == attribute.name }
33
+ attributes[index] = attribute
34
+ else
35
+ attributes << attribute
36
+ end
33
37
  end
34
38
 
35
39
  attr_writer :attributes
@@ -70,8 +74,7 @@ class Fabrication::Schematic
70
74
  clone.tap do |schematic|
71
75
  schematic.instance_eval(&block) if block_given?
72
76
  overrides.each do |name, value|
73
- schematic.delete_attribute(name)
74
- schematic.attributes << Fabrication::Attribute.new(name, nil, value)
77
+ schematic.append_or_update_attribute(Fabrication::Attribute.new(name, nil, value))
75
78
  end
76
79
  end
77
80
  end
@@ -86,8 +89,7 @@ class Fabrication::Schematic
86
89
  value = args.first
87
90
  end
88
91
 
89
- delete_attribute(method_name)
90
- attributes.push(Fabrication::Attribute.new(method_name, params, value))
92
+ append_or_update_attribute(Fabrication::Attribute.new(method_name, params, value))
91
93
  end
92
94
 
93
95
  def on_init(&block)
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
@@ -49,16 +49,6 @@ describe Fabrication::Schematic do
49
49
  end
50
50
  end
51
51
 
52
- describe "#delete_attribute" do
53
- it "deletes the requested attribute if it exists" do
54
- schematic.delete_attribute(:name).should_not be_nil
55
- schematic.attribute(:name).should be_nil
56
- end
57
- it "returns nil if it does not exist" do
58
- schematic.delete_attribute(:not_there).should be_nil
59
- end
60
- end
61
-
62
52
  describe "#attributes" do
63
53
  it "always returns an empty array" do
64
54
  schematic.attributes = nil
@@ -122,8 +122,7 @@ describe Fabrication do
122
122
  context 'with the generation parameter' do
123
123
 
124
124
  let(:person) do
125
- Fabricate(:person) do
126
- first_name "Paul"
125
+ Fabricate(:person, :first_name => "Paul") do
127
126
  last_name { |person| "#{person.first_name}#{person.age}" }
128
127
  age 50
129
128
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 1
9
- version: 0.9.1
8
+ - 2
9
+ version: 0.9.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Elliott
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-21 00:00:00 -05:00
17
+ date: 2010-11-24 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency