pickle-has_many_support 0.3.1

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.
Files changed (70) hide show
  1. data/.gitignore +5 -0
  2. data/History.txt +331 -0
  3. data/License.txt +20 -0
  4. data/README.rdoc +299 -0
  5. data/Rakefile +20 -0
  6. data/Rakefile.d/cucumber.rake +24 -0
  7. data/Rakefile.d/jeweller.rake +19 -0
  8. data/Rakefile.d/rcov.rake +18 -0
  9. data/Rakefile.d/rspec.rake +7 -0
  10. data/Rakefile.d/yard.rake +5 -0
  11. data/Todo.txt +3 -0
  12. data/VERSION +1 -0
  13. data/features/app/app.rb +122 -0
  14. data/features/app/blueprints.rb +11 -0
  15. data/features/app/factories.rb +23 -0
  16. data/features/app/views/notifier/email.erb +1 -0
  17. data/features/app/views/notifier/user_email.erb +6 -0
  18. data/features/email/email.feature +64 -0
  19. data/features/generator/generators.feature +59 -0
  20. data/features/path/models_page.feature +44 -0
  21. data/features/path/named_route_page.feature +10 -0
  22. data/features/pickle/create_from_active_record.feature +76 -0
  23. data/features/pickle/create_from_factory_girl.feature +59 -0
  24. data/features/pickle/create_from_machinist.feature +39 -0
  25. data/features/step_definitions/email_steps.rb +63 -0
  26. data/features/step_definitions/extra_email_steps.rb +7 -0
  27. data/features/step_definitions/fork_steps.rb +4 -0
  28. data/features/step_definitions/generator_steps.rb +46 -0
  29. data/features/step_definitions/path_steps.rb +14 -0
  30. data/features/step_definitions/pickle_steps.rb +100 -0
  31. data/features/support/email.rb +21 -0
  32. data/features/support/env.rb +52 -0
  33. data/features/support/paths.rb +47 -0
  34. data/features/support/pickle.rb +26 -0
  35. data/features/support/pickle_app.rb +4 -0
  36. data/init.rb +0 -0
  37. data/lib/pickle/adapter.rb +127 -0
  38. data/lib/pickle/adapters/active_record.rb +46 -0
  39. data/lib/pickle/adapters/data_mapper.rb +37 -0
  40. data/lib/pickle/config.rb +48 -0
  41. data/lib/pickle/email/parser.rb +18 -0
  42. data/lib/pickle/email/world.rb +13 -0
  43. data/lib/pickle/email.rb +79 -0
  44. data/lib/pickle/parser/matchers.rb +95 -0
  45. data/lib/pickle/parser.rb +71 -0
  46. data/lib/pickle/path/world.rb +5 -0
  47. data/lib/pickle/path.rb +45 -0
  48. data/lib/pickle/session/parser.rb +34 -0
  49. data/lib/pickle/session.rb +195 -0
  50. data/lib/pickle/version.rb +9 -0
  51. data/lib/pickle/world.rb +13 -0
  52. data/lib/pickle.rb +26 -0
  53. data/pickle.gemspec +117 -0
  54. data/rails_generators/pickle/pickle_generator.rb +33 -0
  55. data/rails_generators/pickle/templates/email.rb +21 -0
  56. data/rails_generators/pickle/templates/email_steps.rb +63 -0
  57. data/rails_generators/pickle/templates/paths.rb +47 -0
  58. data/rails_generators/pickle/templates/pickle.rb +28 -0
  59. data/rails_generators/pickle/templates/pickle_steps.rb +100 -0
  60. data/spec/pickle/adapter_spec.rb +163 -0
  61. data/spec/pickle/config_spec.rb +105 -0
  62. data/spec/pickle/email/parser_spec.rb +51 -0
  63. data/spec/pickle/email_spec.rb +160 -0
  64. data/spec/pickle/parser/matchers_spec.rb +74 -0
  65. data/spec/pickle/parser_spec.rb +165 -0
  66. data/spec/pickle/path_spec.rb +101 -0
  67. data/spec/pickle/session_spec.rb +451 -0
  68. data/spec/pickle_spec.rb +24 -0
  69. data/spec/spec_helper.rb +8 -0
  70. metadata +144 -0
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'pickle/email/parser'
4
+
5
+ describe Pickle::Email::Parser do
6
+ include Pickle::Parser::Matchers
7
+ include Pickle::Email::Parser
8
+
9
+ describe "#match_email" do
10
+ it "should match 'the email'" do
11
+ 'the email'.should match(/^#{match_email}$/)
12
+ end
13
+
14
+ it "should match 'the first email'" do
15
+ 'the first email'.should match(/^#{match_email}$/)
16
+ end
17
+
18
+ it "should match 'the last email'" do
19
+ 'the last email'.should match(/^#{match_email}$/)
20
+ end
21
+
22
+ it "should match 'the 3rd email'" do
23
+ 'the 3rd email'.should match(/^#{match_email}$/)
24
+ end
25
+
26
+ it "should match 'an email'" do
27
+ 'an email'.should match(/^#{match_email}$/)
28
+ end
29
+ end
30
+
31
+ it "#capture_email should just capture match_email" do
32
+ capture_email.should == "(#{match_email})"
33
+ end
34
+
35
+ describe "#capture_index_in_email" do
36
+ it "should extract the '2nd' from 'the 2nd email'" do
37
+ match = 'the 2nd email'.match(/^#{capture_index_in_email}$/)
38
+ match[1].should == '2nd'
39
+ end
40
+
41
+ it "should extract nil from 'the email'" do
42
+ match = 'the email'.match(/^#{capture_index_in_email}$/)
43
+ match[1].should == nil
44
+ end
45
+
46
+ it "should extract the 'last' from 'the last email'" do
47
+ match = 'the last email'.match(/^#{capture_index_in_email}$/)
48
+ match[1].should == 'last'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,160 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ require 'pickle/email'
4
+ require 'pickle/email/parser'
5
+ require 'action_mailer'
6
+
7
+ describe Pickle::Email do
8
+ include Pickle::Session
9
+ include Pickle::Email
10
+ include Pickle::Email::Parser
11
+
12
+ before do
13
+ @email1 = mock("Email 1")
14
+ @email2 = mock("Email 2")
15
+ ActionMailer::Base.stub!(:deliveries).and_return([@email1, @email2])
16
+ if defined?(ActiveRecord::Base)
17
+ ActiveRecord::Base::PickleAdapter.stub!(:model_classes).and_return([])
18
+ end
19
+ end
20
+
21
+ describe "#emails" do
22
+ it "should return ordered deliveries" do
23
+ emails.should == [@email1, @email2]
24
+ end
25
+
26
+ describe "(after)" do
27
+ before do
28
+ emails
29
+ end
30
+
31
+ it "#email('the email') should return the last delivery" do
32
+ email('the email').should == @email2
33
+ end
34
+
35
+ it "#email('the 1st email') should return the first delivery" do
36
+ email('the 1st email').should == @email1
37
+ end
38
+
39
+ it "#email('the first email') should return the first delivery" do
40
+ email('the first email').should == @email1
41
+ end
42
+
43
+ it "#email('the 2nd email') should return the second delivery" do
44
+ email('the 2nd email').should == @email2
45
+ end
46
+
47
+ it "#email('the last email') should return the second delivery" do
48
+ email('the last email').should == @email2
49
+ end
50
+
51
+ it "#email2('the 3rd email') should be nil" do
52
+ email('the 3rd email').should == nil
53
+ end
54
+ end
55
+
56
+ describe "when email1 is to fred & joe, and email2 is to joe" do
57
+ before do
58
+ @email1.stub!(:to).and_return(['fred@gmail.com', 'joe@gmail.com'])
59
+ @email2.stub!(:to).and_return('joe@gmail.com')
60
+ end
61
+
62
+ it "#emails('to: \"fred@gmail.com\"') should just return email1" do
63
+ emails('to: "fred@gmail.com"').should == [@email1]
64
+ end
65
+
66
+ describe "after #emails('to: \"fred@gmail.com\"')" do
67
+ before do
68
+ emails('to: "fred@gmail.com"')
69
+ end
70
+
71
+ it "#email('first') should be #email('last')" do
72
+ email('first email').should == email('last email')
73
+ email('first email').should == @email1
74
+ end
75
+
76
+ it "#email('the email', 'to: \"blah\") should be nil" do
77
+ email('the email', 'to: "blah"').should == nil
78
+ end
79
+
80
+ it "#email('the email', 'to: \"fred@gmail.com\") should be email1" do
81
+ email('the email', 'to: "fred@gmail.com"').should == @email1
82
+ end
83
+ end
84
+
85
+ it "#emails('to: \"joe@gmail.com\"') should return both emails" do
86
+ emails('to: "joe@gmail.com"').should == [@email1, @email2]
87
+ end
88
+
89
+ describe "and emails have subjects 'email1', 'email2'" do
90
+ before do
91
+ @email1.stub!(:subject).and_return('email1')
92
+ @email2.stub!(:subject).and_return('email2')
93
+ end
94
+
95
+ it "#emails('to: \"joe@gmail.com\", subject: \"email1\"') should return email1" do
96
+ emails('to: "joe@gmail.com", subject: "email1"').should == [@email1]
97
+ end
98
+
99
+ it "#emails('to: \"fred@gmail.com\", subject: \"email2\"') should return empty array" do
100
+ emails('to: "fred@gmail.com", subject: "email2"').should == []
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#save_and_open_emails" do
107
+ before do
108
+ stub!(:open_in_browser)
109
+ stub!(:emails).and_return(["Contents of Email 1"])
110
+ @now = "2008-01-01".to_time
111
+ Time.stub!(:now).and_return(@now)
112
+ end
113
+
114
+ it "should call #emails to get emails" do
115
+ should_receive(:emails).and_return([])
116
+ save_and_open_emails
117
+ end
118
+
119
+ describe "when emails have been already been found" do
120
+ before { @emails = [] }
121
+
122
+ it "should not call #emails" do
123
+ should_not_receive(:emails)
124
+ save_and_open_emails
125
+ end
126
+ end
127
+
128
+ it "should create a file in Rails/tmp with the emails in it" do
129
+ save_and_open_emails
130
+ File.read("pickle-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
131
+ end
132
+
133
+ it "should call open_in_browser on created tmp file" do
134
+ should_receive(:open_in_browser).with("pickle-email-#{@now.to_i}.html")
135
+ save_and_open_emails
136
+ end
137
+ end
138
+
139
+ describe "following links in emails" do
140
+ before do
141
+ stub!(:open_in_browser)
142
+ @email1.stub!(:body).and_return('some text <a href="http://example.com/page">example page</a> more text')
143
+ end
144
+
145
+ it "should find a link for http://example.com/page" do
146
+ should_receive(:visit).with('/page')
147
+ visit_in_email(@email1, 'http://example.com/page')
148
+ end
149
+
150
+ it "should find a link for \"example page\"" do
151
+ should_receive(:visit).with('/page')
152
+ visit_in_email(@email1, 'example page')
153
+ end
154
+
155
+ it "should follow the first link in an email" do
156
+ should_receive(:visit).with('/page')
157
+ click_first_link_in_email(@email1)
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Pickle::Parser::Matchers do
4
+ include Pickle::Parser::Matchers
5
+
6
+ describe "(config: [factories: user, car, fast_car] [predicates: name, status, fancy?, super_fancy?, has_style?, has_super_style?]" do
7
+ def config
8
+ @config ||= Pickle::Config.new do |c|
9
+ c.factories = {
10
+ 'user' => mock('factory'),
11
+ 'car' => mock('factory'),
12
+ 'fast_car' => mock('factory')
13
+ }
14
+ c.predicates = %w(name status fancy? super_fancy? has_style? has_super_style?)
15
+ end
16
+ end
17
+
18
+ describe "Match atoms" do
19
+ def self.atom_should_match(atom, strings)
20
+ Array(strings).each do |string|
21
+ it "#{atom} should match '#{string}'" do
22
+ string.should match(/^#{send atom}$/)
23
+ end
24
+ end
25
+ end
26
+
27
+ def self.atom_should_not_match(atom, strings)
28
+ Array(strings).each do |string|
29
+ it "#{atom} should NOT match '#{string}'" do
30
+ string.should_not match(/^#{send atom}$/)
31
+ end
32
+ end
33
+ end
34
+
35
+ atom_should_match :match_ordinal, ['1st', '2nd', '23rd', '104th']
36
+ atom_should_not_match :match_ordinal, ['1', '2']
37
+
38
+ atom_should_match :match_index, ['first', 'last', '23rd', '104th']
39
+ atom_should_not_match :match_index, ['1', '2', 'foo']
40
+
41
+ atom_should_match :match_label, [': "gday"', ': "gday mate"']
42
+ atom_should_not_match :match_label, [': "gday""', ': gday']
43
+
44
+ atom_should_match :match_collection, ['[]', '[that user]', '[that car, user "Bob"]']
45
+ atom_should_not_match :match_collection, ['[, ]', '[a giraffe]', '[a 1st faster car: "jim", an event created]']
46
+
47
+ atom_should_match :match_field, ['foo: "this is the life"', 'bar_man: "and so is this"', 'boolean: false', 'boolean: true', 'numeric: 10', 'numeric: 12.5', 'numeric: +10', 'numeric: +12.5', 'numeric: -10', 'numeric: -12.5', 'nil_field: nil', 'collection: [that car, user "Bob"]']
48
+ atom_should_not_match :match_field, ['foo bar: "this aint workin"', 'not_numeric: --10', 'not_numeric: -ten']
49
+
50
+ atom_should_match :match_fields, ['foo: "bar"', 'foo: "bar", baz: "bah"']
51
+ atom_should_not_match :match_fields, ['foo bar: "baz"', 'email: "a", password: "b", and password_confirmation: "c"']
52
+
53
+ atom_should_match :match_model, ['a user', '1st fast car', 'the 23rd fast_car', 'the user: "fred flinstone"']
54
+
55
+ atom_should_not_match :match_model, ['a giraffe', 'a 1st faster car: "jim"', 'an event created']
56
+
57
+ atom_should_match :match_predicate, ['name', 'status', 'fancy', 'super fancy', 'super_fancy', 'style', 'super style', 'super_style']
58
+ atom_should_not_match :match_predicate, ['nameo', 'increment', 'not a predicate', 'has style']
59
+
60
+ atom_should_match :match_factory, ['user', 'fast car', 'fast_car', 'car']
61
+ atom_should_not_match :match_factory, ['users', 'faster car', 'event created']
62
+
63
+ atom_should_match :match_plural_factory, ['users', 'fast cars']
64
+ atom_should_not_match :match_plural_factory, ['usereres', 'fasts cars']
65
+ end
66
+ end
67
+
68
+ describe "capture methods" do
69
+ it "capture_field should == '(' + match_field + ')'" do
70
+ should_receive(:match_field).and_return('MATCH_FIELD')
71
+ capture_field.should == '(MATCH_FIELD)'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,165 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Pickle::Parser do
4
+ before do
5
+ @parser = Pickle::Parser.new(:config => Pickle::Config.new)
6
+ end
7
+
8
+ it "should raise error when created with no config" do
9
+ lambda{ Pickle::Parser.new }.should raise_error(ArgumentError)
10
+ end
11
+
12
+ describe "when a 'user' factory exists in config" do
13
+ before do
14
+ @parser.config.stub(:factories).and_return('user' => mock('User'))
15
+ end
16
+
17
+ describe 'misc regexps' do
18
+ describe '/^#{capture_model} exists/' do
19
+ before do
20
+ @regexp = /^(#{@parser.capture_model}) exists$/
21
+ end
22
+
23
+ it "should match 'a user exists'" do
24
+ 'a user exists'.should match(@regexp)
25
+ end
26
+
27
+ it "should caputure 'a user' from 'a user exists'" do
28
+ 'a user exists'.match(@regexp)[1].should == 'a user'
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '#parse_field' do
34
+ it "should return {'a' => 'b'} for 'a: \"b\"'" do
35
+ @parser.parse_field('a: "b"').should == {'a' => 'b'}
36
+ end
37
+
38
+ it "should return {'a' => ['that user', 'user \"Bob\"']} for 'a: [that user, user \"Bob\"]'" do
39
+ @parser.parse_field('a: [that user, user "Bob"]').should == {'a' => ['that user', 'user "Bob"']}
40
+ end
41
+
42
+ it "should raise error for invalid field 'a : b'" do
43
+ lambda { @parser.parse_field('a : b') }.should raise_error(ArgumentError)
44
+ end
45
+ end
46
+
47
+ describe '#parse_fields' do
48
+ it 'should return {} for blank argument' do
49
+ @parser.parse_fields(nil).should == {}
50
+ @parser.parse_fields('').should == {}
51
+ end
52
+
53
+ it 'should raise error for invalid argument' do
54
+ lambda { @parser.parse_fields('foo foo') }.should raise_error(ArgumentError)
55
+ end
56
+
57
+ it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
58
+ @parser.parse_fields('foo: "bar"').should == { "foo" => "bar"}
59
+ end
60
+
61
+ it '("bool: true") should == { "bool" => true}' do
62
+ @parser.parse_fields('bool: true').should == {"bool" => true}
63
+ end
64
+
65
+ it '("bool: false") should == { "bool" => false}' do
66
+ @parser.parse_fields('bool: false').should == {"bool" => false}
67
+ end
68
+
69
+ it '("int: 10") should == { "int" => 10 }' do
70
+ @parser.parse_fields('int: 10').should == {"int" => 10}
71
+ end
72
+
73
+ it '("float: 10.1") should == { "float" => 10.1 }' do
74
+ @parser.parse_fields('float: 10.1').should == {"float" => 10.1}
75
+ end
76
+
77
+ it '(\'foo: "bar", bar_man: "wonga wonga", gump: 123, many: [that user]\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123, "many" => ["that user"]}' do
78
+ @parser.parse_fields('foo: "bar", bar_man: "wonga wonga", gump: 123, many: [that user]').should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123, "many" => ["that user"]}
79
+ end
80
+ end
81
+
82
+ describe '#parse_model' do
83
+ it '("a user") should == ["user", ""]' do
84
+ @parser.parse_model("a user").should == ["user", ""]
85
+ end
86
+
87
+ it '("the user") should == ["user", ""]' do
88
+ @parser.parse_model("the user").should == ["user", ""]
89
+ end
90
+
91
+ it '("1 user") should == ["user", ""]' do
92
+ @parser.parse_model("1 user").should == ["user", ""]
93
+ end
94
+
95
+ it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
96
+ @parser.parse_model('an user: "jim jones"').should == ["user", "jim_jones"]
97
+ end
98
+
99
+ it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
100
+ @parser.parse_model('that user: "herbie"').should == ["user", "herbie"]
101
+ end
102
+
103
+ it '(\'the 12th user\') should == ["user", 11]' do
104
+ @parser.parse_model('the 12th user').should == ["user", 11]
105
+ end
106
+
107
+ it '(\'the last user\') should == ["user", -1]' do
108
+ @parser.parse_model('the last user').should == ["user", -1]
109
+ end
110
+
111
+ it '("the first user") should == ["user", 0]' do
112
+ @parser.parse_model('the first user').should == ["user", 0]
113
+ end
114
+
115
+ it '("the 1st user") should == ["user", 0]' do
116
+ @parser.parse_model('the 1st user').should == ["user", 0]
117
+ end
118
+ end
119
+
120
+ describe "#parse_index" do
121
+ it '("1st") should == 0' do
122
+ @parser.parse_index("1st").should == 0
123
+ end
124
+
125
+ it '("24th") should == 23' do
126
+ @parser.parse_index("24th").should == 23
127
+ end
128
+ it '("first") should == 0' do
129
+ @parser.parse_index("first").should == 0
130
+ end
131
+
132
+ it '("last") should == -1' do
133
+ @parser.parse_index("last").should == -1
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "customised mappings" do
139
+ describe "config maps 'I|myself' to 'user: \"me\"'" do
140
+ before do
141
+ @config = Pickle::Config.new do |c|
142
+ c.map 'I', 'myself', :to => 'user: "me"'
143
+ end
144
+ @parser = Pickle::Parser.new(:config => @config)
145
+ @parser.config.stub(:factories).and_return('user' => mock('User'))
146
+ end
147
+
148
+ it "'I' should match /\#{match_model}/" do
149
+ 'I'.should match(/#{@parser.match_model}/)
150
+ end
151
+
152
+ it "'myself' should match /\#{match_model}/" do
153
+ 'myself'.should match(/#{@parser.match_model}/)
154
+ end
155
+
156
+ it "parse_model('I') should == ['user', 'me']" do
157
+ @parser.parse_model('I').should == ["user", "me"]
158
+ end
159
+
160
+ it "parse_model('myself') should == ['user', 'me']" do
161
+ @parser.parse_model('myself').should == ["user", "me"]
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ require 'pickle/path'
4
+
5
+ describe Pickle::Path do
6
+ include Pickle::Path
7
+
8
+ describe "#path_to_pickle, when the model doesn't exist" do
9
+ before do
10
+ stub!(:model).and_return(nil)
11
+ end
12
+ it "('that user', :extra => 'new comment') should raise the error raised by model!" do
13
+ lambda { path_to_pickle "that user", "new comment" }.should raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
14
+ end
15
+
16
+ end
17
+
18
+ describe "#path_to_pickle" do
19
+ describe "when model returns a user" do
20
+ let :user_class do
21
+ mock 'User', :name => 'User'
22
+ end
23
+
24
+ let :user do
25
+ mock 'user', :class => user_class
26
+ end
27
+
28
+ before do
29
+ stub!(:model).and_return(user)
30
+ end
31
+
32
+ it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
33
+ should_receive(:model).with('a user')
34
+ should_receive(:model).with('the user: "fred"')
35
+ stub!(:user_user_path).and_return('the path')
36
+ path_to_pickle('a user', 'the user: "fred"').should == 'the path'
37
+ end
38
+
39
+ it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
40
+ should_receive(:foo_user_path).with(user).and_return('the path')
41
+ path_to_pickle('a user', :action => 'foo').should == 'the path'
42
+ end
43
+
44
+ it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
45
+ should_receive(:foo_user_path).with(user).and_raise(NoMethodError)
46
+ lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
47
+ end
48
+
49
+ it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
50
+ should_receive(:user_foo_path).with(user).and_return('the path')
51
+ path_to_pickle('a user', :segment => 'foo').should == 'the path'
52
+ end
53
+
54
+ it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
55
+ should_receive(:user_foo_path).with(user).and_raise(NoMethodError)
56
+ lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
57
+ end
58
+
59
+ it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
60
+ should_receive(:new_user_comment_path).with(user).and_return('the path')
61
+ path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
62
+ end
63
+
64
+ it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
65
+ should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
66
+ lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
67
+ end
68
+
69
+ it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
70
+ should_receive(:new_user_comment_path).with(user).and_return('the path')
71
+ path_to_pickle('a user', :extra => 'new comment').should == 'the path'
72
+ end
73
+
74
+ it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
75
+ should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
76
+ lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
77
+ end
78
+
79
+ describe "when args is a list of pickle and non pickle models" do
80
+ before do
81
+ stub!(:model).with("account").and_return(nil)
82
+ end
83
+
84
+ it "('account', 'the user') should return account_user_path(<user>)" do
85
+ should_receive(:account_user_path).with(user).and_return("the path")
86
+ path_to_pickle('account', 'the user').should == 'the path'
87
+ end
88
+ end
89
+
90
+ describe "(private API)" do
91
+ it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
92
+ should_receive(:pickle_path_for_resources_action_segment).with([user], '', 'new_ish_comment').once
93
+ should_receive(:pickle_path_for_resources_action_segment).with([user], 'new', 'ish_comment').once
94
+ should_receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish', 'comment').once
95
+ should_receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish_comment', '').once
96
+ lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end