ianwhite-pickle 0.1.10 → 0.1.11

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/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.11 - 22 Feb 2009
2
+
3
+ * 2 minor enhancements
4
+ * Pickle now supports multiple machinist blueprints
5
+ * Fix confusing adapter/adaptor comment generator comment
6
+
7
+
1
8
  == 0.1.10 - 13 Feb 2009
2
9
 
3
10
  * 2 minor enhancements
data/README.rdoc CHANGED
@@ -53,6 +53,9 @@ you've written, you can just do stuff like
53
53
 
54
54
  ==== Machinst: require your blueprints and reset Shams
55
55
 
56
+ (The latest version of pickle supports {multiple blueprints}[http://github.com/notahat/machinist/commit/d6492e6927a8aa1819926e48b22377171fd20496], for
57
+ earlier versions of machinist use pickle <= 0.1.10)
58
+
56
59
  In your <tt>features/support/env.rb</tt> add the following lines at the bottom
57
60
 
58
61
  require "#{Rails.root}/spec/blueprints" # or wherever they live
@@ -36,22 +36,21 @@ module Pickle
36
36
  def self.factories
37
37
  factories = []
38
38
  model_classes.each do |klass|
39
- factories << new(klass, "make") if klass.instance_variable_get('@blueprint')
40
- # if there are make_<special> methods, add blueprints for them
41
- klass.methods.select{|m| m =~ /^make_/ && m !~ /_unsaved$/}.each do |method|
42
- factories << new(klass, method)
39
+ if blueprints = klass.instance_variable_get('@blueprints')
40
+ blueprints.keys.each {|blueprint| factories << new(klass, blueprint)}
43
41
  end
44
42
  end
45
43
  factories
46
44
  end
47
45
 
48
- def initialize(klass, method)
49
- @klass, @method = klass, method
50
- @name = (@method =~ /make_/ ? "#{@method.sub('make_','')}_" : "") + @klass.name.underscore.gsub('/','_')
46
+ def initialize(klass, blueprint)
47
+ @klass, @blueprint = klass, blueprint
48
+ @name = @klass.name.underscore.gsub('/','_')
49
+ @name = "#{@blueprint}_#{@name}" unless @blueprint == :master
51
50
  end
52
51
 
53
52
  def create(attrs = {})
54
- @klass.send(@method, attrs)
53
+ @klass.send(:make, @blueprint, attrs)
55
54
  end
56
55
  end
57
56
 
@@ -2,7 +2,7 @@ module Pickle
2
2
  module Version
3
3
  Major = 0
4
4
  Minor = 1
5
- Tiny = 10
5
+ Tiny = 11
6
6
 
7
7
  String = [Major, Minor, Tiny].join('.')
8
8
  end
@@ -4,7 +4,7 @@ require 'pickle/world'
4
4
  # Example of configuring pickle:
5
5
  #
6
6
  # Pickle.configure do |config|
7
- # config.adaptors = [:machinist]
7
+ # config.adapters = [:machinist]
8
8
  # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
9
9
  # end
10
10
  <%- end -%>
@@ -38,18 +38,22 @@ describe Pickle::Adapter do
38
38
  end
39
39
  end
40
40
 
41
- describe '::ActiveRecord' do
41
+ describe "adapters: " do
42
42
  before do
43
- # set up a fake object space
44
- @klass1 = mock('One', :name => 'One')
45
- @klass2 = mock('One::Two', :name => 'One::Two')
46
- Pickle::Adapter::ActiveRecord.stub!(:model_classes).and_return([@klass1, @klass2])
43
+ @klass1 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One')}
44
+ @klass2 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One::Two')}
45
+ @klass3 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('Three')}
47
46
  end
48
47
 
49
- describe ".factories" do
50
- it "should create one for each active record class" do
48
+ describe 'ActiveRecord' do
49
+ before do
50
+ Pickle::Adapter::ActiveRecord.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
51
+ end
52
+
53
+ it ".factories should create one for each active record class" do
51
54
  Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass1).once
52
55
  Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass2).once
56
+ Pickle::Adapter::ActiveRecord.should_receive(:new).with(@klass3).once
53
57
  Pickle::Adapter::ActiveRecord.factories
54
58
  end
55
59
 
@@ -57,100 +61,101 @@ describe Pickle::Adapter do
57
61
  before do
58
62
  @factory = Pickle::Adapter::ActiveRecord.new(@klass2)
59
63
  end
60
-
64
+
61
65
  it "should have underscored (s/_) name of Class as #name" do
62
66
  @factory.name.should == 'one_two'
63
67
  end
64
-
68
+
65
69
  it "#create(attrs) should call Class.create!(attrs)" do
66
70
  @klass2.should_receive(:create!).with({:key => "val"})
67
71
  @factory.create(:key => "val")
68
72
  end
69
73
  end
70
74
  end
71
- end
72
75
 
73
- describe '::FactoryGirl' do
74
- before do
75
- # set up a fake object space
76
- @factory1 = mock('factory1', :factory_name => :one, :build_class => (@class1 = mock('Class1')))
77
- @factory2 = mock('factory2', :factory_name => :two, :build_class => (@class2 = mock('Class2')))
78
- Factory.stub!(:factories).and_return(:factory1 => @factory1, :factory2 => @factory2)
79
- end
76
+ describe 'FactoryGirl' do
77
+ before do
78
+ Pickle::Adapter::FactoryGirl.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
79
+ @orig_factories, Factory.factories = Factory.factories, {}
80
+
81
+ Factory.define(:one, :class => @klass1) {}
82
+ Factory.define(:two, :class => @klass2) {}
83
+ @factory1 = Factory.factories[:one]
84
+ @factory2 = Factory.factories[:two]
85
+ end
86
+
87
+ after do
88
+ Factory.factories = @orig_factories
89
+ end
80
90
 
81
- describe ".factories" do
82
- it "should create one for each factory" do
91
+ it ".factories should create one for each factory" do
83
92
  Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory1).once
84
93
  Pickle::Adapter::FactoryGirl.should_receive(:new).with(@factory2).once
85
94
  Pickle::Adapter::FactoryGirl.factories
86
95
  end
87
-
96
+
88
97
  describe ".new(factory)" do
89
98
  before do
90
99
  @factory = Pickle::Adapter::FactoryGirl.new(@factory1)
91
100
  end
92
-
101
+
93
102
  it "should have name of factory_name" do
94
103
  @factory.name.should == 'one'
95
104
  end
96
-
105
+
97
106
  it "should have klass of build_class" do
98
- @factory.klass.should == @class1
107
+ @factory.klass.should == @klass1
99
108
  end
100
-
109
+
101
110
  it "#create(attrs) should call Factory(<:key>, attrs)" do
102
111
  Factory.should_receive(:create).with("one", {:key => "val"})
103
112
  @factory.create(:key => "val")
104
113
  end
105
114
  end
106
115
  end
107
- end
108
116
 
109
- describe '::Machinist' do
110
- before do
111
- # set up a fake object space
112
- @klass1 = mock('One', :name => 'One', :make => true, :make_unsaved => true)
113
- @klass1.instance_variable_set('@blueprint', true)
114
- @klass2 = mock('Two', :name => 'Two')
115
- @klass3 = mock('Two::Sub', :name => 'Two::Sub', :make_special => true, :make => true, :make_unsaved => true)
116
- @klass3.instance_variable_set('@blueprint', true)
117
- Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
118
- end
119
-
120
- describe ".factories" do
121
- it "should create one for each machinist make method, except make_unsaved" do
122
- Pickle::Adapter::Machinist.should_receive(:new).with(@klass1, 'make').once
123
- Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, 'make').once
124
- Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, 'make_special').once
125
- Pickle::Adapter::Machinist.factories
117
+ describe 'Machinist' do
118
+ before do
119
+ Pickle::Adapter::Machinist.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
120
+
121
+ @klass1.blueprint {}
122
+ @klass3.blueprint {}
123
+ @klass3.blueprint(:special) {}
126
124
  end
127
125
 
128
- describe ".new(Class, 'make')" do
126
+ it ".factories should create one for each master blueprint, and special case" do
127
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass1, :master).once
128
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :master).once
129
+ Pickle::Adapter::Machinist.should_receive(:new).with(@klass3, :special).once
130
+ Pickle::Adapter::Machinist.factories
131
+ end
132
+
133
+ describe ".new(Class, :master)" do
129
134
  before do
130
- @factory = Pickle::Adapter::Machinist.new(@klass1, 'make')
135
+ @factory = Pickle::Adapter::Machinist.new(@klass1, :master)
131
136
  end
132
137
 
133
138
  it "should have underscored (s/_) name of Class as #name" do
134
139
  @factory.name.should == 'one'
135
140
  end
136
141
 
137
- it "#create(attrs) should call Class.make(attrs)" do
138
- @klass1.should_receive(:make).with({:key => "val"})
142
+ it "#create(attrs) should call Class.make(:master, attrs)" do
143
+ @klass1.should_receive(:make).with(:master, {:key => "val"})
139
144
  @factory.create(:key => "val")
140
145
  end
141
146
  end
142
147
 
143
- describe ".new(Class, 'make_special')" do
148
+ describe ".new(Class, :special)" do
144
149
  before do
145
- @factory = Pickle::Adapter::Machinist.new(@klass3, 'make_special')
150
+ @factory = Pickle::Adapter::Machinist.new(@klass3, :special)
146
151
  end
147
152
 
148
153
  it "should have 'special_<Class name>' as #name" do
149
- @factory.name.should == 'special_two_sub'
154
+ @factory.name.should == 'special_three'
150
155
  end
151
156
 
152
- it "#create(attrs) should call Class.make_special(attrs)" do
153
- @klass3.should_receive(:make_special).with({:key => "val"})
157
+ it "#create(attrs) should call Class.make(:special, attrs)" do
158
+ @klass3.should_receive(:make).with(:special, {:key => "val"})
154
159
  @factory.create(:key => "val")
155
160
  end
156
161
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ianwhite-pickle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian White
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-13 00:00:00 -08:00
12
+ date: 2009-02-22 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15