pickle-has_many_support 0.3.1 → 0.4.2
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 +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +98 -0
- data/History.txt +78 -0
- data/README.rdoc +129 -61
- data/Rakefile.d/{jeweller.rake → jeweler.rake} +4 -0
- data/VERSION +1 -1
- data/features/pickle/create_from_active_record.feature +1 -1
- data/features/pickle/create_from_factory_girl.feature +5 -1
- data/features/step_definitions/raise_error_steps.rb +3 -0
- data/lib/generators/pickle_generator.rb +69 -0
- data/lib/pickle/adapter.rb +17 -7
- data/lib/pickle/adapters/active_record.rb +12 -1
- data/lib/pickle/adapters/data_mapper.rb +5 -0
- data/lib/pickle/adapters/mongoid.rb +44 -0
- data/lib/pickle/config.rb +5 -4
- data/lib/pickle/email.rb +6 -8
- data/lib/pickle/session/parser.rb +1 -1
- data/lib/pickle/session.rb +20 -5
- data/lib/pickle/world.rb +2 -1
- data/pickle.gemspec +20 -4
- data/spec/pickle/adapter_spec.rb +44 -21
- data/spec/pickle/config_spec.rb +17 -13
- data/spec/pickle/email_spec.rb +9 -3
- data/spec/pickle/session_spec.rb +11 -5
- metadata +70 -8
@@ -18,7 +18,13 @@ class ActiveRecord::Base
|
|
18
18
|
|
19
19
|
# Gets a list of the available models for this adapter
|
20
20
|
def self.model_classes
|
21
|
-
|
21
|
+
begin
|
22
|
+
klasses = ::ActiveRecord::Base.__send__(:descendants) # Rails 3
|
23
|
+
rescue
|
24
|
+
klasses = ::ActiveRecord::Base.__send__(:subclasses) # Rails 2
|
25
|
+
end
|
26
|
+
|
27
|
+
klasses.select do |klass|
|
22
28
|
!klass.abstract_class? && klass.table_exists? && !except_classes.include?(klass.name)
|
23
29
|
end
|
24
30
|
end
|
@@ -42,5 +48,10 @@ class ActiveRecord::Base
|
|
42
48
|
def self.find_all_models(klass, conditions)
|
43
49
|
klass.find(:all, :conditions => conditions)
|
44
50
|
end
|
51
|
+
|
52
|
+
# Create a model using attributes
|
53
|
+
def self.create_model(klass, attributes)
|
54
|
+
klass.create!(attributes)
|
55
|
+
end
|
45
56
|
end
|
46
57
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
module Document
|
5
|
+
module PickleAdapter
|
6
|
+
include Pickle::Adapter::Base
|
7
|
+
|
8
|
+
# Do not consider these to be part of the class list
|
9
|
+
def self.except_classes
|
10
|
+
@@except_classes ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Gets a list of the available models for this adapter
|
14
|
+
def self.model_classes
|
15
|
+
ObjectSpace.each_object(Class).to_a.select {|klass| klass.ancestors.include? Mongoid::Document}
|
16
|
+
end
|
17
|
+
|
18
|
+
# get a list of column names for a given class
|
19
|
+
def self.column_names(klass)
|
20
|
+
klass.fields.keys
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get an instance by id of the model
|
24
|
+
def self.get_model(klass, id)
|
25
|
+
klass.find(id)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Find the first instance matching conditions
|
29
|
+
def self.find_first_model(klass, conditions)
|
30
|
+
klass.first(:conditions => conditions)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Find all models matching conditions
|
34
|
+
def self.find_all_models(klass, conditions)
|
35
|
+
klass.all(:conditions => conditions)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create a model with given attributes
|
39
|
+
def self.create_model(klass, attributes)
|
40
|
+
klass.create!(attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/pickle/config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
1
|
module Pickle
|
4
2
|
class Config
|
5
3
|
attr_writer :adapters, :factories, :mappings, :predicates
|
@@ -13,7 +11,7 @@ module Pickle
|
|
13
11
|
end
|
14
12
|
|
15
13
|
def adapters
|
16
|
-
@adapters ||= [:machinist, :factory_girl, :
|
14
|
+
@adapters ||= [:machinist, :factory_girl, :orm]
|
17
15
|
end
|
18
16
|
|
19
17
|
def adapter_classes
|
@@ -31,6 +29,9 @@ module Pickle
|
|
31
29
|
k.public_instance_methods.select {|m| m =~ /\?$/} + Pickle::Adapter.column_names(k)
|
32
30
|
end.flatten.uniq
|
33
31
|
end
|
32
|
+
|
33
|
+
class Mapping < Struct.new(:search, :replacement)
|
34
|
+
end
|
34
35
|
|
35
36
|
def mappings
|
36
37
|
@mappings ||= []
|
@@ -41,7 +42,7 @@ module Pickle
|
|
41
42
|
options = args.extract_options!
|
42
43
|
raise ArgumentError, "Usage: map 'search' [, 'search2', ...] :to => 'replace'" unless args.any? && options[:to].is_a?(String)
|
43
44
|
args.each do |search|
|
44
|
-
self.mappings <<
|
45
|
+
self.mappings << Mapping.new(search, options[:to])
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/lib/pickle/email.rb
CHANGED
@@ -25,8 +25,7 @@ module Pickle
|
|
25
25
|
|
26
26
|
def click_first_link_in_email(email)
|
27
27
|
link = links_in_email(email).first
|
28
|
-
|
29
|
-
visit request_uri
|
28
|
+
visit link
|
30
29
|
end
|
31
30
|
|
32
31
|
protected
|
@@ -60,19 +59,18 @@ module Pickle
|
|
60
59
|
# e.g. confirm in http://confirm
|
61
60
|
def parse_email_for_explicit_link(email, regex)
|
62
61
|
regex = /#{Regexp.escape(regex)}/ unless regex.is_a?(Regexp)
|
63
|
-
|
64
|
-
URI::parse(url).request_uri if url
|
62
|
+
links_in_email(email).detect { |link| link =~ regex }
|
65
63
|
end
|
66
64
|
|
67
65
|
# e.g. Click here in <a href="http://confirm">Click here</a>
|
68
66
|
def parse_email_for_anchor_text_link(email, link_text)
|
69
|
-
email.body
|
70
|
-
|
71
|
-
|
67
|
+
if match_data = email.body.match(%r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>})
|
68
|
+
match_data[1]
|
69
|
+
end
|
72
70
|
end
|
73
71
|
|
74
72
|
def links_in_email(email, protos=['http', 'https'])
|
75
|
-
URI.extract(email.body, protos)
|
73
|
+
URI.extract(email.body.to_s, protos)
|
76
74
|
end
|
77
75
|
|
78
76
|
end
|
data/lib/pickle/session.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module Pickle
|
3
3
|
module Session
|
4
|
+
class ModelNotKnownError < RuntimeError
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(name, message = nil)
|
8
|
+
@name = name
|
9
|
+
@message = message || "The model: '#{name}' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario."
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
class << self
|
5
18
|
def included(world_class)
|
6
19
|
proxy_to_pickle_parser(world_class)
|
@@ -58,11 +71,13 @@ module Pickle
|
|
58
71
|
record
|
59
72
|
end
|
60
73
|
|
61
|
-
def find_model!(
|
62
|
-
find_model(
|
74
|
+
def find_model!(name, fields = nil)
|
75
|
+
find_model(name, fields) or raise ModelNotKnownError, name
|
63
76
|
end
|
64
77
|
|
65
78
|
def find_models(factory, fields = nil)
|
79
|
+
factory = pickle_parser.canonical(factory)
|
80
|
+
|
66
81
|
models_by_index(factory).clear
|
67
82
|
|
68
83
|
model_class = pickle_config.factories[factory].klass
|
@@ -90,7 +105,7 @@ module Pickle
|
|
90
105
|
elsif name_or_index.is_a?(Integer)
|
91
106
|
models_by_index(factory)[name_or_index]
|
92
107
|
else
|
93
|
-
models_by_name(factory)[name_or_index] or raise
|
108
|
+
models_by_name(factory)[name_or_index] or raise ModelNotKnownError, name
|
94
109
|
end
|
95
110
|
end
|
96
111
|
|
@@ -113,12 +128,12 @@ module Pickle
|
|
113
128
|
|
114
129
|
# like model, but raise an error if it can't be found
|
115
130
|
def model!(name)
|
116
|
-
model(name) or raise
|
131
|
+
model(name) or raise ModelNotKnownError, name
|
117
132
|
end
|
118
133
|
|
119
134
|
# like created_model, but raise an error if it can't be found
|
120
135
|
def created_model!(name)
|
121
|
-
created_model(name) or raise
|
136
|
+
created_model(name) or raise ModelNotKnownError, name
|
122
137
|
end
|
123
138
|
|
124
139
|
# return all original models of specified type
|
data/lib/pickle/world.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'pickle'
|
2
2
|
|
3
|
-
# auto require for active record and
|
3
|
+
# auto require for active record, datamapper and mongoid
|
4
4
|
require 'pickle/adapters/active_record' if defined?(ActiveRecord::Base)
|
5
5
|
require 'pickle/adapters/data_mapper' if defined?(DataMapper::Resource)
|
6
|
+
require 'pickle/adapters/mongoid' if defined?(Mongoid::Document)
|
6
7
|
|
7
8
|
# make cucumber world pickle aware
|
8
9
|
World(Pickle::Session)
|
data/pickle.gemspec
CHANGED
@@ -5,11 +5,10 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pickle-has_many_support}
|
8
|
-
s.version = "0.
|
9
|
-
|
8
|
+
s.version = "0.4.2"
|
10
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
10
|
s.authors = ["Ian White"]
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.date = %q{2010-08-23}
|
13
12
|
s.description = %q{Easy model creation and reference in your cucumber features}
|
14
13
|
s.email = %q{ian.w.white@gmail.com}
|
15
14
|
s.extra_rdoc_files = [
|
@@ -17,12 +16,14 @@ Gem::Specification.new do |s|
|
|
17
16
|
]
|
18
17
|
s.files = [
|
19
18
|
".gitignore",
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
20
21
|
"History.txt",
|
21
22
|
"License.txt",
|
22
23
|
"README.rdoc",
|
23
24
|
"Rakefile",
|
24
25
|
"Rakefile.d/cucumber.rake",
|
25
|
-
"Rakefile.d/
|
26
|
+
"Rakefile.d/jeweler.rake",
|
26
27
|
"Rakefile.d/rcov.rake",
|
27
28
|
"Rakefile.d/rspec.rake",
|
28
29
|
"Rakefile.d/yard.rake",
|
@@ -46,16 +47,19 @@ Gem::Specification.new do |s|
|
|
46
47
|
"features/step_definitions/generator_steps.rb",
|
47
48
|
"features/step_definitions/path_steps.rb",
|
48
49
|
"features/step_definitions/pickle_steps.rb",
|
50
|
+
"features/step_definitions/raise_error_steps.rb",
|
49
51
|
"features/support/email.rb",
|
50
52
|
"features/support/env.rb",
|
51
53
|
"features/support/paths.rb",
|
52
54
|
"features/support/pickle.rb",
|
53
55
|
"features/support/pickle_app.rb",
|
54
56
|
"init.rb",
|
57
|
+
"lib/generators/pickle_generator.rb",
|
55
58
|
"lib/pickle.rb",
|
56
59
|
"lib/pickle/adapter.rb",
|
57
60
|
"lib/pickle/adapters/active_record.rb",
|
58
61
|
"lib/pickle/adapters/data_mapper.rb",
|
62
|
+
"lib/pickle/adapters/mongoid.rb",
|
59
63
|
"lib/pickle/config.rb",
|
60
64
|
"lib/pickle/email.rb",
|
61
65
|
"lib/pickle/email/parser.rb",
|
@@ -109,9 +113,21 @@ Gem::Specification.new do |s|
|
|
109
113
|
s.specification_version = 3
|
110
114
|
|
111
115
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
116
|
+
s.add_runtime_dependency(%q<rspec>, [">= 1.3"])
|
117
|
+
s.add_runtime_dependency(%q<cucumber>, [">= 0.8"])
|
118
|
+
s.add_runtime_dependency(%q<yard>, [">= 0"])
|
119
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
112
120
|
else
|
121
|
+
s.add_dependency(%q<rspec>, [">= 1.3"])
|
122
|
+
s.add_dependency(%q<cucumber>, [">= 0.8"])
|
123
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
124
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
113
125
|
end
|
114
126
|
else
|
127
|
+
s.add_dependency(%q<rspec>, [">= 1.3"])
|
128
|
+
s.add_dependency(%q<cucumber>, [">= 0.8"])
|
129
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
130
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
115
131
|
end
|
116
132
|
end
|
117
133
|
|
data/spec/pickle/adapter_spec.rb
CHANGED
@@ -7,11 +7,11 @@ require 'pickle/adapters/active_record'
|
|
7
7
|
|
8
8
|
describe Pickle::Adapter do
|
9
9
|
it ".factories should raise NotImplementedError" do
|
10
|
-
lambda{ Pickle::Adapter.factories }.should raise_error(NotImplementedError)
|
10
|
+
lambda { Pickle::Adapter.factories }.should raise_error(NotImplementedError)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "#create should raise NotImplementedError" do
|
14
|
-
lambda{ Pickle::Adapter.new.create }.should raise_error(NotImplementedError)
|
14
|
+
lambda { Pickle::Adapter.new.create }.should raise_error(NotImplementedError)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe ".model_classes" do
|
@@ -26,7 +26,7 @@ describe Pickle::Adapter do
|
|
26
26
|
klass4 = Class.new(ActiveRecord::Base)
|
27
27
|
klass5 = Class.new(ActiveRecord::Base)
|
28
28
|
klass6 = Class.new(ActiveRecord::Base)
|
29
|
-
[klass1, klass2,klass3,klass4, klass5, klass6].each{|k| k.stub!(:table_exists?).and_return(true)}
|
29
|
+
[klass1, klass2, klass3, klass4, klass5, klass6].each { |k| k.stub!(:table_exists?).and_return(true) }
|
30
30
|
|
31
31
|
klass2.stub!(:name).and_return("CGI::Session::ActiveRecordStore::Session")
|
32
32
|
klass3.stub!(:name).and_return("ActiveRecord::SessionStore::Session")
|
@@ -39,37 +39,60 @@ describe Pickle::Adapter do
|
|
39
39
|
|
40
40
|
describe "adapters: " do
|
41
41
|
before do
|
42
|
-
@klass1 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One')}
|
43
|
-
@klass2 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('One::Two')}
|
44
|
-
@klass3 = returning(Class.new(ActiveRecord::Base)) {|k| k.stub!(:name).and_return('Three')}
|
42
|
+
@klass1 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('One') }
|
43
|
+
@klass2 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('One::Two') }
|
44
|
+
@klass3 = returning(Class.new(ActiveRecord::Base)) { |k| k.stub!(:name).and_return('Three') }
|
45
45
|
end
|
46
46
|
|
47
47
|
describe 'ActiveRecord' do
|
48
|
-
before do
|
49
|
-
ActiveRecord::Base::PickleAdapter.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
50
|
-
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
#DEPRECATION WARNING: subclasses is deprecated and will be removed from Rails 3.0 (use descendants instead). (called from __send__ at /Users/pivotal/workspace/factorylabs/protosite/vendor/cache/ruby/1.8/gems/pickle-0.3.1/lib/pickle/adapters/active_record.rb:21)
|
50
|
+
|
51
|
+
describe ".model_classes" do
|
52
|
+
it "calls .descendants" do
|
53
|
+
::ActiveRecord::Base.should_receive(:descendants).and_return([])
|
54
|
+
::ActiveRecord::Base.should_not_receive(:subclasses).and_return([])
|
55
|
+
|
56
|
+
ActiveRecord::Base::PickleAdapter.model_classes
|
57
|
+
end
|
58
|
+
|
59
|
+
it "calls .subclasses when .descendants doesn't respond" do
|
60
|
+
::ActiveRecord::Base.should_receive(:subclasses).and_return([])
|
61
|
+
|
62
|
+
ActiveRecord::Base::PickleAdapter.model_classes
|
63
|
+
end
|
64
|
+
|
57
65
|
end
|
58
66
|
|
59
|
-
describe
|
67
|
+
describe 'with class stubs' do
|
60
68
|
before do
|
61
|
-
|
69
|
+
Pickle::Adapter::Orm.stub!(:model_classes).and_return([@klass1, @klass2, @klass3])
|
62
70
|
end
|
63
71
|
|
64
|
-
it "should
|
65
|
-
@
|
72
|
+
it ".factories should create one for each active record class" do
|
73
|
+
Pickle::Adapter::Orm.should_receive(:new).with(@klass1).once
|
74
|
+
Pickle::Adapter::Orm.should_receive(:new).with(@klass2).once
|
75
|
+
Pickle::Adapter::Orm.should_receive(:new).with(@klass3).once
|
76
|
+
Pickle::Adapter::Orm.factories.length.should == 3
|
66
77
|
end
|
67
78
|
|
68
|
-
|
69
|
-
|
70
|
-
|
79
|
+
describe ".new(Class)" do
|
80
|
+
before do
|
81
|
+
@factory = Pickle::Adapter::Orm.new(@klass2)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have underscored (s/_) name of Class as #name" do
|
85
|
+
@factory.name.should == 'one_two'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "#create(attrs) should call Class.create!(attrs)" do
|
89
|
+
@klass2.should_receive(:create!).with({:key => "val"})
|
90
|
+
@factory.create(:key => "val")
|
91
|
+
end
|
71
92
|
end
|
72
93
|
end
|
94
|
+
|
95
|
+
|
73
96
|
end
|
74
97
|
|
75
98
|
describe 'FactoryGirl' do
|
data/spec/pickle/config_spec.rb
CHANGED
@@ -5,12 +5,12 @@ describe Pickle::Config do
|
|
5
5
|
@config = Pickle::Config.new
|
6
6
|
end
|
7
7
|
|
8
|
-
it "#adapters should default to :machinist, :factory_girl, :
|
9
|
-
@config.adapters.should == [:machinist, :factory_girl, :
|
8
|
+
it "#adapters should default to :machinist, :factory_girl, :orm" do
|
9
|
+
@config.adapters.should == [:machinist, :factory_girl, :orm]
|
10
10
|
end
|
11
11
|
|
12
|
-
it "#adapter_classes should default to Adapter::Machinist, Adapter::FactoryGirl, Adapter::
|
13
|
-
@config.adapter_classes.should == [Pickle::Adapter::Machinist, Pickle::Adapter::FactoryGirl, Pickle::Adapter::
|
12
|
+
it "#adapter_classes should default to Adapter::Machinist, Adapter::FactoryGirl, Adapter::Orm" do
|
13
|
+
@config.adapter_classes.should == [Pickle::Adapter::Machinist, Pickle::Adapter::FactoryGirl, Pickle::Adapter::Orm]
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "setting adapters to [:machinist, SomeAdapter]" do
|
@@ -29,22 +29,22 @@ describe Pickle::Config do
|
|
29
29
|
it "should call adaptor.factories for each adaptor" do
|
30
30
|
Pickle::Adapter::Machinist.should_receive(:factories).and_return([])
|
31
31
|
Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([])
|
32
|
-
Pickle::Adapter::
|
32
|
+
Pickle::Adapter::Orm.should_receive(:factories).and_return([])
|
33
33
|
@config.factories
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should aggregate factories into a hash using factory name as key" do
|
37
37
|
Pickle::Adapter::Machinist.should_receive(:factories).and_return([@machinist = mock('machinist', :name => 'machinist')])
|
38
38
|
Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([@factory_girl = mock('factory_girl', :name => 'factory_girl')])
|
39
|
-
Pickle::Adapter::
|
40
|
-
@config.factories.should == {'machinist' => @machinist, 'factory_girl' => @factory_girl, '
|
39
|
+
Pickle::Adapter::Orm.should_receive(:factories).and_return([@orm = mock('orm', :name => 'orm')])
|
40
|
+
@config.factories.should == {'machinist' => @machinist, 'factory_girl' => @factory_girl, 'orm' => @orm}
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should give preference to adaptors first in the list" do
|
44
44
|
Pickle::Adapter::Machinist.should_receive(:factories).and_return([@machinist_one = mock('one', :name => 'one')])
|
45
45
|
Pickle::Adapter::FactoryGirl.should_receive(:factories).and_return([@factory_girl_one = mock('one', :name => 'one'), @factory_girl_two = mock('two', :name => 'two')])
|
46
|
-
Pickle::Adapter::
|
47
|
-
@config.factories.should == {'one' => @machinist_one, 'two' => @factory_girl_two, 'three' => @
|
46
|
+
Pickle::Adapter::Orm.should_receive(:factories).and_return([@orm_two = mock('two', :name => 'two'), @orm_three = mock('three', :name => 'three')])
|
47
|
+
@config.factories.should == {'one' => @machinist_one, 'two' => @factory_girl_two, 'three' => @orm_three}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -80,8 +80,12 @@ describe Pickle::Config do
|
|
80
80
|
@config.map 'foo', :to => 'faz'
|
81
81
|
end
|
82
82
|
|
83
|
-
it "should create
|
84
|
-
@config.mappings.first.
|
83
|
+
it "should create Mapping('foo', 'faz') mapping" do
|
84
|
+
@config.mappings.first.tap do |mapping|
|
85
|
+
mapping.should be_kind_of Pickle::Config::Mapping
|
86
|
+
mapping.search.should == 'foo'
|
87
|
+
mapping.replacement.should == 'faz'
|
88
|
+
end
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
@@ -91,8 +95,8 @@ describe Pickle::Config do
|
|
91
95
|
end
|
92
96
|
|
93
97
|
it "should create 2 mappings" do
|
94
|
-
@config.mappings.first.should ==
|
95
|
-
@config.mappings.last.should ==
|
98
|
+
@config.mappings.first.should == Pickle::Config::Mapping.new('foo', 'faz')
|
99
|
+
@config.mappings.last.should == Pickle::Config::Mapping.new('bar', 'faz')
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
data/spec/pickle/email_spec.rb
CHANGED
@@ -143,18 +143,24 @@ describe Pickle::Email do
|
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should find a link for http://example.com/page" do
|
146
|
-
should_receive(:visit).with('/page')
|
146
|
+
should_receive(:visit).with('http://example.com/page')
|
147
147
|
visit_in_email(@email1, 'http://example.com/page')
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should find a link for \"example page\"" do
|
151
|
-
should_receive(:visit).with('/page')
|
151
|
+
should_receive(:visit).with('http://example.com/page')
|
152
152
|
visit_in_email(@email1, 'example page')
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should follow the first link in an email" do
|
156
|
-
should_receive(:visit).with('/page')
|
156
|
+
should_receive(:visit).with('http://example.com/page')
|
157
157
|
click_first_link_in_email(@email1)
|
158
158
|
end
|
159
|
+
|
160
|
+
it "should not raise an error when the email body is not a string, but needs to_s [#26]" do
|
161
|
+
stub!(:visit)
|
162
|
+
@email1.stub!(:body).and_return(:a_string_body)
|
163
|
+
lambda { click_first_link_in_email(@email1) }.should_not raise_error
|
164
|
+
end
|
159
165
|
end
|
160
166
|
end
|
data/spec/pickle/session_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Pickle::Session do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
let :user_factory do
|
26
|
-
Pickle::Adapter::
|
26
|
+
Pickle::Adapter::Orm.new(user_class)
|
27
27
|
end
|
28
28
|
|
29
29
|
before do
|
@@ -280,7 +280,7 @@ describe Pickle::Session do
|
|
280
280
|
|
281
281
|
it "should call raise error if find_model returns nil" do
|
282
282
|
should_receive(:find_model).with('name', 'fields').and_return(nil)
|
283
|
-
lambda { find_model!('name', 'fields') }.should raise_error(
|
283
|
+
lambda { find_model!('name', 'fields') }.should raise_error(Pickle::Session::ModelNotKnownError)
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -290,7 +290,7 @@ describe Pickle::Session do
|
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
|
293
|
-
find_models('user', 'hair: "pink"')
|
293
|
+
find_models('user', 'hair: "pink"').should == [user]
|
294
294
|
end
|
295
295
|
|
296
296
|
describe "after find," do
|
@@ -298,6 +298,12 @@ describe Pickle::Session do
|
|
298
298
|
|
299
299
|
it_should_behave_like "after storing a single user"
|
300
300
|
end
|
301
|
+
|
302
|
+
it "should cope with spaces in the factory name (ie. it should make it canonical)" do
|
303
|
+
pickle_parser.stub!(:canonical).and_return('user')
|
304
|
+
pickle_parser.should_receive(:canonical).with('u ser').and_return('user')
|
305
|
+
find_models('u ser', 'hair: "pink"').should == [user]
|
306
|
+
end
|
301
307
|
end
|
302
308
|
|
303
309
|
describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
|
@@ -442,10 +448,10 @@ describe Pickle::Session do
|
|
442
448
|
end
|
443
449
|
|
444
450
|
it "#model!('unknown') should raise informative error message" do
|
445
|
-
lambda { model!('unknown') }.should raise_error("
|
451
|
+
lambda { model!('unknown') }.should 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.")
|
446
452
|
end
|
447
453
|
|
448
454
|
it "#created_model!('unknown') should raise informative error message" do
|
449
|
-
lambda { created_model!('unknown') }.should raise_error(
|
455
|
+
lambda { created_model!('unknown') }.should raise_error(Pickle::Session::ModelNotKnownError)
|
450
456
|
end
|
451
457
|
end
|