ianwhite-pickle 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +38 -1
- data/Todo.txt +2 -0
- data/lib/pickle/adapter.rb +5 -2
- data/lib/pickle/config.rb +5 -8
- data/lib/pickle/email/parser.rb +18 -0
- data/lib/pickle/email/world.rb +17 -0
- data/lib/pickle/email.rb +36 -0
- data/lib/pickle/parser/matchers.rb +4 -4
- data/lib/pickle/parser.rb +3 -3
- data/lib/pickle/path/world.rb +8 -0
- data/lib/pickle/path.rb +44 -0
- data/lib/pickle/{parser/with_session.rb → session/parser.rb} +2 -2
- data/lib/pickle/session.rb +61 -32
- data/lib/pickle/version.rb +1 -1
- data/lib/pickle/world.rb +12 -0
- data/lib/pickle.rb +2 -13
- data/rails_generators/pickle/pickle_generator.rb +20 -7
- data/rails_generators/pickle/templates/env.rb +5 -3
- data/rails_generators/pickle/templates/pickle_email_steps.rb +50 -0
- data/rails_generators/pickle/templates/pickle_path_steps.rb +53 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +1 -2
- data/spec/lib/pickle_adapter_spec.rb +10 -2
- data/spec/lib/pickle_config_spec.rb +4 -8
- data/spec/lib/pickle_email_parser_spec.rb +49 -0
- data/spec/lib/pickle_email_spec.rb +131 -0
- data/spec/lib/pickle_path_spec.rb +68 -0
- data/spec/lib/pickle_session_spec.rb +68 -53
- metadata +17 -6
- data/lib/pickle/injector.rb +0 -18
- data/spec/lib/pickle_injector_spec.rb +0 -22
@@ -17,12 +17,11 @@ end
|
|
17
17
|
|
18
18
|
# find exactly n models
|
19
19
|
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
20
|
-
clear_models(plural_factory.singularize)
|
21
20
|
find_models(plural_factory.singularize, fields).size.should == count.to_i
|
22
21
|
end
|
23
22
|
|
24
23
|
# assert model is in another model's has_many assoc
|
25
|
-
Then(/^#{capture_model} should be in #{capture_model}'s (\w+)$/) do |target, owner, association|
|
24
|
+
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
|
26
25
|
model(owner).send(association).should include(model(target))
|
27
26
|
end
|
28
27
|
|
@@ -9,8 +9,16 @@ describe Pickle::Adapter do
|
|
9
9
|
lambda{ Pickle::Adapter.new.create }.should raise_error(NotImplementedError)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
if defined?(CGI::Session::ActiveRecordStore::Session)
|
13
|
+
it ".model_classes should not include CGI::Session::ActiveRecordStore::Session" do
|
14
|
+
Pickle::Adapter.model_classes.should_not include(CGI::Session::ActiveRecordStore)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if defined?(ActiveRecord::SessionStore::Session)
|
19
|
+
it ".model_classes should not include ActiveRecord::SessionStore::Session" do
|
20
|
+
Pickle::Adapter.model_classes.should_not include(ActiveRecord::SessionStore::Session)
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
describe '::ActiveRecord' do
|
@@ -48,17 +48,12 @@ describe Pickle::Config do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
it "#factory_names should be keys of #factories" do
|
52
|
-
@config.should_receive(:factories).and_return('one' => nil, 'two' => nil)
|
53
|
-
@config.factory_names.sort.should == ['one', 'two'].sort
|
54
|
-
end
|
55
|
-
|
56
51
|
it "#mappings should default to []" do
|
57
52
|
@config.mappings.should == []
|
58
53
|
end
|
59
54
|
|
60
55
|
describe '#predicates' do
|
61
|
-
it "should be list of all ? public instance methods + columns methods of Adapter.model_classes" do
|
56
|
+
it "should be list of all non object ? public instance methods + columns methods of Adapter.model_classes" do
|
62
57
|
class1 = mock('Class1', :public_instance_methods => ['nope', 'foo?', 'bar?'], :column_names => ['one', 'two'])
|
63
58
|
class2 = mock('Class2', :public_instance_methods => ['not', 'foo?', 'faz?'], :column_names => ['two', 'three'])
|
64
59
|
Pickle::Adapter.stub!(:model_classes).and_return([class1, class2])
|
@@ -87,8 +82,9 @@ describe Pickle::Config do
|
|
87
82
|
@config.map 'foo', 'bar', :to => 'faz'
|
88
83
|
end
|
89
84
|
|
90
|
-
it "should create
|
91
|
-
@config.mappings.first.should == OpenStruct.new(:search => '
|
85
|
+
it "should create 2 mappings" do
|
86
|
+
@config.mappings.first.should == OpenStruct.new(:search => 'foo', :replace => 'faz')
|
87
|
+
@config.mappings.last.should == OpenStruct.new(:search => 'bar', :replace => 'faz')
|
92
88
|
end
|
93
89
|
end
|
94
90
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Pickle::Email::Parser do
|
4
|
+
include Pickle::Parser::Matchers
|
5
|
+
include Pickle::Email::Parser
|
6
|
+
|
7
|
+
describe "#match_email" do
|
8
|
+
it "should match 'the email'" do
|
9
|
+
'the email'.should match(/^#{match_email}$/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should match 'the first email'" do
|
13
|
+
'the first email'.should match(/^#{match_email}$/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should match 'the last email'" do
|
17
|
+
'the last email'.should match(/^#{match_email}$/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should match 'the 3rd email'" do
|
21
|
+
'the 3rd email'.should match(/^#{match_email}$/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should match 'an email'" do
|
25
|
+
'an email'.should match(/^#{match_email}$/)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#capture_email should just capture match_email" do
|
30
|
+
capture_email.should == "(#{match_email})"
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#capture_index_in_email" do
|
34
|
+
it "should extract the '2nd' from 'the 2nd email'" do
|
35
|
+
match = 'the 2nd email'.match(/^#{capture_index_in_email}$/)
|
36
|
+
match[1].should == '2nd'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should extract nil from 'the email'" do
|
40
|
+
match = 'the email'.match(/^#{capture_index_in_email}$/)
|
41
|
+
match[1].should == nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should extract the 'last' from 'the last email'" do
|
45
|
+
match = 'the last email'.match(/^#{capture_index_in_email}$/)
|
46
|
+
match[1].should == 'last'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Pickle::Email do
|
4
|
+
include Pickle::Session
|
5
|
+
include Pickle::Email
|
6
|
+
include Pickle::Email::Parser
|
7
|
+
|
8
|
+
before do
|
9
|
+
@email1 = mock("Email 1")
|
10
|
+
@email2 = mock("Email 2")
|
11
|
+
ActionMailer::Base.stub!(:deliveries).and_return([@email1, @email2])
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#emails" do
|
15
|
+
it "should return ordered deliveries" do
|
16
|
+
emails.should == [@email1, @email2]
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "(after)" do
|
20
|
+
before do
|
21
|
+
emails
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#email('the email') should return the last delivery" do
|
25
|
+
email('the email').should == @email2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#email('the 1st email') should return the first delivery" do
|
29
|
+
email('the 1st email').should == @email1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#email('the first email') should return the first delivery" do
|
33
|
+
email('the first email').should == @email1
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#email('the 2nd email') should return the second delivery" do
|
37
|
+
email('the 2nd email').should == @email2
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#email('the last email') should return the second delivery" do
|
41
|
+
email('the last email').should == @email2
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#email2('the 3rd email') should be nil" do
|
45
|
+
email('the 3rd email').should == nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "when email1 is to fred & joe, and email2 is to joe" do
|
50
|
+
before do
|
51
|
+
@email1.stub!(:to).and_return(['fred@gmail.com', 'joe@gmail.com'])
|
52
|
+
@email2.stub!(:to).and_return('joe@gmail.com')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "#emails('to: \"fred@gmail.com\"') should just return email1" do
|
56
|
+
emails('to: "fred@gmail.com"').should == [@email1]
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "after #emails('to: \"fred@gmail.com\"')" do
|
60
|
+
before do
|
61
|
+
emails('to: "fred@gmail.com"')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "#email('first') should be #email('last')" do
|
65
|
+
email('first email').should == email('last email')
|
66
|
+
email('first email').should == @email1
|
67
|
+
end
|
68
|
+
|
69
|
+
it "#email('the email', 'to: \"blah\") should be nil" do
|
70
|
+
email('the email', 'to: "blah"').should == nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "#email('the email', 'to: \"fred@gmail.com\") should be email1" do
|
74
|
+
email('the email', 'to: "fred@gmail.com"').should == @email1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "#emails('to: \"joe@gmail.com\"') should return both emails" do
|
79
|
+
emails('to: "joe@gmail.com"').should == [@email1, @email2]
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "and emails have subjects 'email1', 'email2'" do
|
83
|
+
before do
|
84
|
+
@email1.stub!(:subject).and_return('email1')
|
85
|
+
@email2.stub!(:subject).and_return('email2')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "#emails('to: \"joe@gmail.com\", subject: \"email1\"') should return email1" do
|
89
|
+
emails('to: "joe@gmail.com", subject: "email1"').should == [@email1]
|
90
|
+
end
|
91
|
+
|
92
|
+
it "#emails('to: \"fred@gmail.com\", subject: \"email2\"') should return empty array" do
|
93
|
+
emails('to: "fred@gmail.com", subject: "email2"').should == []
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#save_and_open_emails" do
|
100
|
+
before do
|
101
|
+
stub!(:open_in_browser)
|
102
|
+
stub!(:emails).and_return(["Contents of Email 1"])
|
103
|
+
@now = "2008-01-01".to_time
|
104
|
+
Time.stub!(:now).and_return(@now)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should call #emails to get emails" do
|
108
|
+
should_receive(:emails).and_return([])
|
109
|
+
save_and_open_emails
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "when emails have been already been found" do
|
113
|
+
before { @emails = [] }
|
114
|
+
|
115
|
+
it "should not call #emails" do
|
116
|
+
should_not_receive(:emails)
|
117
|
+
save_and_open_emails
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should create a file in Rails/tmp with the emails in it" do
|
122
|
+
save_and_open_emails
|
123
|
+
File.read("#{RAILS_ROOT}/tmp/webrat-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should call open_in_browser on created tmp file" do
|
127
|
+
should_receive(:open_in_browser).with("#{RAILS_ROOT}/tmp/webrat-email-#{@now.to_i}.html")
|
128
|
+
save_and_open_emails
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
|
+
|
3
|
+
describe Pickle::Path do
|
4
|
+
include Pickle::Path
|
5
|
+
|
6
|
+
before do
|
7
|
+
stub!(:model).and_return(@user = mock_model(User))
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#pickle_path" do
|
11
|
+
it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
|
12
|
+
should_receive(:model).with('a user')
|
13
|
+
should_receive(:model).with('the user: "fred"')
|
14
|
+
stub!(:user_user_path).and_return('the path')
|
15
|
+
pickle_path 'a user', 'the user: "fred"'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
|
19
|
+
should_receive(:foo_user_path).with(@user).and_return('the path')
|
20
|
+
pickle_path('a user', :action => 'foo').should == 'the path'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
|
24
|
+
should_receive(:foo_user_path).with(@user).and_raise(NoMethodError)
|
25
|
+
lambda { pickle_path('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
|
29
|
+
should_receive(:user_foo_path).with(@user).and_return('the path')
|
30
|
+
pickle_path('a user', :segment => 'foo').should == 'the path'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
|
34
|
+
should_receive(:user_foo_path).with(@user).and_raise(NoMethodError)
|
35
|
+
lambda { pickle_path('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
|
39
|
+
should_receive(:new_user_comment_path).with(@user).and_return('the path')
|
40
|
+
pickle_path('a user', :segment => 'comment', :action => 'new').should == 'the path'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
|
44
|
+
should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
|
45
|
+
lambda { pickle_path('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
|
49
|
+
should_receive(:new_user_comment_path).with(@user).and_return('the path')
|
50
|
+
pickle_path('a user', :extra => 'new comment').should == 'the path'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
|
54
|
+
should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
|
55
|
+
lambda { pickle_path('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "(private API)" do
|
59
|
+
it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
|
60
|
+
should_receive(:pickle_path_for_models_action_segment).with([@user], '', 'new_ish_comment').once
|
61
|
+
should_receive(:pickle_path_for_models_action_segment).with([@user], 'new', 'ish_comment').once
|
62
|
+
should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish', 'comment').once
|
63
|
+
should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish_comment', '').once
|
64
|
+
lambda { pickle_path('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,26 +1,52 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
|
2
2
|
|
3
3
|
describe Pickle::Session do
|
4
|
-
|
5
|
-
|
4
|
+
include Pickle::Session
|
5
|
+
|
6
|
+
describe "Pickle::Session proxy missing methods to parser", :shared => true do
|
7
|
+
it "should forward to pickle_parser it responds_to them" do
|
8
|
+
@it.pickle_parser.should_receive(:parse_model)
|
9
|
+
@it.parse_model
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error if pickle_parser don't know about em" do
|
13
|
+
lambda { @it.parse_infinity }.should raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "including Pickle::Session" do
|
18
|
+
before do
|
19
|
+
@it = self
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "extending Pickle::Session" do
|
26
|
+
before do
|
27
|
+
@it = Object.new
|
28
|
+
@it.extend Pickle::Session
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like "Pickle::Session proxy missing methods to parser"
|
6
32
|
end
|
7
33
|
|
8
34
|
describe "after storing a single user", :shared => true do
|
9
35
|
it "created_models('user') should be array containing the original user" do
|
10
|
-
|
36
|
+
created_models('user').should == [@user]
|
11
37
|
end
|
12
38
|
|
13
39
|
describe "the original user should be retrievable with" do
|
14
40
|
it "created_model('the user')" do
|
15
|
-
|
41
|
+
created_model('the user').should == @user
|
16
42
|
end
|
17
43
|
|
18
44
|
it "created_model('1st user')" do
|
19
|
-
|
45
|
+
created_model('1st user').should == @user
|
20
46
|
end
|
21
47
|
|
22
48
|
it "created_model('last user')" do
|
23
|
-
|
49
|
+
created_model('last user').should == @user
|
24
50
|
end
|
25
51
|
end
|
26
52
|
|
@@ -31,20 +57,20 @@ describe Pickle::Session do
|
|
31
57
|
end
|
32
58
|
|
33
59
|
it "models('user') should be array containing user" do
|
34
|
-
|
60
|
+
models('user').should == [@user_from_db]
|
35
61
|
end
|
36
62
|
|
37
63
|
describe "user should be retrievable with" do
|
38
64
|
it "model('the user')" do
|
39
|
-
|
65
|
+
model('the user').should == @user_from_db
|
40
66
|
end
|
41
67
|
|
42
68
|
it "model('1st user')" do
|
43
|
-
|
69
|
+
model('1st user').should == @user_from_db
|
44
70
|
end
|
45
71
|
|
46
72
|
it "model('last user')" do
|
47
|
-
|
73
|
+
model('last user').should == @user_from_db
|
48
74
|
end
|
49
75
|
end
|
50
76
|
end
|
@@ -58,7 +84,7 @@ describe Pickle::Session do
|
|
58
84
|
|
59
85
|
describe "('a user')" do
|
60
86
|
def do_create_model
|
61
|
-
|
87
|
+
create_model('a user')
|
62
88
|
end
|
63
89
|
|
64
90
|
it "should call Factory.create('user', {})" do
|
@@ -75,7 +101,7 @@ describe Pickle::Session do
|
|
75
101
|
|
76
102
|
describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
|
77
103
|
def do_create_model
|
78
|
-
|
104
|
+
create_model('1 user', 'foo: "bar", baz: "bing bong"')
|
79
105
|
end
|
80
106
|
|
81
107
|
it "should call Factory.create('user', {'foo' => 'bar', 'baz' => 'bing bong'})" do
|
@@ -92,7 +118,7 @@ describe Pickle::Session do
|
|
92
118
|
|
93
119
|
describe "('an user: \"fred\")" do
|
94
120
|
def do_create_model
|
95
|
-
|
121
|
+
create_model('an user: "fred"')
|
96
122
|
end
|
97
123
|
|
98
124
|
it "should call Factory.create('user', {})" do
|
@@ -106,15 +132,15 @@ describe Pickle::Session do
|
|
106
132
|
it_should_behave_like "after storing a single user"
|
107
133
|
|
108
134
|
it "created_model('the user: \"fred\"') should retrieve the user" do
|
109
|
-
|
135
|
+
created_model('the user: "fred"').should == @user
|
110
136
|
end
|
111
137
|
|
112
138
|
it "created_model?('the user: \"shirl\"') should be false" do
|
113
|
-
|
139
|
+
created_model?('the user: "shirl"').should == false
|
114
140
|
end
|
115
141
|
|
116
142
|
it "model?('the user: \"shirl\"') should be false" do
|
117
|
-
|
143
|
+
model?('the user: "shirl"').should == false
|
118
144
|
end
|
119
145
|
end
|
120
146
|
end
|
@@ -127,7 +153,7 @@ describe Pickle::Session do
|
|
127
153
|
end
|
128
154
|
|
129
155
|
def do_find_model
|
130
|
-
|
156
|
+
find_model('a user', 'hair: "pink"')
|
131
157
|
end
|
132
158
|
|
133
159
|
it "should call User.find :first, :conditions => {'hair' => 'pink'}" do
|
@@ -149,7 +175,7 @@ describe Pickle::Session do
|
|
149
175
|
end
|
150
176
|
|
151
177
|
def do_find_models
|
152
|
-
|
178
|
+
find_models('user', 'hair: "pink"')
|
153
179
|
end
|
154
180
|
|
155
181
|
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
@@ -163,16 +189,6 @@ describe Pickle::Session do
|
|
163
189
|
it_should_behave_like "after storing a single user"
|
164
190
|
end
|
165
191
|
end
|
166
|
-
|
167
|
-
describe '#clear_models(<factory_name>)' do
|
168
|
-
it "should clear the storage for that factory name" do
|
169
|
-
@session.send :store_model, 'user', nil, mock('user')
|
170
|
-
@session.send :store_model, 'car', nil, mock('user')
|
171
|
-
@session.clear_models('user')
|
172
|
-
@session.created_models('user').size.should == 0
|
173
|
-
@session.created_models('car').size.should == 1
|
174
|
-
end
|
175
|
-
end
|
176
192
|
|
177
193
|
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\'' do
|
178
194
|
before do
|
@@ -183,9 +199,9 @@ describe Pickle::Session do
|
|
183
199
|
end
|
184
200
|
|
185
201
|
def do_create_users
|
186
|
-
|
187
|
-
|
188
|
-
|
202
|
+
create_model('a super admin: "fred"')
|
203
|
+
create_model('a user: "shirl"')
|
204
|
+
create_model('1 super_admin')
|
189
205
|
end
|
190
206
|
|
191
207
|
it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
|
@@ -200,44 +216,44 @@ describe Pickle::Session do
|
|
200
216
|
end
|
201
217
|
|
202
218
|
it "created_models('user') should == [@fred, @shirl, @noname]" do
|
203
|
-
|
219
|
+
created_models('user').should == [@fred, @shirl, @noname]
|
204
220
|
end
|
205
221
|
|
206
222
|
it "created_models('super_admin') should == [@fred, @noname]" do
|
207
|
-
|
223
|
+
created_models('super_admin').should == [@fred, @noname]
|
208
224
|
end
|
209
225
|
|
210
226
|
describe "#created_model" do
|
211
227
|
it "'that user' should be @noname (the last user created - as super_admins are users)" do
|
212
|
-
|
228
|
+
created_model('that user').should == @noname
|
213
229
|
end
|
214
230
|
|
215
231
|
it "'the super admin' should be @noname (the last super admin created)" do
|
216
|
-
|
232
|
+
created_model('that super admin').should == @noname
|
217
233
|
end
|
218
234
|
|
219
235
|
it "'the 1st super admin' should be @fred" do
|
220
|
-
|
236
|
+
created_model('the 1st super admin').should == @fred
|
221
237
|
end
|
222
238
|
|
223
239
|
it "'the first user' should be @fred" do
|
224
|
-
|
240
|
+
created_model('the first user').should == @fred
|
225
241
|
end
|
226
242
|
|
227
243
|
it "'the 2nd user' should be @shirl" do
|
228
|
-
|
244
|
+
created_model('the 2nd user').should == @shirl
|
229
245
|
end
|
230
246
|
|
231
247
|
it "'the last user' should be @noname" do
|
232
|
-
|
248
|
+
created_model('the last user').should == @noname
|
233
249
|
end
|
234
250
|
|
235
251
|
it "'the user: \"fred\" should be @fred" do
|
236
|
-
|
252
|
+
created_model('the user: "fred"').should == @fred
|
237
253
|
end
|
238
254
|
|
239
255
|
it "'the user: \"shirl\" should be @shirl" do
|
240
|
-
|
256
|
+
created_model('the user: "shirl"').should == @shirl
|
241
257
|
end
|
242
258
|
end
|
243
259
|
end
|
@@ -248,37 +264,36 @@ describe Pickle::Session do
|
|
248
264
|
@user = mock_model(User)
|
249
265
|
User.stub!(:find).and_return(@user)
|
250
266
|
Factory.stub!(:create).and_return(@user)
|
251
|
-
|
252
|
-
|
253
|
-
@session.create_model('the user: "me"')
|
267
|
+
self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
|
268
|
+
create_model('the user: "me"')
|
254
269
|
end
|
255
270
|
|
256
271
|
it 'model("I") should return the user' do
|
257
|
-
|
272
|
+
model('I').should == @user
|
258
273
|
end
|
259
274
|
|
260
275
|
it 'model("myself") should return the user' do
|
261
|
-
|
276
|
+
model('myself').should == @user
|
262
277
|
end
|
263
278
|
|
264
279
|
it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
|
265
|
-
lambda {
|
280
|
+
lambda { pickle_parser.parse_fields('author: user "JIM"') }.should raise_error
|
266
281
|
end
|
267
282
|
|
268
283
|
it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
|
269
|
-
|
284
|
+
pickle_parser.parse_fields('author: the user').should == {"author" => @user}
|
270
285
|
end
|
271
286
|
|
272
287
|
it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
|
273
|
-
|
288
|
+
pickle_parser.parse_fields('author: myself').should == {"author" => @user}
|
274
289
|
end
|
275
290
|
|
276
291
|
it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
|
277
|
-
|
292
|
+
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' => @user, 'approver' => @user, 'rating' => '5'}
|
278
293
|
end
|
279
294
|
|
280
295
|
it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
|
281
|
-
|
296
|
+
pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' => @user, 'approver' => ""}
|
282
297
|
end
|
283
298
|
end
|
284
299
|
|
@@ -293,7 +308,7 @@ describe Pickle::Session do
|
|
293
308
|
end
|
294
309
|
|
295
310
|
it "should return {'user_id' => <the user.id>}" do
|
296
|
-
|
311
|
+
convert_models_to_attributes(@ar_class, :user => @user).should == {'user_id' => @user.id}
|
297
312
|
end
|
298
313
|
end
|
299
314
|
|
@@ -303,7 +318,7 @@ describe Pickle::Session do
|
|
303
318
|
end
|
304
319
|
|
305
320
|
it "should return {'user_id' => <the user.id>, 'user_type' => <the user.type>}" do
|
306
|
-
|
321
|
+
convert_models_to_attributes(@ar_class, :user => @user).should == {'user_id' => @user.id, 'user_type' => @user.class.name}
|
307
322
|
end
|
308
323
|
end
|
309
324
|
end
|