ianwhite-pickle 0.1.6 → 0.1.8

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,22 @@
1
+ == 0.1.8 - 29 Jan 2009
2
+
3
+ * API change
4
+ * pickle_path becomes path_to_pickle, to avoid named route clashes
5
+
6
+ * 2 minor enhancements
7
+ * Updated features for cucumber 0.2 compat
8
+ * Made paths allow for optional possesives
9
+
10
+
11
+ == 0,1,7
12
+
13
+ * 2 API changes
14
+ * script/generate pickle path[s] now amends the features/support/paths.rb file
15
+ instead of creating pge_to_path and path_steps.
16
+
17
+ * pickle_email_steps is renamed email_steps
18
+
19
+
1
20
  == 0.1.6
2
21
 
3
22
  * 1 API change
data/lib/pickle/path.rb CHANGED
@@ -3,15 +3,15 @@ module Pickle
3
3
  # given args of pickle model name, and an optional extra action, or segment, will attempt to find
4
4
  # a matching named route
5
5
  #
6
- # pickle_path 'the user', :action => 'edit' # => /users/3/edit
7
- # pickle_path 'the user', 'the comment' # => /users/3/comments/1
8
- # pickle_path 'the user', :segment => 'comments' # => /users/3/comments
6
+ # path_to_pickle 'the user', :action => 'edit' # => /users/3/edit
7
+ # path_to_pickle 'the user', 'the comment' # => /users/3/comments/1
8
+ # path_to_pickle 'the user', :segment => 'comments' # => /users/3/comments
9
9
  #
10
10
  # If you don;t know if the 'extra' part of the path is an action or a segment, then just
11
11
  # pass it as 'extra' and this method will run through the possibilities
12
12
  #
13
- # pickle_path 'the user', :extra => 'new comment' # => /users/3/comments/new
14
- def pickle_path(*pickle_names)
13
+ # path_to_pickle 'the user', :extra => 'new comment' # => /users/3/comments/new
14
+ def path_to_pickle(*pickle_names)
15
15
  options = pickle_names.extract_options!
16
16
  models = pickle_names.map{|m| model(m)}
17
17
  if options[:extra]
@@ -2,7 +2,7 @@ module Pickle
2
2
  module Version
3
3
  Major = 0
4
4
  Minor = 1
5
- Tiny = 6
5
+ Tiny = 8
6
6
 
7
7
  String = [Major, Minor, Tiny].join('.')
8
8
  end
@@ -1,9 +1,11 @@
1
1
  class PickleGenerator < Rails::Generator::Base
2
2
  def initialize(args, options)
3
3
  super(args, options)
4
- @generate_path_steps = args.include?('page') || args.include?('path')
5
- @generate_email_steps = args.include?('email')
6
4
  File.exists?('features/support/env.rb') or raise "features/support/env.rb not found, try running script/generate cucumber"
5
+ @generate_email_steps = args.include?('email')
6
+ if @generate_path_steps = args.include?('path') || args.include?('paths')
7
+ File.exists?('features/support/paths.rb') or raise "features/support/paths.rb not found, is your cucumber up to date?"
8
+ end
7
9
  end
8
10
 
9
11
  def manifest
@@ -15,12 +17,19 @@ class PickleGenerator < Rails::Generator::Base
15
17
 
16
18
  if @generate_path_steps
17
19
  env_assigns[:pickle_path] = true unless current_env.include?("require 'pickle/path/world'")
18
- m.template 'pickle_path_steps.rb', File.join('features/step_definitions', "pickle_path_steps.rb")
20
+ current_paths = File.read('features/support/paths.rb')
21
+ unless current_paths.include?('#{capture_model}')
22
+ if current_paths =~ /^(.*)(\n\s+else\n\s+raise ".*"\n\s+end\nend\s*)$/m
23
+ env_assigns[:current_paths_header] = $1
24
+ env_assigns[:current_paths_footer] = $2
25
+ m.template 'paths.rb', File.join('features/support', "paths.rb"), :assigns => env_assigns, :collision => :force
26
+ end
27
+ end
19
28
  end
20
29
 
21
30
  if @generate_email_steps
22
31
  env_assigns[:pickle_email] = true unless current_env.include?("require 'pickle/email/world'")
23
- m.template 'pickle_email_steps.rb', File.join('features/step_definitions', "pickle_email_steps.rb")
32
+ m.template 'email_steps.rb', File.join('features/step_definitions', "email_steps.rb")
24
33
  end
25
34
 
26
35
  env_assigns[:pickle] = true unless current_env.include?("require 'pickle/world'")
@@ -41,8 +41,8 @@ Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
41
41
  email(email_ref).body.should_not =~ /#{text}/
42
42
  end
43
43
 
44
- Then(/^#{capture_email} should link to (.+) page$/) do |email_ref, page|
45
- email(email_ref).body.should =~ /#{page_to_path(page)}/
44
+ Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
45
+ email(email_ref).body.should =~ /#{path_to(page)}/
46
46
  end
47
47
 
48
48
  Then(/^show me the emails?$/) do
@@ -1,12 +1,14 @@
1
- <%= current_env %>
2
- <% if pickle %>require 'pickle/world'<% end %>
3
- <% if pickle_path %>require 'pickle/path/world'<% end %>
4
- <% if pickle_email %>require 'pickle/email/world'<% end %>
5
- <% if pickle %>
1
+ <%= current_env -%>
2
+ <%- if pickle -%>
3
+ require 'pickle/world'
6
4
  # Example of configuring pickle:
7
5
  #
8
6
  # Pickle.configure do |config|
9
7
  # config.adaptors = [:machinist]
10
8
  # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
11
9
  # end
12
- <% end -%>
10
+ <%- end -%>
11
+ <%- if pickle_path -%>require 'pickle/path/world'
12
+ <%- end -%>
13
+ <%- if pickle_email -%>require 'pickle/email/world'
14
+ <%- end -%>
@@ -0,0 +1,20 @@
1
+ <%= current_paths_header %>
2
+ # added by script/generate pickle path
3
+
4
+ when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
5
+ path_to_pickle $1
6
+
7
+ when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
8
+ path_to_pickle $1, $2
9
+
10
+ when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
11
+ path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
12
+
13
+ when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
14
+ path_to_pickle $1, :extra => $2 # or the forum's edit page
15
+
16
+ when /^the (.+?) page$/ # translate to named route
17
+ send "#{$1.downcase.gsub(' ','_')}_path"
18
+
19
+ # end added by pickle path
20
+ <%= current_paths_footer %>
@@ -7,52 +7,52 @@ describe Pickle::Path do
7
7
  stub!(:model).and_return(@user = mock_model(User))
8
8
  end
9
9
 
10
- describe "#pickle_path" do
10
+ describe "#path_to_pickle" do
11
11
  it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
12
12
  should_receive(:model).with('a user')
13
13
  should_receive(:model).with('the user: "fred"')
14
14
  stub!(:user_user_path).and_return('the path')
15
- pickle_path 'a user', 'the user: "fred"'
15
+ path_to_pickle 'a user', 'the user: "fred"'
16
16
  end
17
17
 
18
18
  it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
19
19
  should_receive(:foo_user_path).with(@user).and_return('the path')
20
- pickle_path('a user', :action => 'foo').should == 'the path'
20
+ path_to_pickle('a user', :action => 'foo').should == 'the path'
21
21
  end
22
22
 
23
23
  it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
24
24
  should_receive(:foo_user_path).with(@user).and_raise(NoMethodError)
25
- lambda { pickle_path('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
25
+ lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
26
26
  end
27
27
 
28
28
  it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
29
29
  should_receive(:user_foo_path).with(@user).and_return('the path')
30
- pickle_path('a user', :segment => 'foo').should == 'the path'
30
+ path_to_pickle('a user', :segment => 'foo').should == 'the path'
31
31
  end
32
32
 
33
33
  it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
34
34
  should_receive(:user_foo_path).with(@user).and_raise(NoMethodError)
35
- lambda { pickle_path('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
35
+ lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
36
36
  end
37
37
 
38
38
  it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
39
39
  should_receive(:new_user_comment_path).with(@user).and_return('the path')
40
- pickle_path('a user', :segment => 'comment', :action => 'new').should == 'the path'
40
+ path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
41
41
  end
42
42
 
43
43
  it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
44
44
  should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
45
- lambda { pickle_path('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
45
+ lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
46
46
  end
47
47
 
48
48
  it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
49
49
  should_receive(:new_user_comment_path).with(@user).and_return('the path')
50
- pickle_path('a user', :extra => 'new comment').should == 'the path'
50
+ path_to_pickle('a user', :extra => 'new comment').should == 'the path'
51
51
  end
52
52
 
53
53
  it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
54
54
  should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
55
- lambda { pickle_path('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
55
+ lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
56
56
  end
57
57
 
58
58
  describe "(private API)" do
@@ -61,7 +61,7 @@ describe Pickle::Path do
61
61
  should_receive(:pickle_path_for_models_action_segment).with([@user], 'new', 'ish_comment').once
62
62
  should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish', 'comment').once
63
63
  should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish_comment', '').once
64
- lambda { pickle_path('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
64
+ lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
65
65
  end
66
66
  end
67
67
  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.6
4
+ version: 0.1.8
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-01-24 00:00:00 -08:00
12
+ date: 2009-01-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -37,9 +37,9 @@ files:
37
37
  - lib/pickle/world.rb
38
38
  - lib/pickle.rb
39
39
  - rails_generators/pickle/pickle_generator.rb
40
+ - rails_generators/pickle/templates/email_steps.rb
40
41
  - rails_generators/pickle/templates/env.rb
41
- - rails_generators/pickle/templates/pickle_email_steps.rb
42
- - rails_generators/pickle/templates/pickle_path_steps.rb
42
+ - rails_generators/pickle/templates/paths.rb
43
43
  - rails_generators/pickle/templates/pickle_steps.rb
44
44
  - License.txt
45
45
  - README.textile
@@ -1,53 +0,0 @@
1
- # this file generated by script/generate pickle page.
2
- # You should edit the page_to_path method below for your own app's needs
3
-
4
- # When I go to /sessions/new
5
- When(/^I go to \/(.+?)$/) do |path|
6
- visit "/#{path}"
7
- end
8
-
9
- # Then I should be at /sessions/new
10
- Then(/^I should be at \/(.+?)$/) do |path|
11
- request.path.should =~ /^\/#{path}/
12
- end
13
-
14
- # When I go to the posts's new comment page
15
- When(/^I go to (.+?) page$/) do |page|
16
- visit page_to_path(page)
17
- end
18
-
19
- # Then I should be at the posts's new comment page
20
- Then(/^I should be at (.+?) page$/) do |page|
21
- request.path.should =~ /^#{page_to_path(page)}/
22
- end
23
-
24
- # passed a string like 'the home', returns a path
25
- def page_to_path(page)
26
- case page
27
- # add your own app-specific mappings, e.g.
28
- #
29
- # when 'the home'
30
- # '/'
31
- #
32
- # when /$#{capture_model}'s activation^/
33
- # activation_by_code_path(created_model($1).activation_code)
34
-
35
- when /^#{capture_model}'s$/ # the forum's
36
- pickle_path $1
37
-
38
- when /^#{capture_model}'s #{capture_model}'s$/ # the forum's post's
39
- pickle_path $1, $2
40
-
41
- when /^#{capture_model}'s #{capture_model}'s (.+?)$/ # the forum's post's comments
42
- pickle_path $1, $2, :extra => $3
43
-
44
- when /^#{capture_model}'s (.+?)$/ # the post's comments
45
- pickle_path $1, :extra => $2
46
-
47
- when /^the (.+?)$/ # the new session
48
- send "#{$1.downcase.gsub(' ','_')}_path"
49
-
50
- else
51
- raise "Could not map '#{page}' page to a path"
52
- end
53
- end