pickle 0.4.11 → 0.5.0
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.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile.lock.development +91 -94
- data/History.txt +8 -1
- data/README.rdoc +8 -9
- data/Rakefile.d/cucumber.rake +10 -9
- data/features/app/blueprints.rb +1 -6
- data/features/app/factories.rb +17 -15
- data/features/step_definitions/email_steps.rb +10 -10
- data/features/step_definitions/fork_steps.rb +2 -2
- data/features/step_definitions/generator_steps.rb +15 -9
- data/features/step_definitions/path_steps.rb +3 -3
- data/features/step_definitions/pickle_steps.rb +19 -19
- data/features/step_definitions/raise_error_steps.rb +3 -3
- data/features/support/pickle.rb +0 -1
- data/lib/generators/pickle_generator.rb +1 -26
- data/lib/pickle/adapter.rb +4 -10
- data/lib/pickle/version.rb +2 -2
- data/pickle.gemspec +7 -6
- data/rails_generators/pickle/pickle_generator.rb +2 -4
- data/rails_generators/pickle/templates/email_steps.rb +10 -10
- data/rails_generators/pickle/templates/pickle.rb +0 -1
- data/rails_generators/pickle/templates/pickle_steps.rb +19 -19
- data/spec/pickle/adapter_spec.rb +39 -39
- data/spec/pickle/config_spec.rb +29 -29
- data/spec/pickle/email/parser_spec.rb +9 -9
- data/spec/pickle/email_spec.rb +38 -38
- data/spec/pickle/parser/matchers_spec.rb +8 -8
- data/spec/pickle/parser_spec.rb +34 -34
- data/spec/pickle/path_spec.rb +33 -33
- data/spec/pickle/session_spec.rb +87 -87
- data/spec/pickle_spec.rb +4 -4
- data/spec/spec_helper.rb +73 -3
- metadata +55 -79
@@ -7,9 +7,9 @@ describe Pickle::Parser::Matchers do
|
|
7
7
|
def config
|
8
8
|
@config ||= Pickle::Config.new do |c|
|
9
9
|
c.factories = {
|
10
|
-
'user' =>
|
11
|
-
'car' =>
|
12
|
-
'fast_car' =>
|
10
|
+
'user' => double('factory'),
|
11
|
+
'car' => double('factory'),
|
12
|
+
'fast_car' => double('factory')
|
13
13
|
}
|
14
14
|
c.predicates = %w(name status fancy? super_fancy? has_style? has_super_style?)
|
15
15
|
end
|
@@ -19,7 +19,7 @@ describe Pickle::Parser::Matchers do
|
|
19
19
|
def self.atom_should_match(atom, strings)
|
20
20
|
Array(strings).each do |string|
|
21
21
|
it "#{atom} should match '#{string}'" do
|
22
|
-
string.
|
22
|
+
expect(string).to match(/^#{send atom}$/)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,7 +27,7 @@ describe Pickle::Parser::Matchers do
|
|
27
27
|
def self.atom_should_not_match(atom, strings)
|
28
28
|
Array(strings).each do |string|
|
29
29
|
it "#{atom} should NOT match '#{string}'" do
|
30
|
-
string.
|
30
|
+
expect(string).not_to match(/^#{send atom}$/)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -63,8 +63,8 @@ describe Pickle::Parser::Matchers do
|
|
63
63
|
|
64
64
|
describe "capture methods" do
|
65
65
|
it "capture_field should == '(' + match_field + ')'" do
|
66
|
-
|
67
|
-
capture_field.
|
66
|
+
expect(self).to receive(:match_field).and_return('MATCH_FIELD')
|
67
|
+
expect(capture_field).to eq('(MATCH_FIELD)')
|
68
68
|
end
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
data/spec/pickle/parser_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe Pickle::Parser do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should raise error when created with no config" do
|
9
|
-
|
9
|
+
expect{ Pickle::Parser.new }.to raise_error(ArgumentError)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "when a 'user' factory exists in config" do
|
13
13
|
before do
|
14
|
-
@parser.config.
|
14
|
+
allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'misc regexps' do
|
@@ -21,116 +21,116 @@ describe Pickle::Parser do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should match 'a user exists'" do
|
24
|
-
'a user exists'.
|
24
|
+
expect('a user exists').to match(@regexp)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should caputure 'a user' from 'a user exists'" do
|
28
|
-
'a user exists'.match(@regexp)[1].
|
28
|
+
expect('a user exists'.match(@regexp)[1]).to eq('a user')
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe '#parse_field' do
|
34
34
|
it "should return {'a' => 'b'} for 'a: \"b\"'" do
|
35
|
-
@parser.parse_field('a: "b"').
|
35
|
+
expect(@parser.parse_field('a: "b"')).to eq({'a' => 'b'})
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should raise error for invalid field 'a : b'" do
|
39
|
-
|
39
|
+
expect { @parser.parse_field('a : b') }.to raise_error(ArgumentError)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#parse_fields' do
|
44
44
|
it 'should return {} for blank argument' do
|
45
|
-
@parser.parse_fields(nil).
|
46
|
-
@parser.parse_fields('').
|
45
|
+
expect(@parser.parse_fields(nil)).to eq({})
|
46
|
+
expect(@parser.parse_fields('')).to eq({})
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should raise error for invalid argument' do
|
50
|
-
|
50
|
+
expect { @parser.parse_fields('foo foo') }.to raise_error(ArgumentError)
|
51
51
|
end
|
52
52
|
|
53
53
|
it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
|
54
|
-
@parser.parse_fields('foo: "bar"').
|
54
|
+
expect(@parser.parse_fields('foo: "bar"')).to eq({ "foo" => "bar"})
|
55
55
|
end
|
56
56
|
|
57
57
|
it '(\'foo: "something \"quoted\""\') should == { "foo" => "bar"}' do
|
58
|
-
@parser.parse_fields('foo: "something \"quoted\""').
|
58
|
+
expect(@parser.parse_fields('foo: "something \"quoted\""')).to eq({ "foo" => 'something "quoted"' })
|
59
59
|
end
|
60
60
|
|
61
61
|
it '("bool: true") should == { "bool" => true}' do
|
62
|
-
@parser.parse_fields('bool: true').
|
62
|
+
expect(@parser.parse_fields('bool: true')).to eq({"bool" => true})
|
63
63
|
end
|
64
64
|
|
65
65
|
it '("bool: false") should == { "bool" => false}' do
|
66
|
-
@parser.parse_fields('bool: false').
|
66
|
+
expect(@parser.parse_fields('bool: false')).to eq({"bool" => false})
|
67
67
|
end
|
68
68
|
|
69
69
|
it '("int: 10") should == { "int" => 10 }' do
|
70
|
-
@parser.parse_fields('int: 10').
|
70
|
+
expect(@parser.parse_fields('int: 10')).to eq({"int" => 10})
|
71
71
|
end
|
72
72
|
|
73
73
|
it '("float: 10.1") should == { "float" => 10.1 }' do
|
74
|
-
@parser.parse_fields('float: 10.1').
|
74
|
+
expect(@parser.parse_fields('float: 10.1')).to eq({"float" => 10.1})
|
75
75
|
end
|
76
76
|
|
77
77
|
it '(\'foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
|
78
|
-
@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123').
|
78
|
+
expect(@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123')).to eq({"foo" => "bar", "bar_man" => "wonga wonga", "baz_woman" => "one \"two\" three", "gump" => 123})
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe '#parse_model' do
|
83
83
|
it '("a user") should == ["user", ""]' do
|
84
|
-
@parser.parse_model("a user").
|
84
|
+
expect(@parser.parse_model("a user")).to eq(["user", ""])
|
85
85
|
end
|
86
86
|
|
87
87
|
it '("the user") should == ["user", ""]' do
|
88
|
-
@parser.parse_model("the user").
|
88
|
+
expect(@parser.parse_model("the user")).to eq(["user", ""])
|
89
89
|
end
|
90
90
|
|
91
91
|
it '("1 user") should == ["user", ""]' do
|
92
|
-
@parser.parse_model("1 user").
|
92
|
+
expect(@parser.parse_model("1 user")).to eq(["user", ""])
|
93
93
|
end
|
94
94
|
|
95
95
|
it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
|
96
|
-
@parser.parse_model('an user: "jim jones"').
|
96
|
+
expect(@parser.parse_model('an user: "jim jones"')).to eq(["user", "jim_jones"])
|
97
97
|
end
|
98
98
|
|
99
99
|
it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
|
100
|
-
@parser.parse_model('that user: "herbie"').
|
100
|
+
expect(@parser.parse_model('that user: "herbie"')).to eq(["user", "herbie"])
|
101
101
|
end
|
102
102
|
|
103
103
|
it '(\'the 12th user\') should == ["user", 11]' do
|
104
|
-
@parser.parse_model('the 12th user').
|
104
|
+
expect(@parser.parse_model('the 12th user')).to eq(["user", 11])
|
105
105
|
end
|
106
106
|
|
107
107
|
it '(\'the last user\') should == ["user", -1]' do
|
108
|
-
@parser.parse_model('the last user').
|
108
|
+
expect(@parser.parse_model('the last user')).to eq(["user", -1])
|
109
109
|
end
|
110
110
|
|
111
111
|
it '("the first user") should == ["user", 0]' do
|
112
|
-
@parser.parse_model('the first user').
|
112
|
+
expect(@parser.parse_model('the first user')).to eq(["user", 0])
|
113
113
|
end
|
114
114
|
|
115
115
|
it '("the 1st user") should == ["user", 0]' do
|
116
|
-
@parser.parse_model('the 1st user').
|
116
|
+
expect(@parser.parse_model('the 1st user')).to eq(["user", 0])
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "#parse_index" do
|
121
121
|
it '("1st") should == 0' do
|
122
|
-
@parser.parse_index("1st").
|
122
|
+
expect(@parser.parse_index("1st")).to eq(0)
|
123
123
|
end
|
124
124
|
|
125
125
|
it '("24th") should == 23' do
|
126
|
-
@parser.parse_index("24th").
|
126
|
+
expect(@parser.parse_index("24th")).to eq(23)
|
127
127
|
end
|
128
128
|
it '("first") should == 0' do
|
129
|
-
@parser.parse_index("first").
|
129
|
+
expect(@parser.parse_index("first")).to eq(0)
|
130
130
|
end
|
131
131
|
|
132
132
|
it '("last") should == -1' do
|
133
|
-
@parser.parse_index("last").
|
133
|
+
expect(@parser.parse_index("last")).to eq(-1)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
@@ -142,23 +142,23 @@ describe Pickle::Parser do
|
|
142
142
|
c.map 'I', 'myself', :to => 'user: "me"'
|
143
143
|
end
|
144
144
|
@parser = Pickle::Parser.new(:config => @config)
|
145
|
-
@parser.config.
|
145
|
+
allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
|
146
146
|
end
|
147
147
|
|
148
148
|
it "'I' should match /\#{match_model}/" do
|
149
|
-
'I'.
|
149
|
+
expect('I').to match(/#{@parser.match_model}/)
|
150
150
|
end
|
151
151
|
|
152
152
|
it "'myself' should match /\#{match_model}/" do
|
153
|
-
'myself'.
|
153
|
+
expect('myself').to match(/#{@parser.match_model}/)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "parse_model('I') should == ['user', 'me']" do
|
157
|
-
@parser.parse_model('I').
|
157
|
+
expect(@parser.parse_model('I')).to eq(["user", "me"])
|
158
158
|
end
|
159
159
|
|
160
160
|
it "parse_model('myself') should == ['user', 'me']" do
|
161
|
-
@parser.parse_model('myself').
|
161
|
+
expect(@parser.parse_model('myself')).to eq(["user", "me"])
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
data/spec/pickle/path_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe Pickle::Path do
|
|
7
7
|
|
8
8
|
describe "#path_to_pickle, when the model doesn't exist" do
|
9
9
|
before do
|
10
|
-
|
10
|
+
allow(self).to receive(:model).and_return(nil)
|
11
11
|
end
|
12
12
|
it "('that user', :extra => 'new comment') should raise the error raised by model!" do
|
13
|
-
|
13
|
+
expect { path_to_pickle "that user", "new comment" }.to raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
@@ -18,82 +18,82 @@ describe Pickle::Path do
|
|
18
18
|
describe "#path_to_pickle" do
|
19
19
|
describe "when model returns a user" do
|
20
20
|
let :user_class do
|
21
|
-
|
21
|
+
double 'User', :name => 'User'
|
22
22
|
end
|
23
23
|
|
24
24
|
let :user do
|
25
|
-
|
25
|
+
double 'user', :class => user_class
|
26
26
|
end
|
27
27
|
|
28
28
|
before do
|
29
|
-
|
29
|
+
allow(self).to receive(:model).and_return(user)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
path_to_pickle('a user', 'the user: "fred"').
|
33
|
+
expect(self).to receive(:model).with('a user')
|
34
|
+
expect(self).to receive(:model).with('the user: "fred"')
|
35
|
+
allow(self).to receive(:user_user_path).and_return('the path')
|
36
|
+
expect(path_to_pickle('a user', 'the user: "fred"')).to eq('the path')
|
37
37
|
end
|
38
38
|
|
39
39
|
it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
|
40
|
-
|
41
|
-
path_to_pickle('a user', :action => 'foo').
|
40
|
+
expect(self).to receive(:foo_user_path).with(user).and_return('the path')
|
41
|
+
expect(path_to_pickle('a user', :action => 'foo')).to eq('the path')
|
42
42
|
end
|
43
43
|
|
44
44
|
it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
|
45
|
-
|
46
|
-
|
45
|
+
expect(self).to receive(:foo_user_path).with(user).and_raise(NoMethodError)
|
46
|
+
expect { path_to_pickle('a user', :action => 'foo') }.to raise_error(Exception, /Could not figure out a path for/)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
|
50
|
-
|
51
|
-
path_to_pickle('a user', :segment => 'foo').
|
50
|
+
expect(self).to receive(:user_foo_path).with(user).and_return('the path')
|
51
|
+
expect(path_to_pickle('a user', :segment => 'foo')).to eq('the path')
|
52
52
|
end
|
53
53
|
|
54
54
|
it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
|
55
|
-
|
56
|
-
|
55
|
+
expect(self).to receive(:user_foo_path).with(user).and_raise(NoMethodError)
|
56
|
+
expect { path_to_pickle('a user', :segment => 'foo') }.to raise_error(Exception, /Could not figure out a path for/)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
|
60
|
-
|
61
|
-
path_to_pickle('a user', :segment => 'comment', :action => 'new').
|
60
|
+
expect(self).to receive(:new_user_comment_path).with(user).and_return('the path')
|
61
|
+
expect(path_to_pickle('a user', :segment => 'comment', :action => 'new')).to eq('the path')
|
62
62
|
end
|
63
63
|
|
64
64
|
it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
|
65
|
-
|
66
|
-
|
65
|
+
expect(self).to receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
|
66
|
+
expect { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.to raise_error(Exception, /Could not figure out a path for/)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
|
70
|
-
|
71
|
-
path_to_pickle('a user', :extra => 'new comment').
|
70
|
+
expect(self).to receive(:new_user_comment_path).with(user).and_return('the path')
|
71
|
+
expect(path_to_pickle('a user', :extra => 'new comment')).to eq('the path')
|
72
72
|
end
|
73
73
|
|
74
74
|
it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
|
75
|
-
|
76
|
-
|
75
|
+
expect(self).to receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
|
76
|
+
expect { path_to_pickle('a user', :extra => 'new comment') }.to raise_error(Exception, /Could not figure out a path for/)
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "when args is a list of pickle and non pickle models" do
|
80
80
|
before do
|
81
|
-
|
81
|
+
allow(self).to receive(:model).with("account").and_return(nil)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "('account', 'the user') should return account_user_path(<user>)" do
|
85
|
-
|
86
|
-
path_to_pickle('account', 'the user').
|
85
|
+
expect(self).to receive(:account_user_path).with(user).and_return("the path")
|
86
|
+
expect(path_to_pickle('account', 'the user')).to eq('the path')
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe "(private API)" do
|
91
91
|
it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], '', 'new_ish_comment').once
|
93
|
+
expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new', 'ish_comment').once
|
94
|
+
expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish', 'comment').once
|
95
|
+
expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish_comment', '').once
|
96
|
+
expect { path_to_pickle('a user', :extra => 'new ish comment') }.to raise_error(Exception, /Could not figure out a path for/)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
data/spec/pickle/session_spec.rb
CHANGED
@@ -15,11 +15,11 @@ describe Pickle::Session do
|
|
15
15
|
include Pickle::Session
|
16
16
|
|
17
17
|
let :user_class do
|
18
|
-
|
18
|
+
double("User class", :name => 'User')
|
19
19
|
end
|
20
20
|
|
21
21
|
let :user do
|
22
|
-
|
22
|
+
double("user", :class => user_class, :id => 100)
|
23
23
|
end
|
24
24
|
|
25
25
|
let :user_factory do
|
@@ -27,17 +27,17 @@ describe Pickle::Session do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
before do
|
30
|
-
config.
|
30
|
+
allow(config).to receive(:factories).and_return('user' => user_factory)
|
31
31
|
end
|
32
32
|
|
33
33
|
shared_examples_for "Pickle::Session proxy missing methods to parser" do
|
34
34
|
it "should forward to pickle_parser it responds_to them" do
|
35
|
-
subject.pickle_parser.
|
35
|
+
expect(subject.pickle_parser).to receive(:parse_model)
|
36
36
|
subject.parse_model
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should raise error if pickle_parser don't know about em" do
|
40
|
-
|
40
|
+
expect { subject.parse_infinity }.to raise_error
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -59,51 +59,51 @@ describe Pickle::Session do
|
|
59
59
|
|
60
60
|
shared_examples_for "after storing a single user" do
|
61
61
|
it "created_models('user') should be array containing the original user" do
|
62
|
-
created_models('user').
|
62
|
+
expect(created_models('user')).to eq([user])
|
63
63
|
end
|
64
64
|
|
65
65
|
describe "the original user should be retrievable with" do
|
66
66
|
it "created_model('the user')" do
|
67
|
-
created_model('the user').
|
67
|
+
expect(created_model('the user')).to eq(user)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "created_model('1st user')" do
|
71
|
-
created_model('1st user').
|
71
|
+
expect(created_model('1st user')).to eq(user)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "created_model('last user')" do
|
75
|
-
created_model('last user').
|
75
|
+
expect(created_model('last user')).to eq(user)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "(found from db)" do
|
80
80
|
let :user_from_db do
|
81
|
-
user.dup.tap {|from_db| from_db.
|
81
|
+
user.dup.tap {|from_db| allow(from_db).to receive(:id).and_return(100) }
|
82
82
|
end
|
83
83
|
|
84
84
|
before do
|
85
|
-
Pickle::Adapter.
|
85
|
+
allow(Pickle::Adapter).to receive(:get_model).with(user_class, 100).and_return(user_from_db)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "models('user') should be array containing user" do
|
89
|
-
models('user').
|
89
|
+
expect(models('user')).to eq([user_from_db])
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "user should be retrievable with" do
|
93
93
|
it "model('the user')" do
|
94
|
-
model('the user').
|
94
|
+
expect(model('the user')).to eq(user_from_db)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "model('1st user')" do
|
98
|
-
model('1st user').
|
98
|
+
expect(model('1st user')).to eq(user_from_db)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "model('last user')" do
|
102
|
-
model('last user').
|
102
|
+
expect(model('last user')).to eq(user_from_db)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "model!('last user')" do
|
106
|
-
model('last user').
|
106
|
+
expect(model('last user')).to eq(user_from_db)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -111,12 +111,12 @@ describe Pickle::Session do
|
|
111
111
|
|
112
112
|
describe "#create_model" do
|
113
113
|
before do
|
114
|
-
user_factory.
|
114
|
+
allow(user_factory).to receive(:create).and_return(user)
|
115
115
|
end
|
116
116
|
|
117
117
|
describe "('a user')" do
|
118
118
|
it "should call user_factory.create({})" do
|
119
|
-
user_factory.
|
119
|
+
expect(user_factory).to receive(:create).with({})
|
120
120
|
create_model('a user')
|
121
121
|
end
|
122
122
|
|
@@ -129,7 +129,7 @@ describe Pickle::Session do
|
|
129
129
|
|
130
130
|
describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
|
131
131
|
it "should call user_factory.create({'foo' => 'bar', 'baz' => 'bing bong'})" do
|
132
|
-
user_factory.
|
132
|
+
expect(user_factory).to receive(:create).with({'foo' => 'bar', 'baz' => 'bing bong'})
|
133
133
|
create_model('1 user', 'foo: "bar", baz: "bing bong"')
|
134
134
|
end
|
135
135
|
|
@@ -142,7 +142,7 @@ describe Pickle::Session do
|
|
142
142
|
|
143
143
|
describe "('an user: \"fred\")" do
|
144
144
|
it "should call user_factory.create({})" do
|
145
|
-
user_factory.
|
145
|
+
expect(user_factory).to receive(:create).with({})
|
146
146
|
create_model('an user: "fred"')
|
147
147
|
end
|
148
148
|
|
@@ -152,23 +152,23 @@ describe Pickle::Session do
|
|
152
152
|
it_should_behave_like "after storing a single user"
|
153
153
|
|
154
154
|
it "created_model('the user: \"fred\"') should retrieve the user" do
|
155
|
-
created_model('the user: "fred"').
|
155
|
+
expect(created_model('the user: "fred"')).to eq(user)
|
156
156
|
end
|
157
157
|
|
158
158
|
it "created_model?('the user: \"shirl\"') should be false" do
|
159
|
-
created_model?('the user: "shirl"').
|
159
|
+
expect(created_model?('the user: "shirl"')).to eq(false)
|
160
160
|
end
|
161
161
|
|
162
162
|
it "model?('the user: \"shirl\"') should be false" do
|
163
|
-
model?('the user: "shirl"').
|
163
|
+
expect(model?('the user: "shirl"')).to eq(false)
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
describe "with hash" do
|
169
169
|
it "should call user_factory.create({'foo' => 'bar'})" do
|
170
|
-
user_factory.
|
171
|
-
create_model('a user', {'foo' => 'bar'}).
|
170
|
+
expect(user_factory).to receive(:create).with({'foo' => 'bar'})
|
171
|
+
expect(create_model('a user', {'foo' => 'bar'})).to eq(user)
|
172
172
|
end
|
173
173
|
|
174
174
|
describe "after create," do
|
@@ -181,11 +181,11 @@ describe Pickle::Session do
|
|
181
181
|
|
182
182
|
describe '#find_model' do
|
183
183
|
before do
|
184
|
-
Pickle::Adapter.
|
184
|
+
allow(Pickle::Adapter).to receive(:find_first_model).with(user_class, anything).and_return(user)
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should call user_class.find :first, :conditions => {<fields>}" do
|
188
|
-
find_model('a user', 'hair: "pink"').
|
188
|
+
expect(find_model('a user', 'hair: "pink"')).to eq(user)
|
189
189
|
end
|
190
190
|
|
191
191
|
describe "after find," do
|
@@ -210,60 +210,60 @@ describe Pickle::Session do
|
|
210
210
|
describe "create and find using plural_factory and table" do
|
211
211
|
context "when given a table without a matching pickle ref column" do
|
212
212
|
let :table do
|
213
|
-
|
213
|
+
double(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
|
214
214
|
end
|
215
215
|
|
216
216
|
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
|
-
|
219
|
-
create_models_from_table("users", table).
|
217
|
+
expect(self).to receive(:create_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
218
|
+
expect(self).to receive(:create_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
219
|
+
expect(create_models_from_table("users", table)).to eq([:fred, :betty])
|
220
220
|
end
|
221
221
|
|
222
222
|
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
|
-
|
225
|
-
find_models_from_table("users", table).
|
223
|
+
expect(self).to receive(:find_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
|
224
|
+
expect(self).to receive(:find_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
|
225
|
+
expect(find_models_from_table("users", table)).to eq([:fred, :betty])
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
229
229
|
context "when given a table with a matching pickle ref column" do
|
230
230
|
let :table do
|
231
|
-
|
231
|
+
double(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
|
232
232
|
end
|
233
233
|
|
234
234
|
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
|
-
|
237
|
-
create_models_from_table("users", table).
|
235
|
+
expect(self).to receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
236
|
+
expect(self).to receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
237
|
+
expect(create_models_from_table("users", table)).to eq([:fred, :betty])
|
238
238
|
end
|
239
239
|
|
240
240
|
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
|
-
|
243
|
-
find_models_from_table("users", table).
|
241
|
+
expect(self).to receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
|
242
|
+
expect(self).to receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
|
243
|
+
expect(find_models_from_table("users", table)).to eq([:fred, :betty])
|
244
244
|
end
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
248
248
|
describe "#find_model!" do
|
249
249
|
it "should call find_model" do
|
250
|
-
|
250
|
+
expect(self).to receive(:find_model).with('name', 'fields').and_return(user)
|
251
251
|
find_model!('name', 'fields')
|
252
252
|
end
|
253
253
|
|
254
254
|
it "should call raise error if find_model returns nil" do
|
255
|
-
|
256
|
-
|
255
|
+
expect(self).to receive(:find_model).with('name', 'fields').and_return(nil)
|
256
|
+
expect { find_model!('name', 'fields') }.to raise_error(Pickle::Session::ModelNotFoundError)
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
260
260
|
describe "#find_models" do
|
261
261
|
before do
|
262
|
-
Pickle::Adapter.
|
262
|
+
allow(Pickle::Adapter).to receive(:find_all_models).with(user_class, anything).and_return([user])
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
266
|
-
find_models('user', 'hair: "pink"').
|
266
|
+
expect(find_models('user', 'hair: "pink"')).to eq([user])
|
267
267
|
end
|
268
268
|
|
269
269
|
describe "after find," do
|
@@ -273,27 +273,27 @@ describe Pickle::Session do
|
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should cope with spaces in the factory name (ie. it should make it canonical)" do
|
276
|
-
pickle_parser.
|
277
|
-
pickle_parser.
|
278
|
-
find_models('u ser', 'hair: "pink"').
|
276
|
+
allow(pickle_parser).to receive(:canonical).and_return('user')
|
277
|
+
expect(pickle_parser).to receive(:canonical).with('u ser').and_return('user')
|
278
|
+
expect(find_models('u ser', 'hair: "pink"')).to eq([user])
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
282
|
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
|
283
|
-
let(:fred) {
|
284
|
-
let(:shirl) {
|
285
|
-
let(:noname) {
|
283
|
+
let(:fred) { double("fred", :class => user_class, :id => 2) }
|
284
|
+
let(:shirl) { double("shirl", :class => user_class, :id => 3) }
|
285
|
+
let(:noname) { double("noname", :class => user_class, :id => 4) }
|
286
286
|
|
287
287
|
if defined? ::FactoryGirl
|
288
|
-
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(
|
288
|
+
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(double(:build_class => user_class, :name => :super_admin)) }
|
289
289
|
else
|
290
|
-
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(
|
290
|
+
let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(double(:build_class => user_class, :factory_name => :super_admin)) }
|
291
291
|
end
|
292
292
|
|
293
293
|
before do
|
294
|
-
config.
|
295
|
-
user_factory.
|
296
|
-
super_admin_factory.
|
294
|
+
allow(config).to receive(:factories).and_return(user_factory.name => user_factory, super_admin_factory.name => super_admin_factory)
|
295
|
+
allow(user_factory).to receive(:create).and_return(shirl)
|
296
|
+
allow(super_admin_factory).to receive(:create).and_return(fred, noname)
|
297
297
|
end
|
298
298
|
|
299
299
|
def do_create_users
|
@@ -303,8 +303,8 @@ describe Pickle::Session do
|
|
303
303
|
end
|
304
304
|
|
305
305
|
it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
|
306
|
-
super_admin_factory.
|
307
|
-
user_factory.
|
306
|
+
expect(super_admin_factory).to receive(:create).with({}).twice
|
307
|
+
expect(user_factory).to receive(:create).with({}).once
|
308
308
|
do_create_users
|
309
309
|
end
|
310
310
|
|
@@ -314,44 +314,44 @@ describe Pickle::Session do
|
|
314
314
|
end
|
315
315
|
|
316
316
|
it "created_models('user') should == [fred, shirl, noname]" do
|
317
|
-
created_models('user').
|
317
|
+
expect(created_models('user')).to eq([fred, shirl, noname])
|
318
318
|
end
|
319
319
|
|
320
320
|
it "created_models('super_admin') should == [fred, noname]" do
|
321
|
-
created_models('super_admin').
|
321
|
+
expect(created_models('super_admin')).to eq([fred, noname])
|
322
322
|
end
|
323
323
|
|
324
324
|
describe "#created_model" do
|
325
325
|
it "'that user' should be noname (the last user created - as super_admins are users)" do
|
326
|
-
created_model('that user').
|
326
|
+
expect(created_model('that user')).to eq(noname)
|
327
327
|
end
|
328
328
|
|
329
329
|
it "'the super admin' should be noname (the last super admin created)" do
|
330
|
-
created_model('that super admin').
|
330
|
+
expect(created_model('that super admin')).to eq(noname)
|
331
331
|
end
|
332
332
|
|
333
333
|
it "'the 1st super admin' should be fred" do
|
334
|
-
created_model('the 1st super admin').
|
334
|
+
expect(created_model('the 1st super admin')).to eq(fred)
|
335
335
|
end
|
336
336
|
|
337
337
|
it "'the first user' should be fred" do
|
338
|
-
created_model('the first user').
|
338
|
+
expect(created_model('the first user')).to eq(fred)
|
339
339
|
end
|
340
340
|
|
341
341
|
it "'the 2nd user' should be shirl" do
|
342
|
-
created_model('the 2nd user').
|
342
|
+
expect(created_model('the 2nd user')).to eq(shirl)
|
343
343
|
end
|
344
344
|
|
345
345
|
it "'the last user' should be noname" do
|
346
|
-
created_model('the last user').
|
346
|
+
expect(created_model('the last user')).to eq(noname)
|
347
347
|
end
|
348
348
|
|
349
349
|
it "'the user: \"fred\" should be fred" do
|
350
|
-
created_model('the user: "fred"').
|
350
|
+
expect(created_model('the user: "fred"')).to eq(fred)
|
351
351
|
end
|
352
352
|
|
353
353
|
it "'the user: \"shirl\" should be shirl" do
|
354
|
-
created_model('the user: "shirl"').
|
354
|
+
expect(created_model('the user: "shirl"')).to eq(shirl)
|
355
355
|
end
|
356
356
|
end
|
357
357
|
end
|
@@ -360,73 +360,73 @@ describe Pickle::Session do
|
|
360
360
|
describe "when 'the user: \"me\"' exists and there is a mapping from 'I', 'myself' => 'user: \"me\"" do
|
361
361
|
before do
|
362
362
|
self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
|
363
|
-
config.
|
364
|
-
Pickle::Adapter.
|
365
|
-
user_factory.
|
363
|
+
allow(config).to receive(:factories).and_return('user' => user_factory)
|
364
|
+
allow(Pickle::Adapter).to receive(:get_model).with(user_class, anything).and_return(user)
|
365
|
+
allow(user_factory).to receive(:create).and_return(user)
|
366
366
|
create_model('the user: "me"')
|
367
367
|
end
|
368
368
|
|
369
369
|
it 'model("I") should return the user' do
|
370
|
-
model('I').
|
370
|
+
expect(model('I')).to eq(user)
|
371
371
|
end
|
372
372
|
|
373
373
|
it 'model("myself") should return the user' do
|
374
|
-
model('myself').
|
374
|
+
expect(model('myself')).to eq(user)
|
375
375
|
end
|
376
376
|
|
377
377
|
it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
|
378
|
-
|
378
|
+
expect { pickle_parser.parse_fields('author: user "JIM"') }.to raise_error
|
379
379
|
end
|
380
380
|
|
381
381
|
it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
|
382
|
-
pickle_parser.parse_fields('author: the user').
|
382
|
+
expect(pickle_parser.parse_fields('author: the user')).to eq({"author" => user})
|
383
383
|
end
|
384
384
|
|
385
385
|
it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
|
386
|
-
pickle_parser.parse_fields('author: myself').
|
386
|
+
expect(pickle_parser.parse_fields('author: myself')).to eq({"author" => user})
|
387
387
|
end
|
388
388
|
|
389
389
|
it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
|
390
|
-
pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').
|
390
|
+
expect(pickle_parser.parse_fields('author: the user, approver: I, rating: "5"')).to eq({'author' => user, 'approver' => user, 'rating' => '5'})
|
391
391
|
end
|
392
392
|
|
393
393
|
it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
|
394
|
-
pickle_parser.parse_fields('author: user: "me", approver: ""').
|
394
|
+
expect(pickle_parser.parse_fields('author: user: "me", approver: ""')).to eq({'author' => user, 'approver' => ""})
|
395
395
|
end
|
396
396
|
end
|
397
397
|
|
398
398
|
describe "convert_models_to_attributes(ar_class, :user => <a user>)" do
|
399
399
|
before do
|
400
|
-
user.
|
400
|
+
allow(user).to receive(:is_a?).with(ActiveRecord::Base).and_return(true)
|
401
401
|
end
|
402
402
|
|
403
403
|
describe "(when ar_class has column 'user_id')" do
|
404
404
|
let :ar_class do
|
405
|
-
|
405
|
+
double('ActiveRecord', :column_names => ['user_id'], :const_get => ActiveRecord::Base::PickleAdapter)
|
406
406
|
end
|
407
407
|
|
408
408
|
it "should return {'user_id' => <the user.id>}" do
|
409
|
-
convert_models_to_attributes(ar_class, :user => user).
|
409
|
+
expect(convert_models_to_attributes(ar_class, :user => user)).to eq({'user_id' => user.id})
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
413
413
|
describe "(when ar_class has columns 'user_id', 'user_type')" do
|
414
414
|
let :ar_class do
|
415
|
-
|
415
|
+
double('ActiveRecord', :column_names => ['user_id', 'user_type'], :const_get => ActiveRecord::Base::PickleAdapter)
|
416
416
|
end
|
417
417
|
|
418
418
|
it "should return {'user_id' => <the user.id>, 'user_type' => <the user.base_class>}" do
|
419
|
-
user.class.
|
420
|
-
convert_models_to_attributes(ar_class, :user => user).
|
419
|
+
expect(user.class).to receive(:base_class).and_return(double('User base class', :name => 'UserBase'))
|
420
|
+
expect(convert_models_to_attributes(ar_class, :user => user)).to eq({'user_id' => user.id, 'user_type' => 'UserBase'})
|
421
421
|
end
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
425
425
|
it "#model!('unknown') should raise informative error message" do
|
426
|
-
|
426
|
+
expect { model!('unknown') }.to raise_error(Pickle::Session::ModelNotKnownError, "The model: 'unknown' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario.")
|
427
427
|
end
|
428
428
|
|
429
429
|
it "#created_model!('unknown') should raise informative error message" do
|
430
|
-
|
430
|
+
expect { created_model!('unknown') }.to raise_error(Pickle::Session::ModelNotKnownError)
|
431
431
|
end
|
432
432
|
end
|