pickle 0.2.5 → 0.2.6
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/.gitignore +2 -0
- data/History.txt +7 -0
- data/README.rdoc +7 -10
- data/Rakefile +27 -46
- data/Todo.txt +0 -1
- data/VERSION +1 -1
- data/features/support/env.rb +1 -1
- data/lib/pickle/adapter.rb +18 -10
- data/lib/pickle/email.rb +1 -1
- data/pickle.gemspec +20 -21
- data/spec/{lib/pickle_adapter_spec.rb → pickle/adapter_spec.rb} +39 -20
- data/spec/{lib/pickle_config_spec.rb → pickle/config_spec.rb} +1 -1
- data/spec/{lib/pickle_email_parser_spec.rb → pickle/email/parser_spec.rb} +4 -2
- data/spec/{lib/pickle_email_spec.rb → pickle/email_spec.rb} +8 -4
- data/spec/{lib/pickle_parser_matchers_spec.rb → pickle/parser/matchers_spec.rb} +1 -1
- data/spec/pickle/parser_spec.rb +161 -0
- data/spec/{lib/pickle_path_spec.rb → pickle/path_spec.rb} +35 -26
- data/spec/{lib/pickle_session_spec.rb → pickle/session_spec.rb} +133 -130
- data/spec/{lib/pickle_spec.rb → pickle_spec.rb} +1 -1
- data/spec/spec_helper.rb +5 -37
- metadata +21 -22
- data/garlic.rb +0 -38
- data/spec/lib/pickle_parser_spec.rb +0 -154
@@ -1,4 +1,6 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'pickle/path'
|
2
4
|
|
3
5
|
describe Pickle::Path do
|
4
6
|
include Pickle::Path
|
@@ -15,8 +17,16 @@ describe Pickle::Path do
|
|
15
17
|
|
16
18
|
describe "#path_to_pickle" do
|
17
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
|
+
|
18
28
|
before do
|
19
|
-
stub!(:model).and_return(
|
29
|
+
stub!(:model).and_return(user)
|
20
30
|
end
|
21
31
|
|
22
32
|
it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
|
@@ -27,66 +37,65 @@ describe Pickle::Path do
|
|
27
37
|
end
|
28
38
|
|
29
39
|
it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
|
30
|
-
should_receive(:foo_user_path).with(
|
40
|
+
should_receive(:foo_user_path).with(user).and_return('the path')
|
31
41
|
path_to_pickle('a user', :action => 'foo').should == 'the path'
|
32
42
|
end
|
33
43
|
|
34
44
|
it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
|
35
|
-
should_receive(:foo_user_path).with(
|
45
|
+
should_receive(:foo_user_path).with(user).and_raise(NoMethodError)
|
36
46
|
lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
|
37
47
|
end
|
38
48
|
|
39
49
|
it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
|
40
|
-
should_receive(:user_foo_path).with(
|
50
|
+
should_receive(:user_foo_path).with(user).and_return('the path')
|
41
51
|
path_to_pickle('a user', :segment => 'foo').should == 'the path'
|
42
52
|
end
|
43
53
|
|
44
54
|
it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
|
45
|
-
should_receive(:user_foo_path).with(
|
55
|
+
should_receive(:user_foo_path).with(user).and_raise(NoMethodError)
|
46
56
|
lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
|
47
57
|
end
|
48
58
|
|
49
59
|
it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
|
50
|
-
should_receive(:new_user_comment_path).with(
|
60
|
+
should_receive(:new_user_comment_path).with(user).and_return('the path')
|
51
61
|
path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
|
52
62
|
end
|
53
63
|
|
54
64
|
it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
|
55
|
-
should_receive(:new_user_comment_path).with(
|
65
|
+
should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
|
56
66
|
lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
57
67
|
end
|
58
68
|
|
59
69
|
it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
|
60
|
-
should_receive(:new_user_comment_path).with(
|
70
|
+
should_receive(:new_user_comment_path).with(user).and_return('the path')
|
61
71
|
path_to_pickle('a user', :extra => 'new comment').should == 'the path'
|
62
72
|
end
|
63
73
|
|
64
74
|
it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
|
65
|
-
should_receive(:new_user_comment_path).with(
|
75
|
+
should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
|
66
76
|
lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
67
77
|
end
|
68
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
|
+
|
69
90
|
describe "(private API)" do
|
70
91
|
it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
|
71
|
-
should_receive(:pickle_path_for_resources_action_segment).with([
|
72
|
-
should_receive(:pickle_path_for_resources_action_segment).with([
|
73
|
-
should_receive(:pickle_path_for_resources_action_segment).with([
|
74
|
-
should_receive(:pickle_path_for_resources_action_segment).with([
|
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
|
75
96
|
lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
76
97
|
end
|
77
98
|
end
|
78
99
|
end
|
79
|
-
|
80
|
-
describe "when args is a list of pickle and non pickle models" do
|
81
|
-
before do
|
82
|
-
stub!(:model).with("account").and_return(nil)
|
83
|
-
stub!(:model).with("the user").and_return(@user = mock_model(User))
|
84
|
-
end
|
85
|
-
|
86
|
-
it "('account', 'the user') should return account_user_path(<user>)" do
|
87
|
-
should_receive(:account_user_path).with(@user).and_return("the path")
|
88
|
-
path_to_pickle('account', 'the user').should == 'the path'
|
89
|
-
end
|
90
|
-
end
|
91
100
|
end
|
92
101
|
end
|
@@ -1,31 +1,54 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
# TODO: remove this and push AR stuff into ORM adapter
|
4
|
+
module ActiveRecord
|
5
|
+
class Base
|
6
|
+
end
|
7
|
+
end
|
2
8
|
|
3
9
|
describe Pickle::Session do
|
4
10
|
include Pickle::Session
|
5
11
|
|
12
|
+
let :user_class do
|
13
|
+
mock("User class", :name => 'User')
|
14
|
+
end
|
15
|
+
|
16
|
+
let :user do
|
17
|
+
mock("user", :class => user_class, :id => 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
let :user_factory do
|
21
|
+
Pickle::Adapter::ActiveRecord.new(user_class)
|
22
|
+
end
|
23
|
+
|
24
|
+
before do
|
25
|
+
config.stub(:factories).and_return('user' => user_factory)
|
26
|
+
end
|
27
|
+
|
6
28
|
describe "Pickle::Session proxy missing methods to parser", :shared => true do
|
7
29
|
it "should forward to pickle_parser it responds_to them" do
|
8
|
-
|
9
|
-
|
30
|
+
subject.pickle_parser.should_receive(:parse_model)
|
31
|
+
subject.parse_model
|
10
32
|
end
|
11
33
|
|
12
34
|
it "should raise error if pickle_parser don't know about em" do
|
13
|
-
lambda {
|
35
|
+
lambda { subject.parse_infinity }.should raise_error
|
14
36
|
end
|
15
37
|
end
|
16
38
|
|
17
39
|
describe "including Pickle::Session" do
|
18
|
-
|
19
|
-
|
40
|
+
subject do
|
41
|
+
self
|
20
42
|
end
|
21
43
|
|
22
44
|
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
23
45
|
end
|
24
46
|
|
25
47
|
describe "extending Pickle::Session" do
|
26
|
-
|
27
|
-
|
28
|
-
|
48
|
+
subject do
|
49
|
+
returning Object.new do |object|
|
50
|
+
object.extend Pickle::Session
|
51
|
+
end
|
29
52
|
end
|
30
53
|
|
31
54
|
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
@@ -33,48 +56,53 @@ describe Pickle::Session do
|
|
33
56
|
|
34
57
|
describe "after storing a single user", :shared => true do
|
35
58
|
it "created_models('user') should be array containing the original user" do
|
36
|
-
created_models('user').should == [
|
59
|
+
created_models('user').should == [user]
|
37
60
|
end
|
38
61
|
|
39
62
|
describe "the original user should be retrievable with" do
|
40
63
|
it "created_model('the user')" do
|
41
|
-
created_model('the user').should ==
|
64
|
+
created_model('the user').should == user
|
42
65
|
end
|
43
66
|
|
44
67
|
it "created_model('1st user')" do
|
45
|
-
created_model('1st user').should ==
|
68
|
+
created_model('1st user').should == user
|
46
69
|
end
|
47
70
|
|
48
71
|
it "created_model('last user')" do
|
49
|
-
created_model('last user').should ==
|
72
|
+
created_model('last user').should == user
|
50
73
|
end
|
51
74
|
end
|
52
75
|
|
53
76
|
describe "(found from db)" do
|
77
|
+
let :user_from_db do
|
78
|
+
returning user.dup do |from_db|
|
79
|
+
from_db.stub!(:id).and_return(100)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
54
83
|
before do
|
55
|
-
|
56
|
-
@user.class.should_receive(:find).with(100).and_return(@user_from_db = @user.dup)
|
84
|
+
user_class.should_receive(:find).with(100).and_return(user_from_db)
|
57
85
|
end
|
58
86
|
|
59
87
|
it "models('user') should be array containing user" do
|
60
|
-
models('user').should == [
|
88
|
+
models('user').should == [user_from_db]
|
61
89
|
end
|
62
90
|
|
63
91
|
describe "user should be retrievable with" do
|
64
92
|
it "model('the user')" do
|
65
|
-
model('the user').should ==
|
93
|
+
model('the user').should == user_from_db
|
66
94
|
end
|
67
95
|
|
68
96
|
it "model('1st user')" do
|
69
|
-
model('1st user').should ==
|
97
|
+
model('1st user').should == user_from_db
|
70
98
|
end
|
71
99
|
|
72
100
|
it "model('last user')" do
|
73
|
-
model('last user').should ==
|
101
|
+
model('last user').should == user_from_db
|
74
102
|
end
|
75
103
|
|
76
104
|
it "model!('last user')" do
|
77
|
-
model('last user').should ==
|
105
|
+
model('last user').should == user_from_db
|
78
106
|
end
|
79
107
|
end
|
80
108
|
end
|
@@ -82,61 +110,48 @@ describe Pickle::Session do
|
|
82
110
|
|
83
111
|
describe "#create_model" do
|
84
112
|
before do
|
85
|
-
|
86
|
-
Factory.stub!(:create).and_return(@user)
|
113
|
+
user_factory.stub!(:create).and_return(user)
|
87
114
|
end
|
88
115
|
|
89
116
|
describe "('a user')" do
|
90
|
-
|
117
|
+
it "should call user_factory.create({})" do
|
118
|
+
user_factory.should_receive(:create).with({})
|
91
119
|
create_model('a user')
|
92
120
|
end
|
93
|
-
|
94
|
-
it "should call Factory.create('user', {})" do
|
95
|
-
Factory.should_receive(:create).with('user', {}).and_return(@user)
|
96
|
-
do_create_model
|
97
|
-
end
|
98
121
|
|
99
122
|
describe "after create," do
|
100
|
-
before {
|
123
|
+
before { create_model('a user') }
|
101
124
|
|
102
125
|
it_should_behave_like "after storing a single user"
|
103
126
|
end
|
104
127
|
end
|
105
128
|
|
106
129
|
describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
|
107
|
-
|
130
|
+
it "should call user_factory.create({'foo' => 'bar', 'baz' => 'bing bong'})" do
|
131
|
+
user_factory.should_receive(:create).with({'foo' => 'bar', 'baz' => 'bing bong'})
|
108
132
|
create_model('1 user', 'foo: "bar", baz: "bing bong"')
|
109
133
|
end
|
110
|
-
|
111
|
-
it "should call Factory.create('user', {'foo' => 'bar', 'baz' => 'bing bong'})" do
|
112
|
-
Factory.should_receive(:create).with('user', {'foo' => 'bar', 'baz' => 'bing bong'}).and_return(@user)
|
113
|
-
do_create_model
|
114
|
-
end
|
115
134
|
|
116
135
|
describe "after create," do
|
117
|
-
before {
|
136
|
+
before { create_model('1 user', 'foo: "bar", baz: "bing bong"') }
|
118
137
|
|
119
138
|
it_should_behave_like "after storing a single user"
|
120
139
|
end
|
121
140
|
end
|
122
141
|
|
123
142
|
describe "('an user: \"fred\")" do
|
124
|
-
|
143
|
+
it "should call user_factory.create({})" do
|
144
|
+
user_factory.should_receive(:create).with({})
|
125
145
|
create_model('an user: "fred"')
|
126
146
|
end
|
127
|
-
|
128
|
-
it "should call Factory.create('user', {})" do
|
129
|
-
Factory.should_receive(:create).with('user', {}).and_return(@user)
|
130
|
-
do_create_model
|
131
|
-
end
|
132
147
|
|
133
148
|
describe "after create," do
|
134
|
-
before {
|
149
|
+
before { create_model('an user: "fred"') }
|
135
150
|
|
136
151
|
it_should_behave_like "after storing a single user"
|
137
152
|
|
138
153
|
it "created_model('the user: \"fred\"') should retrieve the user" do
|
139
|
-
created_model('the user: "fred"').should ==
|
154
|
+
created_model('the user: "fred"').should == user
|
140
155
|
end
|
141
156
|
|
142
157
|
it "created_model?('the user: \"shirl\"') should be false" do
|
@@ -150,57 +165,43 @@ describe Pickle::Session do
|
|
150
165
|
end
|
151
166
|
|
152
167
|
describe "with hash" do
|
153
|
-
|
168
|
+
it "should call user_factory.create({'foo' => 'bar'})" do
|
169
|
+
user_factory.should_receive(:create).with({'foo' => 'bar'})
|
154
170
|
create_model('a user', {'foo' => 'bar'})
|
155
171
|
end
|
156
|
-
|
157
|
-
it "should call Factory.create('user', {'foo' => 'bar'})" do
|
158
|
-
Factory.should_receive(:create).with('user', {'foo' => 'bar'}).and_return(@user)
|
159
|
-
do_create_model
|
160
|
-
end
|
161
172
|
|
162
173
|
describe "after create," do
|
163
|
-
before {
|
174
|
+
before { create_model('a user', {'foo' => 'bar'}) }
|
164
175
|
|
165
176
|
it_should_behave_like "after storing a single user"
|
166
177
|
end
|
167
178
|
end
|
168
|
-
|
169
179
|
end
|
170
180
|
|
171
181
|
describe '#find_model' do
|
172
182
|
before do
|
173
|
-
|
174
|
-
User.stub!(:find).and_return(@user)
|
183
|
+
user_class.stub!(:find).and_return(user)
|
175
184
|
end
|
176
185
|
|
177
|
-
|
186
|
+
it "should call user_class.find :first, :conditions => {<fields>}" do
|
187
|
+
user_class.should_receive(:find).with(:first, :conditions => {'hair' => 'pink'})
|
178
188
|
find_model('a user', 'hair: "pink"')
|
179
189
|
end
|
180
190
|
|
181
|
-
it "should call User.find :first, :conditions => {'hair' => 'pink'}" do
|
182
|
-
User.should_receive(:find).with(:first, :conditions => {'hair' => 'pink'}).and_return(@user)
|
183
|
-
do_find_model
|
184
|
-
end
|
185
|
-
|
186
191
|
describe "after find," do
|
187
|
-
before {
|
192
|
+
before { find_model('a user', 'hair: "pink"') }
|
188
193
|
|
189
194
|
it_should_behave_like "after storing a single user"
|
190
195
|
end
|
191
196
|
|
192
197
|
describe "with hash" do
|
193
|
-
|
198
|
+
it "should call user_class.find('user', {'foo' => 'bar'})" do
|
199
|
+
user_class.should_receive(:find).with(:first, :conditions => {'foo' => 'bar'})
|
194
200
|
find_model('a user', {'foo' => 'bar'})
|
195
201
|
end
|
196
|
-
|
197
|
-
it "should call User.find('user', {'foo' => 'bar'})" do
|
198
|
-
User.should_receive(:find).with(:first, :conditions => {'foo' => 'bar'}).and_return(@user)
|
199
|
-
do_create_model
|
200
|
-
end
|
201
202
|
|
202
203
|
describe "after find," do
|
203
|
-
before {
|
204
|
+
before { find_model('a user', {'foo' => 'bar'}) }
|
204
205
|
|
205
206
|
it_should_behave_like "after storing a single user"
|
206
207
|
end
|
@@ -209,45 +210,45 @@ describe Pickle::Session do
|
|
209
210
|
|
210
211
|
describe "create and find using plural_factory and table" do
|
211
212
|
context "when given a table without a matching pickle ref column" do
|
212
|
-
|
213
|
-
|
213
|
+
let :table do
|
214
|
+
mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
|
214
215
|
end
|
215
216
|
|
216
217
|
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
|
217
218
|
should_receive(:create_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
218
219
|
should_receive(:create_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
219
|
-
create_models_from_table("users",
|
220
|
+
create_models_from_table("users", table).should == [:fred, :betty]
|
220
221
|
end
|
221
222
|
|
222
223
|
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
|
223
224
|
should_receive(:find_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
224
225
|
should_receive(:find_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
225
|
-
find_models_from_table("users",
|
226
|
+
find_models_from_table("users", table).should == [:fred, :betty]
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
229
230
|
context "when given a table with a matching pickle ref column" do
|
230
|
-
|
231
|
-
|
231
|
+
let :table do
|
232
|
+
mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
|
232
233
|
end
|
233
234
|
|
234
235
|
it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with labelled pickle ref" do
|
235
236
|
should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
236
237
|
should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
237
|
-
create_models_from_table("users",
|
238
|
+
create_models_from_table("users", table).should == [:fred, :betty]
|
238
239
|
end
|
239
240
|
|
240
241
|
it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with labelled pickle ref" do
|
241
242
|
should_receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
242
243
|
should_receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
243
|
-
find_models_from_table("users",
|
244
|
+
find_models_from_table("users", table).should == [:fred, :betty]
|
244
245
|
end
|
245
246
|
end
|
246
247
|
end
|
247
248
|
|
248
249
|
describe "#find_model!" do
|
249
250
|
it "should call find_model" do
|
250
|
-
should_receive(:find_model).with('name', 'fields').and_return(
|
251
|
+
should_receive(:find_model).with('name', 'fields').and_return(user)
|
251
252
|
find_model!('name', 'fields')
|
252
253
|
end
|
253
254
|
|
@@ -259,32 +260,34 @@ describe Pickle::Session do
|
|
259
260
|
|
260
261
|
describe "#find_models" do
|
261
262
|
before do
|
262
|
-
|
263
|
-
User.stub!(:find).and_return([@user])
|
264
|
-
end
|
265
|
-
|
266
|
-
def do_find_models
|
267
|
-
find_models('user', 'hair: "pink"')
|
263
|
+
user_class.stub!(:find).and_return([user])
|
268
264
|
end
|
269
265
|
|
270
266
|
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
271
|
-
|
272
|
-
|
267
|
+
user_class.should_receive(:find).with(:all, :conditions => {'hair' => 'pink'})
|
268
|
+
find_models('user', 'hair: "pink"')
|
273
269
|
end
|
274
270
|
|
275
271
|
describe "after find," do
|
276
|
-
before {
|
272
|
+
before { find_models('user', 'hair: "pink"') }
|
277
273
|
|
278
274
|
it_should_behave_like "after storing a single user"
|
279
275
|
end
|
280
276
|
end
|
281
277
|
|
282
|
-
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\'' do
|
278
|
+
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
|
279
|
+
let(:fred) { mock("fred", :class => user_class, :id => 2) }
|
280
|
+
let(:shirl) { mock("shirl", :class => user_class, :id => 3) }
|
281
|
+
let(:noname) { mock("noname", :class => user_class, :is => 4) }
|
282
|
+
|
283
|
+
let(:super_admin_factory) do
|
284
|
+
Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :factory_name => :super_admin))
|
285
|
+
end
|
286
|
+
|
283
287
|
before do
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
Factory.stub!(:create).and_return(@fred, @shirl, @noname)
|
288
|
+
config.stub(:factories).and_return(user_factory.name => user_factory, super_admin_factory.name => super_admin_factory)
|
289
|
+
user_factory.stub(:create).and_return(shirl)
|
290
|
+
super_admin_factory.stub(:create).and_return(fred, noname)
|
288
291
|
end
|
289
292
|
|
290
293
|
def do_create_users
|
@@ -294,8 +297,8 @@ describe Pickle::Session do
|
|
294
297
|
end
|
295
298
|
|
296
299
|
it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
|
297
|
-
|
298
|
-
|
300
|
+
super_admin_factory.should_receive(:create).with({}).twice
|
301
|
+
user_factory.should_receive(:create).with({}).once
|
299
302
|
do_create_users
|
300
303
|
end
|
301
304
|
|
@@ -304,45 +307,45 @@ describe Pickle::Session do
|
|
304
307
|
do_create_users
|
305
308
|
end
|
306
309
|
|
307
|
-
it "created_models('user') should == [
|
308
|
-
created_models('user').should == [
|
310
|
+
it "created_models('user') should == [fred, shirl, noname]" do
|
311
|
+
created_models('user').should == [fred, shirl, noname]
|
309
312
|
end
|
310
313
|
|
311
|
-
it "created_models('super_admin') should == [
|
312
|
-
created_models('super_admin').should == [
|
314
|
+
it "created_models('super_admin') should == [fred, noname]" do
|
315
|
+
created_models('super_admin').should == [fred, noname]
|
313
316
|
end
|
314
317
|
|
315
318
|
describe "#created_model" do
|
316
|
-
it "'that user' should be
|
317
|
-
created_model('that user').should ==
|
319
|
+
it "'that user' should be noname (the last user created - as super_admins are users)" do
|
320
|
+
created_model('that user').should == noname
|
318
321
|
end
|
319
322
|
|
320
|
-
it "'the super admin' should be
|
321
|
-
created_model('that super admin').should ==
|
323
|
+
it "'the super admin' should be noname (the last super admin created)" do
|
324
|
+
created_model('that super admin').should == noname
|
322
325
|
end
|
323
326
|
|
324
|
-
it "'the 1st super admin' should be
|
325
|
-
created_model('the 1st super admin').should ==
|
327
|
+
it "'the 1st super admin' should be fred" do
|
328
|
+
created_model('the 1st super admin').should == fred
|
326
329
|
end
|
327
330
|
|
328
|
-
it "'the first user' should be
|
329
|
-
created_model('the first user').should ==
|
331
|
+
it "'the first user' should be fred" do
|
332
|
+
created_model('the first user').should == fred
|
330
333
|
end
|
331
334
|
|
332
|
-
it "'the 2nd user' should be
|
333
|
-
created_model('the 2nd user').should ==
|
335
|
+
it "'the 2nd user' should be shirl" do
|
336
|
+
created_model('the 2nd user').should == shirl
|
334
337
|
end
|
335
338
|
|
336
|
-
it "'the last user' should be
|
337
|
-
created_model('the last user').should ==
|
339
|
+
it "'the last user' should be noname" do
|
340
|
+
created_model('the last user').should == noname
|
338
341
|
end
|
339
342
|
|
340
|
-
it "'the user: \"fred\" should be
|
341
|
-
created_model('the user: "fred"').should ==
|
343
|
+
it "'the user: \"fred\" should be fred" do
|
344
|
+
created_model('the user: "fred"').should == fred
|
342
345
|
end
|
343
346
|
|
344
|
-
it "'the user: \"shirl\" should be
|
345
|
-
created_model('the user: "shirl"').should ==
|
347
|
+
it "'the user: \"shirl\" should be shirl" do
|
348
|
+
created_model('the user: "shirl"').should == shirl
|
346
349
|
end
|
347
350
|
end
|
348
351
|
end
|
@@ -350,19 +353,19 @@ describe Pickle::Session do
|
|
350
353
|
|
351
354
|
describe "when 'the user: \"me\"' exists and there is a mapping from 'I', 'myself' => 'user: \"me\"" do
|
352
355
|
before do
|
353
|
-
@user = mock_model(User)
|
354
|
-
User.stub!(:find).and_return(@user)
|
355
|
-
Factory.stub!(:create).and_return(@user)
|
356
356
|
self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
|
357
|
+
config.stub(:factories).and_return('user' => user_factory)
|
358
|
+
user_class.stub!(:find).and_return(user)
|
359
|
+
user_factory.stub!(:create).and_return(user)
|
357
360
|
create_model('the user: "me"')
|
358
361
|
end
|
359
362
|
|
360
363
|
it 'model("I") should return the user' do
|
361
|
-
model('I').should ==
|
364
|
+
model('I').should == user
|
362
365
|
end
|
363
366
|
|
364
367
|
it 'model("myself") should return the user' do
|
365
|
-
model('myself').should ==
|
368
|
+
model('myself').should == user
|
366
369
|
end
|
367
370
|
|
368
371
|
it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
|
@@ -370,44 +373,44 @@ describe Pickle::Session do
|
|
370
373
|
end
|
371
374
|
|
372
375
|
it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
|
373
|
-
pickle_parser.parse_fields('author: the user').should == {"author" =>
|
376
|
+
pickle_parser.parse_fields('author: the user').should == {"author" => user}
|
374
377
|
end
|
375
378
|
|
376
379
|
it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
|
377
|
-
pickle_parser.parse_fields('author: myself').should == {"author" =>
|
380
|
+
pickle_parser.parse_fields('author: myself').should == {"author" => user}
|
378
381
|
end
|
379
382
|
|
380
383
|
it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
|
381
|
-
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' =>
|
384
|
+
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' => user, 'approver' => user, 'rating' => '5'}
|
382
385
|
end
|
383
386
|
|
384
387
|
it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
|
385
|
-
pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' =>
|
388
|
+
pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' => user, 'approver' => ""}
|
386
389
|
end
|
387
390
|
end
|
388
391
|
|
389
392
|
describe "convert_models_to_attributes(ar_class, :user => <a user>)" do
|
390
|
-
before do
|
391
|
-
|
393
|
+
before do
|
394
|
+
user.stub(:is_a?).with(ActiveRecord::Base).and_return(true)
|
392
395
|
end
|
393
396
|
|
394
397
|
describe "(when ar_class has column 'user_id')" do
|
395
|
-
|
396
|
-
|
398
|
+
let :ar_class do
|
399
|
+
mock('ActiveRecord', :column_names => ['user_id'])
|
397
400
|
end
|
398
401
|
|
399
402
|
it "should return {'user_id' => <the user.id>}" do
|
400
|
-
convert_models_to_attributes(
|
403
|
+
convert_models_to_attributes(ar_class, :user => user).should == {'user_id' => user.id}
|
401
404
|
end
|
402
405
|
end
|
403
406
|
|
404
407
|
describe "(when ar_class has columns 'user_id', 'user_type')" do
|
405
|
-
|
406
|
-
|
408
|
+
let :ar_class do
|
409
|
+
mock('ActiveRecord', :column_names => ['user_id', 'user_type'])
|
407
410
|
end
|
408
411
|
|
409
412
|
it "should return {'user_id' => <the user.id>, 'user_type' => <the user.type>}" do
|
410
|
-
convert_models_to_attributes(
|
413
|
+
convert_models_to_attributes(ar_class, :user => user).should == {'user_id' => user.id, 'user_type' => user.class.name}
|
411
414
|
end
|
412
415
|
end
|
413
416
|
end
|