pickle 0.2.12 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/README.rdoc +46 -26
- data/VERSION +1 -1
- data/lib/pickle/adapter.rb +48 -23
- data/lib/pickle/adapters/active_record.rb +46 -0
- data/lib/pickle/adapters/data_mapper.rb +37 -0
- data/lib/pickle/config.rb +2 -2
- data/lib/pickle/email.rb +4 -4
- data/lib/pickle/session.rb +24 -9
- data/lib/pickle/world.rb +4 -0
- data/pickle.gemspec +3 -1
- data/spec/pickle/adapter_spec.rb +41 -61
- data/spec/pickle/config_spec.rb +27 -19
- data/spec/pickle/email_spec.rb +26 -23
- data/spec/pickle/session_spec.rb +80 -78
- data/spec/spec_helper.rb +2 -0
- metadata +6 -4
data/spec/pickle/email_spec.rb
CHANGED
@@ -13,22 +13,25 @@ describe Pickle::Email do
|
|
13
13
|
@email1 = mock("Email 1")
|
14
14
|
@email2 = mock("Email 2")
|
15
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
|
16
19
|
end
|
17
|
-
|
20
|
+
|
18
21
|
describe "#emails" do
|
19
22
|
it "should return ordered deliveries" do
|
20
23
|
emails.should == [@email1, @email2]
|
21
24
|
end
|
22
|
-
|
25
|
+
|
23
26
|
describe "(after)" do
|
24
27
|
before do
|
25
28
|
emails
|
26
29
|
end
|
27
|
-
|
30
|
+
|
28
31
|
it "#email('the email') should return the last delivery" do
|
29
32
|
email('the email').should == @email2
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
it "#email('the 1st email') should return the first delivery" do
|
33
36
|
email('the 1st email').should == @email1
|
34
37
|
end
|
@@ -40,36 +43,36 @@ describe Pickle::Email do
|
|
40
43
|
it "#email('the 2nd email') should return the second delivery" do
|
41
44
|
email('the 2nd email').should == @email2
|
42
45
|
end
|
43
|
-
|
46
|
+
|
44
47
|
it "#email('the last email') should return the second delivery" do
|
45
48
|
email('the last email').should == @email2
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
it "#email2('the 3rd email') should be nil" do
|
49
52
|
email('the 3rd email').should == nil
|
50
53
|
end
|
51
54
|
end
|
52
|
-
|
55
|
+
|
53
56
|
describe "when email1 is to fred & joe, and email2 is to joe" do
|
54
57
|
before do
|
55
58
|
@email1.stub!(:to).and_return(['fred@gmail.com', 'joe@gmail.com'])
|
56
59
|
@email2.stub!(:to).and_return('joe@gmail.com')
|
57
60
|
end
|
58
|
-
|
61
|
+
|
59
62
|
it "#emails('to: \"fred@gmail.com\"') should just return email1" do
|
60
63
|
emails('to: "fred@gmail.com"').should == [@email1]
|
61
64
|
end
|
62
|
-
|
65
|
+
|
63
66
|
describe "after #emails('to: \"fred@gmail.com\"')" do
|
64
67
|
before do
|
65
68
|
emails('to: "fred@gmail.com"')
|
66
69
|
end
|
67
|
-
|
70
|
+
|
68
71
|
it "#email('first') should be #email('last')" do
|
69
72
|
email('first email').should == email('last email')
|
70
73
|
email('first email').should == @email1
|
71
74
|
end
|
72
|
-
|
75
|
+
|
73
76
|
it "#email('the email', 'to: \"blah\") should be nil" do
|
74
77
|
email('the email', 'to: "blah"').should == nil
|
75
78
|
end
|
@@ -78,28 +81,28 @@ describe Pickle::Email do
|
|
78
81
|
email('the email', 'to: "fred@gmail.com"').should == @email1
|
79
82
|
end
|
80
83
|
end
|
81
|
-
|
84
|
+
|
82
85
|
it "#emails('to: \"joe@gmail.com\"') should return both emails" do
|
83
86
|
emails('to: "joe@gmail.com"').should == [@email1, @email2]
|
84
87
|
end
|
85
|
-
|
88
|
+
|
86
89
|
describe "and emails have subjects 'email1', 'email2'" do
|
87
90
|
before do
|
88
91
|
@email1.stub!(:subject).and_return('email1')
|
89
92
|
@email2.stub!(:subject).and_return('email2')
|
90
93
|
end
|
91
|
-
|
94
|
+
|
92
95
|
it "#emails('to: \"joe@gmail.com\", subject: \"email1\"') should return email1" do
|
93
96
|
emails('to: "joe@gmail.com", subject: "email1"').should == [@email1]
|
94
97
|
end
|
95
|
-
|
98
|
+
|
96
99
|
it "#emails('to: \"fred@gmail.com\", subject: \"email2\"') should return empty array" do
|
97
100
|
emails('to: "fred@gmail.com", subject: "email2"').should == []
|
98
101
|
end
|
99
102
|
end
|
100
103
|
end
|
101
104
|
end
|
102
|
-
|
105
|
+
|
103
106
|
describe "#save_and_open_emails" do
|
104
107
|
before do
|
105
108
|
stub!(:open_in_browser)
|
@@ -107,21 +110,21 @@ describe Pickle::Email do
|
|
107
110
|
@now = "2008-01-01".to_time
|
108
111
|
Time.stub!(:now).and_return(@now)
|
109
112
|
end
|
110
|
-
|
113
|
+
|
111
114
|
it "should call #emails to get emails" do
|
112
115
|
should_receive(:emails).and_return([])
|
113
116
|
save_and_open_emails
|
114
117
|
end
|
115
|
-
|
118
|
+
|
116
119
|
describe "when emails have been already been found" do
|
117
120
|
before { @emails = [] }
|
118
|
-
|
121
|
+
|
119
122
|
it "should not call #emails" do
|
120
123
|
should_not_receive(:emails)
|
121
124
|
save_and_open_emails
|
122
125
|
end
|
123
126
|
end
|
124
|
-
|
127
|
+
|
125
128
|
it "should create a file in Rails/tmp with the emails in it" do
|
126
129
|
save_and_open_emails
|
127
130
|
File.read("pickle-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
|
@@ -132,13 +135,13 @@ describe Pickle::Email do
|
|
132
135
|
save_and_open_emails
|
133
136
|
end
|
134
137
|
end
|
135
|
-
|
138
|
+
|
136
139
|
describe "following links in emails" do
|
137
140
|
before do
|
138
141
|
stub!(:open_in_browser)
|
139
142
|
@email1.stub!(:body).and_return('some text <a href="http://example.com/page">example page</a> more text')
|
140
143
|
end
|
141
|
-
|
144
|
+
|
142
145
|
it "should find a link for http://example.com/page" do
|
143
146
|
should_receive(:visit).with('/page')
|
144
147
|
visit_in_email(@email1, 'http://example.com/page')
|
@@ -148,7 +151,7 @@ describe Pickle::Email do
|
|
148
151
|
should_receive(:visit).with('/page')
|
149
152
|
visit_in_email(@email1, 'example page')
|
150
153
|
end
|
151
|
-
|
154
|
+
|
152
155
|
it "should follow the first link in an email" do
|
153
156
|
should_receive(:visit).with('/page')
|
154
157
|
click_first_link_in_email(@email1)
|
data/spec/pickle/session_spec.rb
CHANGED
@@ -3,12 +3,17 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
3
3
|
# TODO: remove this and push AR stuff into ORM adapter
|
4
4
|
module ActiveRecord
|
5
5
|
class Base
|
6
|
-
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module DataMapper
|
10
|
+
class Model
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
describe Pickle::Session do
|
10
15
|
include Pickle::Session
|
11
|
-
|
16
|
+
|
12
17
|
let :user_class do
|
13
18
|
mock("User class", :name => 'User')
|
14
19
|
end
|
@@ -16,15 +21,15 @@ describe Pickle::Session do
|
|
16
21
|
let :user do
|
17
22
|
mock("user", :class => user_class, :id => 1)
|
18
23
|
end
|
19
|
-
|
24
|
+
|
20
25
|
let :user_factory do
|
21
26
|
Pickle::Adapter::ActiveRecord.new(user_class)
|
22
27
|
end
|
23
|
-
|
28
|
+
|
24
29
|
before do
|
25
30
|
config.stub(:factories).and_return('user' => user_factory)
|
26
31
|
end
|
27
|
-
|
32
|
+
|
28
33
|
describe "Pickle::Session proxy missing methods to parser", :shared => true do
|
29
34
|
it "should forward to pickle_parser it responds_to them" do
|
30
35
|
subject.pickle_parser.should_receive(:parse_model)
|
@@ -40,17 +45,17 @@ describe Pickle::Session do
|
|
40
45
|
subject do
|
41
46
|
self
|
42
47
|
end
|
43
|
-
|
48
|
+
|
44
49
|
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
45
50
|
end
|
46
51
|
|
47
52
|
describe "extending Pickle::Session" do
|
48
|
-
subject do
|
53
|
+
subject do
|
49
54
|
returning Object.new do |object|
|
50
55
|
object.extend Pickle::Session
|
51
56
|
end
|
52
57
|
end
|
53
|
-
|
58
|
+
|
54
59
|
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
55
60
|
end
|
56
61
|
|
@@ -81,13 +86,13 @@ describe Pickle::Session do
|
|
81
86
|
end
|
82
87
|
|
83
88
|
before do
|
84
|
-
|
89
|
+
Pickle::Adapter.stub!(:get_model).with(user_class, 100).and_return(user_from_db)
|
85
90
|
end
|
86
|
-
|
91
|
+
|
87
92
|
it "models('user') should be array containing user" do
|
88
93
|
models('user').should == [user_from_db]
|
89
94
|
end
|
90
|
-
|
95
|
+
|
91
96
|
describe "user should be retrievable with" do
|
92
97
|
it "model('the user')" do
|
93
98
|
model('the user').should == user_from_db
|
@@ -100,79 +105,79 @@ describe Pickle::Session do
|
|
100
105
|
it "model('last user')" do
|
101
106
|
model('last user').should == user_from_db
|
102
107
|
end
|
103
|
-
|
108
|
+
|
104
109
|
it "model!('last user')" do
|
105
110
|
model('last user').should == user_from_db
|
106
111
|
end
|
107
112
|
end
|
108
113
|
end
|
109
114
|
end
|
110
|
-
|
115
|
+
|
111
116
|
describe "#create_model" do
|
112
117
|
before do
|
113
118
|
user_factory.stub!(:create).and_return(user)
|
114
119
|
end
|
115
|
-
|
120
|
+
|
116
121
|
describe "('a user')" do
|
117
122
|
it "should call user_factory.create({})" do
|
118
123
|
user_factory.should_receive(:create).with({})
|
119
124
|
create_model('a user')
|
120
125
|
end
|
121
|
-
|
126
|
+
|
122
127
|
describe "after create," do
|
123
128
|
before { create_model('a user') }
|
124
|
-
|
129
|
+
|
125
130
|
it_should_behave_like "after storing a single user"
|
126
131
|
end
|
127
132
|
end
|
128
|
-
|
133
|
+
|
129
134
|
describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
|
130
135
|
it "should call user_factory.create({'foo' => 'bar', 'baz' => 'bing bong'})" do
|
131
136
|
user_factory.should_receive(:create).with({'foo' => 'bar', 'baz' => 'bing bong'})
|
132
137
|
create_model('1 user', 'foo: "bar", baz: "bing bong"')
|
133
138
|
end
|
134
|
-
|
139
|
+
|
135
140
|
describe "after create," do
|
136
141
|
before { create_model('1 user', 'foo: "bar", baz: "bing bong"') }
|
137
|
-
|
142
|
+
|
138
143
|
it_should_behave_like "after storing a single user"
|
139
144
|
end
|
140
|
-
end
|
145
|
+
end
|
141
146
|
|
142
147
|
describe "('an user: \"fred\")" do
|
143
148
|
it "should call user_factory.create({})" do
|
144
149
|
user_factory.should_receive(:create).with({})
|
145
150
|
create_model('an user: "fred"')
|
146
151
|
end
|
147
|
-
|
152
|
+
|
148
153
|
describe "after create," do
|
149
154
|
before { create_model('an user: "fred"') }
|
150
|
-
|
155
|
+
|
151
156
|
it_should_behave_like "after storing a single user"
|
152
|
-
|
157
|
+
|
153
158
|
it "created_model('the user: \"fred\"') should retrieve the user" do
|
154
159
|
created_model('the user: "fred"').should == user
|
155
160
|
end
|
156
|
-
|
161
|
+
|
157
162
|
it "created_model?('the user: \"shirl\"') should be false" do
|
158
163
|
created_model?('the user: "shirl"').should == false
|
159
164
|
end
|
160
|
-
|
165
|
+
|
161
166
|
it "model?('the user: \"shirl\"') should be false" do
|
162
167
|
model?('the user: "shirl"').should == false
|
163
168
|
end
|
164
169
|
end
|
165
170
|
end
|
166
|
-
|
171
|
+
|
167
172
|
describe "with hash" do
|
168
173
|
it "should call user_factory.create({'foo' => 'bar'})" do
|
169
174
|
user_factory.should_receive(:create).with({'foo' => 'bar'})
|
170
|
-
create_model('a user', {'foo' => 'bar'})
|
175
|
+
create_model('a user', {'foo' => 'bar'}).should == user
|
171
176
|
end
|
172
|
-
|
177
|
+
|
173
178
|
describe "after create," do
|
174
179
|
before { create_model('a user', {'foo' => 'bar'}) }
|
175
|
-
|
180
|
+
|
176
181
|
it_should_behave_like "after storing a single user"
|
177
182
|
end
|
178
183
|
end
|
@@ -180,64 +185,62 @@ describe Pickle::Session do
|
|
180
185
|
|
181
186
|
describe '#find_model' do
|
182
187
|
before do
|
183
|
-
|
188
|
+
Pickle::Adapter.stub!(:find_first_model).with(user_class, anything).and_return(user)
|
184
189
|
end
|
185
|
-
|
190
|
+
|
186
191
|
it "should call user_class.find :first, :conditions => {<fields>}" do
|
187
|
-
|
188
|
-
find_model('a user', 'hair: "pink"')
|
192
|
+
find_model('a user', 'hair: "pink"').should == user
|
189
193
|
end
|
190
|
-
|
194
|
+
|
191
195
|
describe "after find," do
|
192
196
|
before { find_model('a user', 'hair: "pink"') }
|
193
|
-
|
197
|
+
|
194
198
|
it_should_behave_like "after storing a single user"
|
195
199
|
end
|
196
|
-
|
200
|
+
|
197
201
|
describe "with hash" do
|
198
202
|
it "should call user_class.find('user', {'foo' => 'bar'})" do
|
199
|
-
user_class.should_receive(:find).with(:first, :conditions => {'foo' => 'bar'})
|
200
203
|
find_model('a user', {'foo' => 'bar'})
|
201
204
|
end
|
202
|
-
|
205
|
+
|
203
206
|
describe "after find," do
|
204
207
|
before { find_model('a user', {'foo' => 'bar'}) }
|
205
|
-
|
208
|
+
|
206
209
|
it_should_behave_like "after storing a single user"
|
207
210
|
end
|
208
211
|
end
|
209
212
|
end
|
210
|
-
|
213
|
+
|
211
214
|
describe "create and find using plural_factory and table" do
|
212
215
|
context "when given a table without a matching pickle ref column" do
|
213
216
|
let :table do
|
214
217
|
mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
|
215
218
|
end
|
216
|
-
|
219
|
+
|
217
220
|
it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with plain factory name and return the models" do
|
218
221
|
should_receive(:create_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
219
222
|
should_receive(:create_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
220
223
|
create_models_from_table("users", table).should == [:fred, :betty]
|
221
224
|
end
|
222
|
-
|
225
|
+
|
223
226
|
it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with plain factory name and return the models" do
|
224
227
|
should_receive(:find_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
225
228
|
should_receive(:find_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
226
229
|
find_models_from_table("users", table).should == [:fred, :betty]
|
227
230
|
end
|
228
231
|
end
|
229
|
-
|
232
|
+
|
230
233
|
context "when given a table with a matching pickle ref column" do
|
231
234
|
let :table do
|
232
235
|
mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
|
233
236
|
end
|
234
|
-
|
237
|
+
|
235
238
|
it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with labelled pickle ref" do
|
236
239
|
should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
237
240
|
should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
238
241
|
create_models_from_table("users", table).should == [:fred, :betty]
|
239
242
|
end
|
240
|
-
|
243
|
+
|
241
244
|
it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with labelled pickle ref" do
|
242
245
|
should_receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
243
246
|
should_receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
@@ -245,7 +248,7 @@ describe Pickle::Session do
|
|
245
248
|
end
|
246
249
|
end
|
247
250
|
end
|
248
|
-
|
251
|
+
|
249
252
|
describe "#find_model!" do
|
250
253
|
it "should call find_model" do
|
251
254
|
should_receive(:find_model).with('name', 'fields').and_return(user)
|
@@ -257,14 +260,13 @@ describe Pickle::Session do
|
|
257
260
|
lambda { find_model!('name', 'fields') }.should raise_error(RuntimeError, "Can't find pickle model: 'name' in this scenario")
|
258
261
|
end
|
259
262
|
end
|
260
|
-
|
263
|
+
|
261
264
|
describe "#find_models" do
|
262
265
|
before do
|
263
|
-
|
266
|
+
Pickle::Adapter.stub!(:find_all_models).with(user_class, anything).and_return([user])
|
264
267
|
end
|
265
268
|
|
266
269
|
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
267
|
-
user_class.should_receive(:find).with(:all, :conditions => {'hair' => 'pink'})
|
268
270
|
find_models('user', 'hair: "pink"')
|
269
271
|
end
|
270
272
|
|
@@ -274,47 +276,47 @@ describe Pickle::Session do
|
|
274
276
|
it_should_behave_like "after storing a single user"
|
275
277
|
end
|
276
278
|
end
|
277
|
-
|
279
|
+
|
278
280
|
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
|
279
281
|
let(:fred) { mock("fred", :class => user_class, :id => 2) }
|
280
282
|
let(:shirl) { mock("shirl", :class => user_class, :id => 3) }
|
281
283
|
let(:noname) { mock("noname", :class => user_class, :is => 4) }
|
282
|
-
|
284
|
+
|
283
285
|
let(:super_admin_factory) do
|
284
286
|
Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :factory_name => :super_admin))
|
285
287
|
end
|
286
|
-
|
288
|
+
|
287
289
|
before do
|
288
290
|
config.stub(:factories).and_return(user_factory.name => user_factory, super_admin_factory.name => super_admin_factory)
|
289
291
|
user_factory.stub(:create).and_return(shirl)
|
290
292
|
super_admin_factory.stub(:create).and_return(fred, noname)
|
291
293
|
end
|
292
|
-
|
294
|
+
|
293
295
|
def do_create_users
|
294
296
|
create_model('a super admin: "fred"')
|
295
297
|
create_model('a user: "shirl"')
|
296
298
|
create_model('1 super_admin')
|
297
299
|
end
|
298
|
-
|
300
|
+
|
299
301
|
it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
|
300
302
|
super_admin_factory.should_receive(:create).with({}).twice
|
301
303
|
user_factory.should_receive(:create).with({}).once
|
302
304
|
do_create_users
|
303
305
|
end
|
304
|
-
|
306
|
+
|
305
307
|
describe "after create," do
|
306
308
|
before do
|
307
309
|
do_create_users
|
308
310
|
end
|
309
|
-
|
311
|
+
|
310
312
|
it "created_models('user') should == [fred, shirl, noname]" do
|
311
313
|
created_models('user').should == [fred, shirl, noname]
|
312
314
|
end
|
313
|
-
|
315
|
+
|
314
316
|
it "created_models('super_admin') should == [fred, noname]" do
|
315
317
|
created_models('super_admin').should == [fred, noname]
|
316
318
|
end
|
317
|
-
|
319
|
+
|
318
320
|
describe "#created_model" do
|
319
321
|
it "'that user' should be noname (the last user created - as super_admins are users)" do
|
320
322
|
created_model('that user').should == noname
|
@@ -323,27 +325,27 @@ describe Pickle::Session do
|
|
323
325
|
it "'the super admin' should be noname (the last super admin created)" do
|
324
326
|
created_model('that super admin').should == noname
|
325
327
|
end
|
326
|
-
|
328
|
+
|
327
329
|
it "'the 1st super admin' should be fred" do
|
328
330
|
created_model('the 1st super admin').should == fred
|
329
331
|
end
|
330
|
-
|
332
|
+
|
331
333
|
it "'the first user' should be fred" do
|
332
334
|
created_model('the first user').should == fred
|
333
335
|
end
|
334
|
-
|
336
|
+
|
335
337
|
it "'the 2nd user' should be shirl" do
|
336
338
|
created_model('the 2nd user').should == shirl
|
337
339
|
end
|
338
|
-
|
340
|
+
|
339
341
|
it "'the last user' should be noname" do
|
340
342
|
created_model('the last user').should == noname
|
341
343
|
end
|
342
|
-
|
344
|
+
|
343
345
|
it "'the user: \"fred\" should be fred" do
|
344
346
|
created_model('the user: "fred"').should == fred
|
345
347
|
end
|
346
|
-
|
348
|
+
|
347
349
|
it "'the user: \"shirl\" should be shirl" do
|
348
350
|
created_model('the user: "shirl"').should == shirl
|
349
351
|
end
|
@@ -355,11 +357,11 @@ describe Pickle::Session do
|
|
355
357
|
before do
|
356
358
|
self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
|
357
359
|
config.stub(:factories).and_return('user' => user_factory)
|
358
|
-
|
360
|
+
Pickle::Adapter.stub!(:get_model).with(user_class, anything).and_return(user)
|
359
361
|
user_factory.stub!(:create).and_return(user)
|
360
362
|
create_model('the user: "me"')
|
361
363
|
end
|
362
|
-
|
364
|
+
|
363
365
|
it 'model("I") should return the user' do
|
364
366
|
model('I').should == user
|
365
367
|
end
|
@@ -367,11 +369,11 @@ describe Pickle::Session do
|
|
367
369
|
it 'model("myself") should return the user' do
|
368
370
|
model('myself').should == user
|
369
371
|
end
|
370
|
-
|
372
|
+
|
371
373
|
it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
|
372
374
|
lambda { pickle_parser.parse_fields('author: user "JIM"') }.should raise_error
|
373
375
|
end
|
374
|
-
|
376
|
+
|
375
377
|
it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
|
376
378
|
pickle_parser.parse_fields('author: the user').should == {"author" => user}
|
377
379
|
end
|
@@ -379,34 +381,34 @@ describe Pickle::Session do
|
|
379
381
|
it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
|
380
382
|
pickle_parser.parse_fields('author: myself').should == {"author" => user}
|
381
383
|
end
|
382
|
-
|
384
|
+
|
383
385
|
it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
|
384
386
|
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' => user, 'approver' => user, 'rating' => '5'}
|
385
387
|
end
|
386
|
-
|
388
|
+
|
387
389
|
it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
|
388
390
|
pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' => user, 'approver' => ""}
|
389
391
|
end
|
390
392
|
end
|
391
|
-
|
393
|
+
|
392
394
|
describe "convert_models_to_attributes(ar_class, :user => <a user>)" do
|
393
395
|
before do
|
394
396
|
user.stub(:is_a?).with(ActiveRecord::Base).and_return(true)
|
395
397
|
end
|
396
|
-
|
398
|
+
|
397
399
|
describe "(when ar_class has column 'user_id')" do
|
398
400
|
let :ar_class do
|
399
|
-
mock('ActiveRecord', :column_names => ['user_id'])
|
401
|
+
mock('ActiveRecord', :column_names => ['user_id'], :const_get => ActiveRecord::Base::PickleAdapter)
|
400
402
|
end
|
401
|
-
|
403
|
+
|
402
404
|
it "should return {'user_id' => <the user.id>}" do
|
403
405
|
convert_models_to_attributes(ar_class, :user => user).should == {'user_id' => user.id}
|
404
406
|
end
|
405
407
|
end
|
406
|
-
|
408
|
+
|
407
409
|
describe "(when ar_class has columns 'user_id', 'user_type')" do
|
408
410
|
let :ar_class do
|
409
|
-
mock('ActiveRecord', :column_names => ['user_id', 'user_type'])
|
411
|
+
mock('ActiveRecord', :column_names => ['user_id', 'user_type'], :const_get => ActiveRecord::Base::PickleAdapter)
|
410
412
|
end
|
411
413
|
|
412
414
|
it "should return {'user_id' => <the user.id>, 'user_type' => <the user.base_class>}" do
|
@@ -415,7 +417,7 @@ describe Pickle::Session do
|
|
415
417
|
end
|
416
418
|
end
|
417
419
|
end
|
418
|
-
|
420
|
+
|
419
421
|
it "#model!('unknown') should raise informative error message" do
|
420
422
|
lambda { model!('unknown') }.should raise_error("Can't find pickle model: 'unknown' in this scenario")
|
421
423
|
end
|
@@ -423,4 +425,4 @@ describe Pickle::Session do
|
|
423
425
|
it "#created_model!('unknown') should raise informative error message" do
|
424
426
|
lambda { created_model!('unknown') }.should raise_error("Can't find pickle model: 'unknown' in this scenario")
|
425
427
|
end
|
426
|
-
end
|
428
|
+
end
|