judit-pickle 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +98 -0
- data/History.txt +409 -0
- data/License.txt +20 -0
- data/README.rdoc +367 -0
- data/Rakefile +20 -0
- data/Rakefile.d/cucumber.rake +24 -0
- data/Rakefile.d/jeweler.rake +23 -0
- data/Rakefile.d/rcov.rake +18 -0
- data/Rakefile.d/rspec.rake +7 -0
- data/Rakefile.d/yard.rake +5 -0
- data/Todo.txt +3 -0
- data/VERSION +1 -0
- data/features/app/app.rb +122 -0
- data/features/app/blueprints.rb +11 -0
- data/features/app/factories.rb +23 -0
- data/features/app/views/notifier/email.erb +1 -0
- data/features/app/views/notifier/user_email.erb +6 -0
- data/features/email/email.feature +64 -0
- data/features/generator/generators.feature +59 -0
- data/features/path/models_page.feature +44 -0
- data/features/path/named_route_page.feature +10 -0
- data/features/pickle/create_from_active_record.feature +76 -0
- data/features/pickle/create_from_factory_girl.feature +63 -0
- data/features/pickle/create_from_machinist.feature +39 -0
- data/features/step_definitions/email_steps.rb +63 -0
- data/features/step_definitions/extra_email_steps.rb +7 -0
- data/features/step_definitions/fork_steps.rb +4 -0
- data/features/step_definitions/generator_steps.rb +46 -0
- data/features/step_definitions/path_steps.rb +14 -0
- data/features/step_definitions/pickle_steps.rb +100 -0
- data/features/step_definitions/raise_error_steps.rb +3 -0
- data/features/support/email.rb +21 -0
- data/features/support/env.rb +52 -0
- data/features/support/paths.rb +47 -0
- data/features/support/pickle.rb +26 -0
- data/features/support/pickle_app.rb +4 -0
- data/init.rb +0 -0
- data/lib/generators/pickle_generator.rb +69 -0
- data/lib/pickle/adapter.rb +137 -0
- data/lib/pickle/adapters/active_record.rb +57 -0
- data/lib/pickle/adapters/data_mapper.rb +42 -0
- data/lib/pickle/adapters/mongoid.rb +44 -0
- data/lib/pickle/config.rb +49 -0
- data/lib/pickle/email/parser.rb +18 -0
- data/lib/pickle/email/world.rb +13 -0
- data/lib/pickle/email.rb +77 -0
- data/lib/pickle/parser/matchers.rb +87 -0
- data/lib/pickle/parser.rb +65 -0
- data/lib/pickle/path/world.rb +5 -0
- data/lib/pickle/path.rb +45 -0
- data/lib/pickle/session/parser.rb +34 -0
- data/lib/pickle/session.rb +205 -0
- data/lib/pickle/version.rb +9 -0
- data/lib/pickle/world.rb +14 -0
- data/lib/pickle.rb +26 -0
- data/pickle.gemspec +134 -0
- data/rails_generators/pickle/pickle_generator.rb +33 -0
- data/rails_generators/pickle/templates/email.rb +21 -0
- data/rails_generators/pickle/templates/email_steps.rb +63 -0
- data/rails_generators/pickle/templates/paths.rb +47 -0
- data/rails_generators/pickle/templates/pickle.rb +28 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +100 -0
- data/spec/pickle/adapter_spec.rb +186 -0
- data/spec/pickle/config_spec.rb +109 -0
- data/spec/pickle/email/parser_spec.rb +51 -0
- data/spec/pickle/email_spec.rb +166 -0
- data/spec/pickle/parser/matchers_spec.rb +70 -0
- data/spec/pickle/parser_spec.rb +161 -0
- data/spec/pickle/path_spec.rb +101 -0
- data/spec/pickle/session_spec.rb +434 -0
- data/spec/pickle_spec.rb +24 -0
- data/spec/spec_helper.rb +8 -0
- metadata +199 -0
@@ -0,0 +1,166 @@
|
|
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('http://example.com/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('http://example.com/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('http://example.com/page')
|
157
|
+
click_first_link_in_email(@email1)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should not raise an error when the email body is not a string, but needs to_s [#26]" do
|
161
|
+
stub!(:visit)
|
162
|
+
@email1.stub!(:body).and_return(:a_string_body)
|
163
|
+
lambda { click_first_link_in_email(@email1) }.should_not raise_error
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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_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']
|
45
|
+
atom_should_not_match :match_field, ['foo bar: "this aint workin"', 'not_numeric: --10', 'not_numeric: -ten']
|
46
|
+
|
47
|
+
atom_should_match :match_fields, ['foo: "bar"', 'foo: "bar", baz: "bah"']
|
48
|
+
atom_should_not_match :match_fields, ['foo bar: "baz"', 'email: "a", password: "b", and password_confirmation: "c"']
|
49
|
+
|
50
|
+
atom_should_match :match_model, ['a user', '1st fast car', 'the 23rd fast_car', 'the user: "fred flinstone"']
|
51
|
+
atom_should_not_match :match_model, ['a giraffe', 'a 1st faster car: "jim"', 'an event created']
|
52
|
+
|
53
|
+
atom_should_match :match_predicate, ['name', 'status', 'fancy', 'super fancy', 'super_fancy', 'style', 'super style', 'super_style']
|
54
|
+
atom_should_not_match :match_predicate, ['nameo', 'increment', 'not a predicate', 'has style']
|
55
|
+
|
56
|
+
atom_should_match :match_factory, ['user', 'fast car', 'fast_car', 'car']
|
57
|
+
atom_should_not_match :match_factory, ['users', 'faster car', 'event created']
|
58
|
+
|
59
|
+
atom_should_match :match_plural_factory, ['users', 'fast cars']
|
60
|
+
atom_should_not_match :match_plural_factory, ['usereres', 'fasts cars']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "capture methods" do
|
65
|
+
it "capture_field should == '(' + match_field + ')'" do
|
66
|
+
should_receive(:match_field).and_return('MATCH_FIELD')
|
67
|
+
capture_field.should == '(MATCH_FIELD)'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,161 @@
|
|
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 raise error for invalid field 'a : b'" do
|
39
|
+
lambda { @parser.parse_field('a : b') }.should raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#parse_fields' do
|
44
|
+
it 'should return {} for blank argument' do
|
45
|
+
@parser.parse_fields(nil).should == {}
|
46
|
+
@parser.parse_fields('').should == {}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise error for invalid argument' do
|
50
|
+
lambda { @parser.parse_fields('foo foo') }.should raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
|
54
|
+
@parser.parse_fields('foo: "bar"').should == { "foo" => "bar"}
|
55
|
+
end
|
56
|
+
|
57
|
+
it '("bool: true") should == { "bool" => true}' do
|
58
|
+
@parser.parse_fields('bool: true').should == {"bool" => true}
|
59
|
+
end
|
60
|
+
|
61
|
+
it '("bool: false") should == { "bool" => false}' do
|
62
|
+
@parser.parse_fields('bool: false').should == {"bool" => false}
|
63
|
+
end
|
64
|
+
|
65
|
+
it '("int: 10") should == { "int" => 10 }' do
|
66
|
+
@parser.parse_fields('int: 10').should == {"int" => 10}
|
67
|
+
end
|
68
|
+
|
69
|
+
it '("float: 10.1") should == { "float" => 10.1 }' do
|
70
|
+
@parser.parse_fields('float: 10.1').should == {"float" => 10.1}
|
71
|
+
end
|
72
|
+
|
73
|
+
it '(\'foo: "bar", bar_man: "wonga wonga", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
|
74
|
+
@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", gump: 123').should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#parse_model' do
|
79
|
+
it '("a user") should == ["user", ""]' do
|
80
|
+
@parser.parse_model("a user").should == ["user", ""]
|
81
|
+
end
|
82
|
+
|
83
|
+
it '("the user") should == ["user", ""]' do
|
84
|
+
@parser.parse_model("the user").should == ["user", ""]
|
85
|
+
end
|
86
|
+
|
87
|
+
it '("1 user") should == ["user", ""]' do
|
88
|
+
@parser.parse_model("1 user").should == ["user", ""]
|
89
|
+
end
|
90
|
+
|
91
|
+
it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
|
92
|
+
@parser.parse_model('an user: "jim jones"').should == ["user", "jim_jones"]
|
93
|
+
end
|
94
|
+
|
95
|
+
it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
|
96
|
+
@parser.parse_model('that user: "herbie"').should == ["user", "herbie"]
|
97
|
+
end
|
98
|
+
|
99
|
+
it '(\'the 12th user\') should == ["user", 11]' do
|
100
|
+
@parser.parse_model('the 12th user').should == ["user", 11]
|
101
|
+
end
|
102
|
+
|
103
|
+
it '(\'the last user\') should == ["user", -1]' do
|
104
|
+
@parser.parse_model('the last user').should == ["user", -1]
|
105
|
+
end
|
106
|
+
|
107
|
+
it '("the first user") should == ["user", 0]' do
|
108
|
+
@parser.parse_model('the first user').should == ["user", 0]
|
109
|
+
end
|
110
|
+
|
111
|
+
it '("the 1st user") should == ["user", 0]' do
|
112
|
+
@parser.parse_model('the 1st user').should == ["user", 0]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#parse_index" do
|
117
|
+
it '("1st") should == 0' do
|
118
|
+
@parser.parse_index("1st").should == 0
|
119
|
+
end
|
120
|
+
|
121
|
+
it '("24th") should == 23' do
|
122
|
+
@parser.parse_index("24th").should == 23
|
123
|
+
end
|
124
|
+
it '("first") should == 0' do
|
125
|
+
@parser.parse_index("first").should == 0
|
126
|
+
end
|
127
|
+
|
128
|
+
it '("last") should == -1' do
|
129
|
+
@parser.parse_index("last").should == -1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "customised mappings" do
|
135
|
+
describe "config maps 'I|myself' to 'user: \"me\"'" do
|
136
|
+
before do
|
137
|
+
@config = Pickle::Config.new do |c|
|
138
|
+
c.map 'I', 'myself', :to => 'user: "me"'
|
139
|
+
end
|
140
|
+
@parser = Pickle::Parser.new(:config => @config)
|
141
|
+
@parser.config.stub(:factories).and_return('user' => mock('User'))
|
142
|
+
end
|
143
|
+
|
144
|
+
it "'I' should match /\#{match_model}/" do
|
145
|
+
'I'.should match(/#{@parser.match_model}/)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "'myself' should match /\#{match_model}/" do
|
149
|
+
'myself'.should match(/#{@parser.match_model}/)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "parse_model('I') should == ['user', 'me']" do
|
153
|
+
@parser.parse_model('I').should == ["user", "me"]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "parse_model('myself') should == ['user', 'me']" do
|
157
|
+
@parser.parse_model('myself').should == ["user", "me"]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
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
|