pickle-has_many_support 0.3.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ doc/*
3
3
  .yardoc
4
4
  pickle-email*
5
5
  cucumber_test_app
6
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "yard"
4
+ gem "rake"
5
+ gem "cucumber", ">=0.8"
6
+ gem "rspec"
7
+
8
+ group :test do
9
+ gem "rspec-rails"
10
+ gem "rails", "~>2.3"
11
+ gem "cucumber-rails", ">=0.3.2"
12
+ gem "factory_girl"
13
+ gem "machinist"
14
+ gem "jeweler"
15
+ gem "rcov"
16
+ gem "database_cleaner"
17
+ gem "capybara"
18
+ gem "webrat"
19
+ gem "sqlite3-ruby"
20
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,98 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (2.3.8)
5
+ actionpack (= 2.3.8)
6
+ actionpack (2.3.8)
7
+ activesupport (= 2.3.8)
8
+ rack (~> 1.1.0)
9
+ activerecord (2.3.8)
10
+ activesupport (= 2.3.8)
11
+ activeresource (2.3.8)
12
+ activesupport (= 2.3.8)
13
+ activesupport (2.3.8)
14
+ builder (2.1.2)
15
+ capybara (0.3.9)
16
+ culerity (>= 0.2.4)
17
+ mime-types (>= 1.16)
18
+ nokogiri (>= 1.3.3)
19
+ rack (>= 1.0.0)
20
+ rack-test (>= 0.5.4)
21
+ selenium-webdriver (>= 0.0.3)
22
+ cucumber (0.8.5)
23
+ builder (~> 2.1.2)
24
+ diff-lcs (~> 1.1.2)
25
+ gherkin (~> 2.1.4)
26
+ json_pure (~> 1.4.3)
27
+ term-ansicolor (~> 1.0.4)
28
+ cucumber-rails (0.3.2)
29
+ cucumber (>= 0.8.0)
30
+ culerity (0.2.10)
31
+ database_cleaner (0.5.2)
32
+ diff-lcs (1.1.2)
33
+ factory_girl (1.3.2)
34
+ ffi (0.6.3)
35
+ rake (>= 0.8.7)
36
+ gemcutter (0.6.1)
37
+ gherkin (2.1.5)
38
+ trollop (~> 1.16.2)
39
+ git (1.2.5)
40
+ jeweler (1.4.0)
41
+ gemcutter (>= 0.1.0)
42
+ git (>= 1.2.5)
43
+ rubyforge (>= 2.0.0)
44
+ json_pure (1.4.6)
45
+ machinist (1.0.6)
46
+ mime-types (1.16)
47
+ nokogiri (1.4.3.1)
48
+ rack (1.1.0)
49
+ rack-test (0.5.4)
50
+ rack (>= 1.0)
51
+ rails (2.3.8)
52
+ actionmailer (= 2.3.8)
53
+ actionpack (= 2.3.8)
54
+ activerecord (= 2.3.8)
55
+ activeresource (= 2.3.8)
56
+ activesupport (= 2.3.8)
57
+ rake (>= 0.8.3)
58
+ rake (0.8.7)
59
+ rcov (0.9.8)
60
+ rspec (1.3.0)
61
+ rspec-rails (1.3.2)
62
+ rack (>= 1.0.0)
63
+ rspec (>= 1.3.0)
64
+ rubyforge (2.0.4)
65
+ json_pure (>= 1.1.7)
66
+ rubyzip (0.9.4)
67
+ selenium-webdriver (0.0.27)
68
+ ffi (>= 0.6.1)
69
+ json_pure
70
+ rubyzip
71
+ sqlite3-ruby (1.3.1)
72
+ term-ansicolor (1.0.5)
73
+ trollop (1.16.2)
74
+ webrat (0.7.1)
75
+ nokogiri (>= 1.2.0)
76
+ rack (>= 1.0)
77
+ rack-test (>= 0.5.3)
78
+ yard (0.5.8)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ capybara
85
+ cucumber (>= 0.8)
86
+ cucumber-rails (>= 0.3.2)
87
+ database_cleaner
88
+ factory_girl
89
+ jeweler
90
+ machinist
91
+ rails (~> 2.3)
92
+ rake
93
+ rcov
94
+ rspec
95
+ rspec-rails
96
+ sqlite3-ruby
97
+ webrat
98
+ yard
data/History.txt CHANGED
@@ -1,3 +1,81 @@
1
+ == 0.4.2
2
+
3
+ * 1 bugfix
4
+ * Use mongoid finder syntax, which requires a :conditions key [Marc Lee]
5
+
6
+
7
+ == 0.4.1
8
+ Docfix
9
+
10
+ * 1 improvement
11
+ * documentation fixes, and example of writing your own pickle steps
12
+
13
+
14
+ == 0.4.0
15
+ Mongoid adapter, fallback ORM adapter for those not using machinist or active_record, bugfixes
16
+
17
+ * 2 major improvements
18
+ * adapter for Mongoid [Sebastian Zuchmanski]
19
+ * replace ActiveRecord 'factory' adapter with Orm adapter.
20
+
21
+ If you don't have machinist or factory_girl, the Orm factory adapter will fallback to your Orm to create classes.
22
+
23
+ BC: if you have a line like this:
24
+ Pickle.configure do |config|
25
+ config.adapters = [:active_record]
26
+ end
27
+
28
+ You need to replace it with :orm
29
+ Pickle.configure do |config|
30
+ config.adapters = [:orm]
31
+ end
32
+
33
+ * 1 minor improvement
34
+ * Pickle::Session::ModelNotKnownError is raised instead of a generic RuntimeError
35
+
36
+ * 1 bugfix
37
+ * references to unknown models in fields now raise ModelNotKnownError instead of silently assigning nil
38
+
39
+
40
+ == 0.3.5
41
+
42
+ * 3 improvements
43
+ * bundler is used for setting up development dependencies
44
+ * gemspec specifies dependencies for using pickle
45
+ * Machinist 2 compatability [giddie]
46
+
47
+ * 1 bugfix
48
+ * find_models now works with a factory name with spaces in it [#27]
49
+
50
+
51
+ == 0.3.4
52
+
53
+ * 2 minor improvements
54
+ * Fix problem where email body is not a string, but is string like [#26] [Tom Meier]
55
+ * Minor code refactoring
56
+
57
+
58
+ == 0.3.3
59
+
60
+ * 1 minor improvement
61
+ * Pickle respects the default build strategy for factory girl. [Sean Hussey]
62
+
63
+
64
+ == 0.3.2
65
+
66
+ * 3 minor improvements
67
+ * Document how to use machinist named blueprints [Christopher Darroch]
68
+ * Email links now visit the url, rather than just the path, this allows for features that
69
+ make use of the domain to function correctly
70
+ * Deprecation warnings for Rails 3 removed [Brian Rose & Kevin Olsen]
71
+
72
+
73
+ == 0.3.1
74
+
75
+ * 1 major improvement
76
+ * Rails 3 support for generators [H.J. Blok, szimek]
77
+
78
+
1
79
  == 0.3.0
2
80
 
3
81
  * 2 major improvements
data/README.rdoc CHANGED
@@ -3,90 +3,80 @@
3
3
  Pickle gives you cucumber steps that create your models easily from factory-girl or
4
4
  machinist factories/blueprints. You can also just use ActiveRecord as a factory but it's not as cool.
5
5
 
6
- Pickle can make use of different ORMs for finding records. Currently ActiveRecord and DataMapper adapters are
6
+ Pickle can make use of different ORMs for finding records. Currently ActiveRecord, DataMapper, MongoID adapters are
7
7
  provided. More adapters welcome!
8
8
 
9
9
  References to the models are stored in the current world, not necessarily for the purpose of checking the db
10
10
  (although you could use it for that), but for enabling easy reference to urls, and for
11
11
  building complex givens which require a bunch of models collaborating
12
12
 
13
- == Resources
13
+ == Quickstart
14
14
 
15
- <b>Github</b> for code: http://github.com/ianwhite/pickle
15
+ This is a quickstart guide for rails apps. Firstly, install {cucumber-rails}[http://github.com/aslakhellesoy/cucumber-rails], and its dependencies.
16
+ Then do the following:
16
17
 
17
- <b>Gemcutter</b> for the gem: http://gemcutter.org/gems/pickle
18
-
19
- <b>Rdoc.info</b> for docs: http://rdoc.info/projects/ianwhite/pickle
18
+ === Rails 3:
20
19
 
21
- <b>Google group</b> for questions: http://groups.google.com/group/pickle-cucumber
20
+ Add the gem to your Gemfile:
22
21
 
23
- <b>Lighthouse</b> for bugs: http://ianwhite.lighthouseapp.com/projects/25941-pickle
22
+ gem 'pickle'
23
+
24
+ Then install with:
24
25
 
25
- <b>Railscast</b> presentation: http://railscasts.com/episodes/186-pickle-with-cucumber
26
+ bundle install
27
+
28
+ Discover the options for the generator:
26
29
 
27
- <b>Blog articles</b>: {dynamic50: Integration testing with cucumber and pickle}[http://blog.dynamic50.com/index.php/2009/04/integration-testing-with-cucumber-and-pickle/], {rubyflare: pickle my cucumber}[http://rubyflare.com/2009/10/28/pickle-my-cucumber/]
30
+ rails g pickle --help
28
31
 
29
- == Install
32
+ Run the generator, e.g:
30
33
 
31
- Install pickle either as a rails plugin, or a gem
34
+ rails g pickle --paths --email
35
+
36
+ === For Rails 2:
32
37
 
33
- # gem from gemcutter
34
- sudo gem install pickle
38
+ Add the following to config/environments/cucumber:
35
39
 
36
- # gem dependency (in config/environments/cucumber.rb)
37
40
  config.gem 'pickle'
38
41
 
39
- # plugin
40
- script/plugin install git://github.com/ianwhite/pickle.git
41
-
42
- # or, plugin as submodule
43
- git submodule add git://github.com/ianwhite/pickle.git vendor/plugins/pickle
42
+ Install the gem with
44
43
 
45
- == CI
44
+ rake gems:install RAILS_ENV=cucumber
45
+
46
+ Run the generator with:
46
47
 
47
- It's tested against all stable branches of 2.x rails, and edge, with the latest versions of rspec, cucumber, factory_girl, machinist.
48
-
49
- == Run the tests
48
+ script/generate pickle [paths] [email]
50
49
 
51
- To run the specs do:
50
+ == Resources
52
51
 
53
- rake spec
52
+ <b>Github</b> for code: http://github.com/ianwhite/pickle
54
53
 
55
- To run the features (rails 2.3 only ATM):
54
+ <b>Gemcutter</b> for the gem: http://gemcutter.org/gems/pickle
56
55
 
57
- rake cucumber
56
+ <b>Rdoc.info</b> for docs: http://rdoc.info/projects/ianwhite/pickle
58
57
 
59
- == Contributors
58
+ <b>Google group</b> for questions: http://groups.google.com/group/pickle-cucumber
60
59
 
61
- The following people have made Pickle better:
60
+ <b>Lighthouse</b> for bugs: http://ianwhite.lighthouseapp.com/projects/25941-pickle
62
61
 
63
- * {Daniel Neighman}[http://github.com/hassox]
64
- * {Josh Bassett}[http://github.com/nullobject]
65
- * {Nick Rutherford}[http://github.com/nruth]
66
- * {Tobi Knaup}[http://github.com/guenter]
67
- * {Michael MacDonald}[http://github.com/schlick]
68
- * {Michael Moen}[http://github.com/UnderpantsGnome]
69
- * {Myron Marston}[http://github.com/myronmarston]
70
- * {Stephan Hagemann}[http://github.com/xing]
71
- * {Chris Flipse}[http://github.com/cflipse]
62
+ <b>Railscast</b> presentation: http://railscasts.com/episodes/186-pickle-with-cucumber
72
63
 
73
- == Get Started
64
+ <b>Blog articles</b>: {dynamic50: Integration testing with cucumber and pickle}[http://blog.dynamic50.com/index.php/2009/04/integration-testing-with-cucumber-and-pickle/], {rubyflare: pickle my cucumber}[http://rubyflare.com/2009/10/28/pickle-my-cucumber/]
74
65
 
75
- (you'd better install cucumber)
76
66
 
77
- script/generate pickle [paths] [email]
67
+ == Using Pickle
78
68
 
79
69
  Now have a look at <tt>features/step_definitions/pickle_steps.rb</tt>
80
70
 
81
- If you want path steps and email steps then just add 'paths' and/or 'email'. The code/steps will be
82
- written to <tt>features/env/paths.rb</tt> and
71
+ If you want path steps and email steps then just add the 'paths' and/or 'email' options to the generator.
72
+ The code/steps will be written to <tt>features/env/paths.rb</tt> and
83
73
  <tt>features/step_definitions/email_steps.rb</tt> respectively.
84
74
 
85
- === Using with plain ole Active Record or DataMapper
75
+ === Using with plain ole Active Record, DataMapper or Mongoid
86
76
 
87
- Pickle comes with adapters for Active Record and DataMapper.
77
+ Pickle comes with ORM adapters for Active Record, DataMapper and Mongoid.
88
78
 
89
- If you have an AR/DM called 'Post', with required fields 'title', and 'body', then you can now write
79
+ If you have a model called 'Post', with required fields 'title', and 'body', then you can now write
90
80
  steps like this
91
81
 
92
82
  Given a post exists with title: "My Post", body: "My body"
@@ -103,10 +93,7 @@ you've written, you can just do stuff like
103
93
  Then a user should exist with name: "Fred"
104
94
  And that user should be activated # this uses rspec predicate matchers
105
95
 
106
- ==== Machinst: require your blueprints and reset Shams
107
-
108
- (The latest version of pickle supports {multiple blueprints}[http://github.com/notahat/machinist/commit/d6492e6927a8aa1819926e48b22377171fd20496], for
109
- earlier versions of machinist use pickle <= 0.1.10)
96
+ ==== Machinist: require your blueprints and reset Shams
110
97
 
111
98
  In your <tt>features/support/env.rb</tt> add the following lines at the bottom
112
99
 
@@ -122,16 +109,16 @@ If that doesn't solve loading issues then require your factories.rb file directl
122
109
  # example features/support/factory_girl.rb
123
110
  require File.dirname(__FILE__) + '/../../spec/factories'
124
111
 
125
- === Using with an ORM other than ActiveRecord or DataMapper
112
+ === Using with an ORM other than ActiveRecord, DataMapper, or Mongoid
126
113
 
127
- Pickle can be used with any Modeling library provided there is an adapter written for it.
114
+ Pickle can be used with any modelling library provided there is an adapter written for it.
128
115
 
129
116
  Adapters are very simple and exist a module or class with the name "PickleAdapter" available to the class. For example
130
117
 
131
118
  User.const_get(:PickleAdapter) #=> should return a pickle adapter
132
119
 
133
120
  The Active Record and DataMapper ones can be found at
134
- ActiveRecord::Base::PickleAdapter and DataMapper::Resource::PickleAdapter respectively.
121
+ ActiveRecord::Base::PickleAdapter, DataMapper::Resource::PickleAdapter, Mongoid::Document::PickleAdapter respectively.
135
122
 
136
123
  See how to implement one by looking at the ones provided in the pickle source in lib/pickle/adapters/*
137
124
 
@@ -146,13 +133,13 @@ In: <tt>features/support/pickle.rb</tt>
146
133
  require 'pickle/world'
147
134
 
148
135
  Pickle.configure do |config|
149
- config.adapters = [:machinist, YourOwnAdapterClass]
136
+ config.adapters = [:machinist, :active_record, YourOwnAdapterClass]
150
137
  config.map 'me', 'myself', 'my', 'I', :to => 'user: "me"'
151
138
  end
152
139
 
153
- Out of the box pickle looks for machinist, then factory-girl, then finally active-record 'factories'.
154
- If you find that your steps aren't working with your factories, it's probably the case that your factory
155
- setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).
140
+ Out of the box pickle looks for machinist, factory-girl, then uses the ORM(s) that you're using to create models.
141
+
142
+ If you find that your steps aren't working with your factories, it's probably the case that your factory setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).
156
143
 
157
144
  == API
158
145
 
@@ -172,15 +159,30 @@ When you run <tt>script/generate pickle</tt> you get the following steps
172
159
 
173
160
  Given a user exists with name: "Fred"
174
161
  Given a user exists with name: "Fred", activated: false
162
+
163
+ This last step could be better expressed by using Machinist/FactoryGirl to create an activated user. Then you can do
164
+
165
+ Given an activated user exists with name: "Fred"
175
166
 
176
167
  You can refer to other models in the fields
177
168
 
178
169
  Given a user exists
179
170
  And a post exists with author: the user
180
171
 
181
- Given a person: "fred" exists
182
- And a person: "ethel" exists
183
- And a fatherhood exists with parent: user "fred", child: user "ethel"
172
+ Given a person "fred" exists
173
+ And a person "ethel" exists
174
+ And a fatherhood exists with parent: person "fred", child: person "ethel"
175
+
176
+ This last step is given by the default pickle steps, but it would be better written as:
177
+
178
+ And "fred" is the father of "ethel"
179
+
180
+ It is expected that you'll need to expand upon the default pickle steps to make your features readable. To write the
181
+ above step, you could do something like:
182
+
183
+ Given /^"(\w+)" is the father of "(\w+)"$/ do |father, child|
184
+ Fatherhood.create! :father => model!("person: \"#{father}\""), :child => model!("person: \"#{child}\"")
185
+ end
184
186
 
185
187
  "Given <b>n models</b> exist", e.g.
186
188
 
@@ -197,6 +199,35 @@ You can refer to other models in the fields
197
199
  | Fred | false |
198
200
  | Ethel | true |
199
201
 
202
+ ===== Named machinist blueprints
203
+
204
+ "Given <b> a <i>named</i> model</b> exists with <b>fields</b>"
205
+
206
+ The latest version of pickle supports {named machinist blueprints}[http://github.com/notahat/machinist/commit/d6492e6927a8aa1819926e48b22377171fd20496].
207
+
208
+ If you had the following blueprints:
209
+
210
+ User.blueprint do
211
+ name
212
+ email
213
+ end
214
+
215
+ User.blueprint(:super_admin) do
216
+ role { "admin" }
217
+ end
218
+
219
+ User.blueprint(:activated) do
220
+ activated { true }
221
+ end
222
+
223
+ You could create a user with pickle by simply adding the name of the blueprint before the model:
224
+
225
+ Given a super admin user exists
226
+ And an activated user exists with name: "Fred"
227
+
228
+ This is much nicer than having to set up common configurations in your steps all the time, and far more readable to boot.
229
+
230
+
200
231
  ==== Then steps
201
232
 
202
233
  ===== Asserting existence of models
@@ -297,3 +328,40 @@ can build up composite objects with ease
297
328
  # example of use
298
329
  Given a user exists
299
330
  And a post exists with author: the user # this step will assign the above user as :author on the post
331
+
332
+ == Run the tests
333
+
334
+ To get all the dependencies required for developing pickle, do the following
335
+
336
+ bundle install
337
+
338
+ To run the specs do:
339
+
340
+ bundle exec rake spec
341
+
342
+ To run the features (rails 2.3 only ATM):
343
+
344
+ bundle exec rake cucumber
345
+
346
+ == Contributors
347
+
348
+ The following people have made Pickle better:
349
+
350
+ * {Marc Lee}[http://github.com/maleko]
351
+ * {Sebastian Zuchmanski}[http://github.com/sebcioz]
352
+ * {Paul Gideon Dann}[http://github.com/giddie]
353
+ * {Tom Meier}[http://github.com/tommeier]
354
+ * {Sean Hussey}[http://github.com/seanhussey]
355
+ * Brian Rose & Kevin Olsen
356
+ * {Christopher Darroch}[http://github.com/chrisdarroch]
357
+ * {Szymon Nowak}[http://github.com/szimek]
358
+ * {H.J. Blok}[http://github.com/hjblok]
359
+ * {Daniel Neighman}[http://github.com/hassox]
360
+ * {Josh Bassett}[http://github.com/nullobject]
361
+ * {Nick Rutherford}[http://github.com/nruth]
362
+ * {Tobi Knaup}[http://github.com/guenter]
363
+ * {Michael MacDonald}[http://github.com/schlick]
364
+ * {Michael Moen}[http://github.com/UnderpantsGnome]
365
+ * {Myron Marston}[http://github.com/myronmarston]
366
+ * {Stephan Hagemann}[http://github.com/xing]
367
+ * {Chris Flipse}[http://github.com/cflipse]
@@ -9,6 +9,10 @@ Jeweler::Tasks.new do |s|
9
9
  s.email = "ian.w.white@gmail.com"
10
10
  s.homepage = "http://github.com/ianwhite/pickle/tree"
11
11
  s.authors = ["Ian White"]
12
+ s.add_dependency('rspec', ">=1.3")
13
+ s.add_dependency('cucumber', ">=0.8")
14
+ s.add_dependency('yard')
15
+ s.add_dependency('rake')
12
16
  end
13
17
 
14
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.2
@@ -4,7 +4,7 @@ Feature: I can easily create models from my blueprints
4
4
  I want to be able to create models with fields
5
5
  So that I can create models quickly and easily in my features
6
6
 
7
- @wip
7
+
8
8
  Scenario: I create a user, and see if it looks right
9
9
  Given a user exists with name: "Fred", has_stale_password: true
10
10
  Then the user should not have a status
@@ -56,4 +56,8 @@ Feature: I can easily create models from my factories
56
56
  Scenario: I create fork via a mapping
57
57
  Given killah fork exists
58
58
  Then the fork should be fancy
59
- And the fancy fork: "of cornwood" should be fancy
59
+ And the fancy fork: "of cornwood" should be fancy
60
+
61
+ Scenario: create a tine with a missing fork
62
+ Then the following should raise Pickle::Session::ModelNotKnownError: "Given a tine exists with fork: the fork"
63
+
@@ -0,0 +1,3 @@
1
+ Then /^the following should raise Pickle::Session::ModelNotKnownError: "([^"]*)"$/ do |step|
2
+ lambda { steps step }.should raise_error(Pickle::Session::ModelNotKnownError)
3
+ end
@@ -0,0 +1,69 @@
1
+ require 'rails/generators'
2
+
3
+ class PickleGenerator < Rails::Generators::Base
4
+ desc "Generates Pickle step files."
5
+
6
+ # Use the same templates as Rails 2 generator
7
+ source_root File.expand_path("../../../rails_generators/pickle/templates", __FILE__)
8
+
9
+ class_option :paths, :desc => "Generate features/support/paths.rb file.", :type => :boolean
10
+ class_option :email, :desc => "Generate features/step_definitions/email_steps.rb file", :type => :boolean
11
+
12
+ def initialize(args = [], options = {}, config = {})
13
+ super
14
+
15
+ if self.options.paths? && !File.exists?("features/support/paths.rb")
16
+ say "features/support/paths.rb not found, is your cucumber up to date?", :red
17
+ exit
18
+ end
19
+ end
20
+
21
+ def create_directories
22
+ empty_directory "features/step_definitions"
23
+ empty_directory "features/support"
24
+ end
25
+
26
+ def copy_pickle_steps_file
27
+ template "pickle_steps.rb", "features/step_definitions/pickle_steps.rb"
28
+ template "pickle.rb", "features/support/pickle.rb"
29
+ end
30
+
31
+ def copy_paths_file
32
+ return unless options.paths?
33
+
34
+ current_paths = File.read("features/support/paths.rb")
35
+ unless current_paths.include?('#{capture_model}')
36
+ if current_paths =~ /^(.*)(\n\s+else\n\s+raise "Can't find.*".*$)/m
37
+ @current_paths_header = $1
38
+ @current_paths_footer = $2
39
+ end
40
+ template "paths.rb", "features/support/paths.rb"
41
+ end
42
+ end
43
+
44
+ def copy_email_steps_file
45
+ return unless options.email?
46
+ template "email_steps.rb", "features/step_definitions/email_steps.rb"
47
+ template "email.rb", "features/support/email.rb"
48
+ end
49
+
50
+
51
+ private
52
+
53
+ # Compatibility methods for Rails 2 templates
54
+ def pickle_path
55
+ options.paths?
56
+ end
57
+
58
+ def pickle_email
59
+ options.email?
60
+ end
61
+
62
+ def current_paths_header
63
+ @current_paths_header
64
+ end
65
+
66
+ def current_paths_footer
67
+ @current_paths_footer
68
+ end
69
+ end
@@ -25,7 +25,7 @@ module Pickle
25
25
 
26
26
  self.model_classes = nil
27
27
 
28
- # Include this module into your adapter
28
+ # Include this module into your ORM adapter
29
29
  # this will register the adapter with pickle and it will be picked up for you
30
30
  # To create an adapter you should create an inner constant "PickleAdapter"
31
31
  #
@@ -33,6 +33,7 @@ module Pickle
33
33
  #
34
34
  # @see pickle/adapters/active_record
35
35
  # @see pickle/adapters/datamapper
36
+ # @see pickle/adapters/mongoid
36
37
  module Base
37
38
  def self.included(base)
38
39
  adapters << base
@@ -69,6 +70,10 @@ module Pickle
69
70
  def find_all_models(klass, conditions)
70
71
  klass.const_get(:PickleAdapter).find_all_models(klass, conditions)
71
72
  end
73
+
74
+ def create_model(klass, attributes)
75
+ klass.const_get(:PickleAdapter).create_model(klass, attributes)
76
+ end
72
77
  end
73
78
 
74
79
  # machinist adapter
@@ -90,7 +95,11 @@ module Pickle
90
95
  end
91
96
 
92
97
  def create(attrs = {})
93
- @klass.send(:make, @blueprint, attrs)
98
+ if @klass.respond_to?('make!')
99
+ @klass.send(:make!, @blueprint, attrs)
100
+ else
101
+ @klass.send(:make, @blueprint, attrs)
102
+ end
94
103
  end
95
104
  end
96
105
 
@@ -105,14 +114,15 @@ module Pickle
105
114
  end
106
115
 
107
116
  def create(attrs = {})
108
- Factory.create(@name, attrs)
117
+ Factory(@name, attrs)
109
118
  end
110
119
  end
111
120
 
112
- # fallback active record adapter
113
- class ActiveRecord < Adapter
121
+ # ORM adapter. If you have no factory adapter, you can use this adapter to
122
+ # use your orm as 'factory' - ie create objects
123
+ class Orm < Adapter
114
124
  def self.factories
115
- ::ActiveRecord::Base::PickleAdapter.model_classes.map{|k| new(k)}
125
+ model_classes.map{|k| new(k)}
116
126
  end
117
127
 
118
128
  def initialize(klass)
@@ -120,7 +130,7 @@ module Pickle
120
130
  end
121
131
 
122
132
  def create(attrs = {})
123
- @klass.send(:create!, attrs)
133
+ Pickle::Adapter.create_model(@klass, attrs)
124
134
  end
125
135
  end
126
136
  end