dm-sweatshop 0.10.2 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +36 -0
- data/Gemfile +144 -0
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/dm-sweatshop.gemspec +24 -15
- data/lib/dm-sweatshop/unique.rb +6 -0
- data/lib/dm-sweatshop.rb +1 -0
- data/spec/dm-sweatshop/model_spec.rb +137 -132
- data/spec/dm-sweatshop/sweatshop_spec.rb +106 -101
- data/spec/spec_helper.rb +6 -32
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +64 -31
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## Rubinius
|
17
|
+
*.rbc
|
18
|
+
|
19
|
+
## PROJECT::GENERAL
|
20
|
+
*.gem
|
21
|
+
coverage
|
22
|
+
rdoc
|
23
|
+
pkg
|
24
|
+
tmp
|
25
|
+
doc
|
26
|
+
log
|
27
|
+
.yardoc
|
28
|
+
measurements
|
29
|
+
|
30
|
+
## BUNDLER
|
31
|
+
.bundle
|
32
|
+
Gemfile.local
|
33
|
+
Gemfile.lock
|
34
|
+
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
spec/db/
|
data/Gemfile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# If you're working on more than one datamapper gem at a time, then it's
|
2
|
+
# recommended to create a local Gemfile and use this instead of the git
|
3
|
+
# sources. This will make sure that you are developing against your
|
4
|
+
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
+
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
+
# it fetches the datamapper gems from local paths. This means that you can use
|
7
|
+
# the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
|
8
|
+
# bundle commands. Gemfile.local is added to .gitignore, so you don't need to
|
9
|
+
# worry about accidentally checking local development paths into git.
|
10
|
+
# In order to create a local Gemfile, all you need to do is run:
|
11
|
+
#
|
12
|
+
# bundle exec rake local_gemfile
|
13
|
+
#
|
14
|
+
# This will give you a Gemfile.local file that points to your local clones of
|
15
|
+
# the various datamapper gems. It's assumed that all datamapper repo clones
|
16
|
+
# reside in the same directory. You can use the Gemfile.local like so for
|
17
|
+
# running any bundle command:
|
18
|
+
#
|
19
|
+
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
20
|
+
#
|
21
|
+
# You can also specify which adapter(s) should be part of the bundle by setting
|
22
|
+
# an environment variable. This of course also works when using the Gemfile.local
|
23
|
+
#
|
24
|
+
# bundle foo # dm-sqlite-adapter
|
25
|
+
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
26
|
+
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
|
27
|
+
#
|
28
|
+
# Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
|
29
|
+
# and running specs against selected adapters.
|
30
|
+
#
|
31
|
+
# For easily working with adapters supported on your machine, it's recommended
|
32
|
+
# that you first install all adapters that you are planning to use or work on
|
33
|
+
# by doing something like
|
34
|
+
#
|
35
|
+
# ADAPTERS=sqlite,mysql,postgres bundle install
|
36
|
+
#
|
37
|
+
# This will clone the various repositories and make them available to bundler.
|
38
|
+
# Once you have them installed you can easily switch between adapters for the
|
39
|
+
# various development tasks. Running something like
|
40
|
+
#
|
41
|
+
# ADAPTER=mysql bundle exec rake spec
|
42
|
+
#
|
43
|
+
# will make sure that the dm-mysql-adapter is part of the bundle, and will be used
|
44
|
+
# when running the specs.
|
45
|
+
#
|
46
|
+
# You can also specify which plugin(s) should be part of the bundle by setting
|
47
|
+
# an environment variable. This also works when using the Gemfile.local
|
48
|
+
#
|
49
|
+
# bundle foo # dm-migrations
|
50
|
+
# PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
|
51
|
+
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
|
52
|
+
#
|
53
|
+
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
|
54
|
+
# for certain adapter/plugin combinations.
|
55
|
+
#
|
56
|
+
# Finally, to speed up running specs and other tasks, it's recommended to run
|
57
|
+
#
|
58
|
+
# bundle lock
|
59
|
+
#
|
60
|
+
# after running 'bundle install' for the first time. This will make 'bundle exec' run
|
61
|
+
# a lot faster compared to the unlocked version. With an unlocked bundle you would
|
62
|
+
# typically just run 'bundle install' from time to time to fetch the latest sources from
|
63
|
+
# upstream. When you locked your bundle, you need to run
|
64
|
+
#
|
65
|
+
# bundle install --relock
|
66
|
+
#
|
67
|
+
# to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
|
68
|
+
# is added to the .gitignore file, so you don't need to worry about accidentally checking
|
69
|
+
# it into version control.
|
70
|
+
|
71
|
+
source 'http://rubygems.org'
|
72
|
+
|
73
|
+
DATAMAPPER = 'git://github.com/datamapper'
|
74
|
+
DM_VERSION = '~> 1.0.0.rc1'
|
75
|
+
|
76
|
+
group :runtime do # Runtime dependencies (as in the gemspec)
|
77
|
+
|
78
|
+
if ENV['EXTLIB']
|
79
|
+
gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
|
80
|
+
else
|
81
|
+
gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
|
82
|
+
end
|
83
|
+
|
84
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
85
|
+
gem 'randexp', '~> 0.1.4'
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
group(:development) do # Development dependencies (as in the gemspec)
|
90
|
+
|
91
|
+
gem 'dm-validations', DM_VERSION, :git => "#{DATAMAPPER}/dm-validations.git"
|
92
|
+
|
93
|
+
gem 'rake', '~> 0.8.7'
|
94
|
+
gem 'rspec', '~> 1.3'
|
95
|
+
gem 'jeweler', '~> 1.4'
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
group :quality do # These gems contain rake tasks that check the quality of the source code
|
100
|
+
|
101
|
+
gem 'metric_fu', '~> 1.3'
|
102
|
+
gem 'rcov', '~> 0.9.7'
|
103
|
+
gem 'reek', '~> 1.2.7'
|
104
|
+
gem 'roodi', '~> 2.1'
|
105
|
+
gem 'yard', '~> 0.5'
|
106
|
+
gem 'yardstick', '~> 0.1'
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
group :datamapper do # We need this because we want to pin these dependencies to their git master sources
|
111
|
+
|
112
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
113
|
+
adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
|
114
|
+
|
115
|
+
unless adapters.empty?
|
116
|
+
|
117
|
+
DO_VERSION = '~> 0.10.2'
|
118
|
+
DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
|
119
|
+
|
120
|
+
gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
121
|
+
|
122
|
+
adapters.each do |adapter|
|
123
|
+
if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
|
124
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
125
|
+
gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
130
|
+
|
131
|
+
adapters.each do |adapter|
|
132
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
138
|
+
plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
|
139
|
+
|
140
|
+
plugins.each do |plugin|
|
141
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/Rakefile
CHANGED
@@ -10,16 +10,16 @@ begin
|
|
10
10
|
gem.summary = 'DataMapper plugin for building pseudo random models'
|
11
11
|
gem.description = gem.summary
|
12
12
|
gem.email = 'ben [a] benburkert [d] com'
|
13
|
-
gem.homepage = 'http://github.com/datamapper/dm-
|
13
|
+
gem.homepage = 'http://github.com/datamapper/dm-sweatshop'
|
14
14
|
gem.authors = [ 'Ben Burkert' ]
|
15
15
|
|
16
16
|
gem.rubyforge_project = 'datamapper'
|
17
17
|
|
18
|
-
gem.add_dependency 'dm-core', '~> 0.
|
18
|
+
gem.add_dependency 'dm-core', '~> 1.0.0.rc1'
|
19
19
|
gem.add_dependency 'randexp', '~> 0.1.4'
|
20
20
|
|
21
|
-
gem.add_development_dependency '
|
22
|
-
gem.add_development_dependency '
|
21
|
+
gem.add_development_dependency 'dm-validations', '~> 1.0.0.rc1'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 1.3'
|
23
23
|
end
|
24
24
|
|
25
25
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.rc1
|
data/dm-sweatshop.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-sweatshop}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Burkert"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-05-19}
|
13
13
|
s.description = %q{DataMapper plugin for building pseudo random models}
|
14
14
|
s.email = %q{ben [a] benburkert [d] com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE",
|
21
23
|
"README.rdoc",
|
22
24
|
"Rakefile",
|
23
25
|
"VERSION",
|
@@ -33,38 +35,45 @@ Gem::Specification.new do |s|
|
|
33
35
|
"spec/spec.opts",
|
34
36
|
"spec/spec_helper.rb",
|
35
37
|
"tasks/ci.rake",
|
38
|
+
"tasks/local_gemfile.rake",
|
36
39
|
"tasks/metrics.rake",
|
37
40
|
"tasks/spec.rake",
|
38
41
|
"tasks/yard.rake",
|
39
42
|
"tasks/yardstick.rake"
|
40
43
|
]
|
41
|
-
s.homepage = %q{http://github.com/datamapper/dm-
|
44
|
+
s.homepage = %q{http://github.com/datamapper/dm-sweatshop}
|
42
45
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
46
|
s.require_paths = ["lib"]
|
44
47
|
s.rubyforge_project = %q{datamapper}
|
45
|
-
s.rubygems_version = %q{1.3.
|
48
|
+
s.rubygems_version = %q{1.3.6}
|
46
49
|
s.summary = %q{DataMapper plugin for building pseudo random models}
|
50
|
+
s.test_files = [
|
51
|
+
"spec/dm-sweatshop/model_spec.rb",
|
52
|
+
"spec/dm-sweatshop/sweatshop_spec.rb",
|
53
|
+
"spec/dm-sweatshop/unique_spec.rb",
|
54
|
+
"spec/spec_helper.rb"
|
55
|
+
]
|
47
56
|
|
48
57
|
if s.respond_to? :specification_version then
|
49
58
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
59
|
s.specification_version = 3
|
51
60
|
|
52
61
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 0.
|
62
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
54
63
|
s.add_runtime_dependency(%q<randexp>, ["~> 0.1.4"])
|
55
|
-
s.add_development_dependency(%q<
|
56
|
-
s.add_development_dependency(%q<
|
64
|
+
s.add_development_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
|
65
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3"])
|
57
66
|
else
|
58
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
67
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
59
68
|
s.add_dependency(%q<randexp>, ["~> 0.1.4"])
|
60
|
-
s.add_dependency(%q<
|
61
|
-
s.add_dependency(%q<
|
69
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
|
70
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
62
71
|
end
|
63
72
|
else
|
64
|
-
s.add_dependency(%q<dm-core>, ["~> 0.
|
73
|
+
s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
|
65
74
|
s.add_dependency(%q<randexp>, ["~> 0.1.4"])
|
66
|
-
s.add_dependency(%q<
|
67
|
-
s.add_dependency(%q<
|
75
|
+
s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
|
76
|
+
s.add_dependency(%q<rspec>, ["~> 1.3"])
|
68
77
|
end
|
69
78
|
end
|
70
79
|
|
data/lib/dm-sweatshop/unique.rb
CHANGED
data/lib/dm-sweatshop.rb
CHANGED
@@ -10,7 +10,7 @@ describe DataMapper::Model do
|
|
10
10
|
property :price, Integer
|
11
11
|
|
12
12
|
belongs_to :order, :required => false
|
13
|
-
|
13
|
+
validates_presence_of :price
|
14
14
|
end
|
15
15
|
|
16
16
|
class Wonket < Widget
|
@@ -31,174 +31,179 @@ describe DataMapper::Model do
|
|
31
31
|
DataMapper::Sweatshop.record_map.clear
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
supported_by :all do
|
35
|
+
|
36
|
+
describe ".default_fauxture_name" do
|
37
|
+
it "is :default" do
|
38
|
+
Order.default_fauxture_name.should == :default
|
39
|
+
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
describe ".fixture" do
|
43
|
+
describe "without fauxture name" do
|
44
|
+
before :each do
|
45
|
+
Widget.fixture {{
|
46
|
+
:name => /\w+/.gen.capitalize,
|
47
|
+
:price => /\d{4,5}/.gen.to_i
|
48
|
+
}}
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
@default = DataMapper::Sweatshop.model_map[Widget][:default]
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
it "add a fixture proc for the model with name :default" do
|
54
|
+
@default.should_not be_empty
|
55
|
+
@default.first.should be_kind_of(Proc)
|
56
|
+
end
|
54
57
|
end
|
55
|
-
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
it "should allow handle complex named fixtures" do
|
60
|
+
Wonket.fix {{
|
61
|
+
:name => /\w+ Wonket/.gen.capitalize,
|
62
|
+
:price => /\d{2,3}99/.gen.to_i,
|
63
|
+
:size => %w[small medium large xl].pick
|
64
|
+
}}
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
Order.fix {{
|
67
|
+
:widgets => (1..5).of { Widget.gen }
|
68
|
+
}}
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
Order.fix(:wonket_order) {{
|
71
|
+
:widgets => (5..10).of { Wonket.gen }
|
72
|
+
}}
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
wonket_order = Order.gen(:wonket_order)
|
75
|
+
wonket_order.widgets.should_not be_empty
|
76
|
+
end
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
it "should allow for STI fixtures" do
|
79
|
+
Widget.fix {{
|
80
|
+
:name => /\w+/.gen.capitalize,
|
81
|
+
:price => /\d{4,5}/.gen.to_i
|
82
|
+
}}
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
Order.fix {{
|
85
|
+
:widgets => (1..5).of { Wonket.gen }
|
86
|
+
}}
|
85
87
|
|
86
|
-
|
88
|
+
Order.gen.widgets.should_not be_empty
|
89
|
+
end
|
87
90
|
end
|
88
|
-
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
describe ".make" do
|
93
|
+
before :each do
|
94
|
+
Widget.fix(:red) {{
|
95
|
+
:name => "red",
|
96
|
+
:price => 20
|
97
|
+
}}
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
+
@widget = Widget.make(:red)
|
100
|
+
end
|
99
101
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
it "creates an object from named attributes hash" do
|
103
|
+
@widget.name.should == "red"
|
104
|
+
@widget.price.should == 20
|
105
|
+
end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
+
it "returns a new object" do
|
108
|
+
@widget.should be_new
|
109
|
+
end
|
107
110
|
end
|
108
|
-
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
112
|
+
describe ".generate" do
|
113
|
+
before :each do
|
114
|
+
Widget.fix(:red) {{
|
115
|
+
:name => "red",
|
116
|
+
:price => 20
|
117
|
+
}}
|
116
118
|
|
117
|
-
|
119
|
+
@widget = Widget.gen(:red)
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
Widget.fix(:blue) {{
|
122
|
+
:name => "blue"
|
123
|
+
}}
|
124
|
+
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
it "creates an object from named attributes hash" do
|
127
|
+
@widget.name.should == "red"
|
128
|
+
@widget.price.should == 20
|
129
|
+
end
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
|
131
|
+
it "returns a saved object" do
|
132
|
+
@widget.should be_saved
|
133
|
+
end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
it "does not save invalid model" do
|
136
|
+
blue_widget = Widget.gen(:blue)
|
137
|
+
blue_widget.should be_new
|
138
|
+
end
|
136
139
|
end
|
137
|
-
end
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
describe ".generate!" do
|
142
|
+
it "saves a model even if it is invalid" do
|
143
|
+
Widget.fix(:blue) {{
|
144
|
+
:name => "blue"
|
145
|
+
}}
|
144
146
|
|
145
|
-
|
146
|
-
|
147
|
+
blue_widget = Widget.gen!(:blue)
|
148
|
+
blue_widget.should be_saved
|
149
|
+
end
|
147
150
|
end
|
148
|
-
end
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
Widget.fix(:yellow) {{
|
158
|
-
:name => "giallo",
|
159
|
-
:price => 30
|
160
|
-
}}
|
161
|
-
|
162
|
-
Widget.fix(:blue) {{
|
163
|
-
:name => Proc.new { "b" + "lu" },
|
164
|
-
:price => 40
|
165
|
-
}}
|
166
|
-
|
167
|
-
@red = Widget.gen(:red)
|
168
|
-
@yellow = Widget.gen(:yellow)
|
169
|
-
@blue = Widget.gen(:blue)
|
170
|
-
end
|
152
|
+
describe ".pick" do
|
153
|
+
before :each do
|
154
|
+
Widget.fix(:red) {{
|
155
|
+
:name => "rosso",
|
156
|
+
:price => 20
|
157
|
+
}}
|
171
158
|
|
172
|
-
|
173
|
-
|
174
|
-
|
159
|
+
Widget.fix(:yellow) {{
|
160
|
+
:name => "giallo",
|
161
|
+
:price => 30
|
162
|
+
}}
|
175
163
|
|
176
|
-
|
177
|
-
|
178
|
-
|
164
|
+
Widget.fix(:blue) {{
|
165
|
+
:name => Proc.new { "b" + "lu" },
|
166
|
+
:price => 40
|
167
|
+
}}
|
179
168
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
169
|
+
@red = Widget.gen(:red)
|
170
|
+
@yellow = Widget.gen(:yellow)
|
171
|
+
@blue = Widget.gen(:blue)
|
172
|
+
end
|
184
173
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
:name => "red",
|
189
|
-
:price => 20
|
190
|
-
}}
|
174
|
+
it "returns a pre existing object with named attributes hash" do
|
175
|
+
@red.name.should == "rosso"
|
176
|
+
@red.price.should == 20
|
191
177
|
|
192
|
-
|
193
|
-
|
178
|
+
@yellow.name.should == "giallo"
|
179
|
+
@yellow.price.should == 30
|
180
|
+
end
|
194
181
|
|
195
|
-
|
196
|
-
|
182
|
+
it "expands callable values of attributes hash" do
|
183
|
+
@blue.name.should == "blu"
|
184
|
+
end
|
197
185
|
end
|
198
186
|
|
199
|
-
|
200
|
-
|
201
|
-
|
187
|
+
describe ".generate_attributes" do
|
188
|
+
before :each do
|
189
|
+
Widget.fix(:red) {{
|
190
|
+
:name => "red",
|
191
|
+
:price => 20
|
192
|
+
}}
|
193
|
+
|
194
|
+
@hash = Widget.generate_attributes(:red)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "returns a Hash" do
|
198
|
+
@hash.should be_an_instance_of(Hash)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "returns stored attributes hash by name" do
|
202
|
+
@hash[:name].should == "red"
|
203
|
+
@hash[:price].should == 20
|
204
|
+
end
|
202
205
|
end
|
206
|
+
|
203
207
|
end
|
208
|
+
|
204
209
|
end
|
@@ -20,142 +20,147 @@ describe DataMapper::Sweatshop do
|
|
20
20
|
DataMapper::Sweatshop.record_map.clear
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
it "should return a Hash if the model is not mapped" do
|
25
|
-
DataMapper::Sweatshop.model_map[Class.new].should be_is_a(Hash)
|
26
|
-
end
|
23
|
+
supported_by :all do
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
describe ".model_map" do
|
26
|
+
it "should return a Hash if the model is not mapped" do
|
27
|
+
DataMapper::Sweatshop.model_map[Class.new].should be_is_a(Hash)
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
lambda {
|
37
|
-
DataMapper::Sweatshop.add(Parent, :default, &proc)
|
38
|
-
}.should change {
|
39
|
-
DataMapper::Sweatshop.model_map[Parent][:default].first
|
40
|
-
}.from(nil).to(proc)
|
30
|
+
it "should return a map for names to an array of procs if the model is not mapped" do
|
31
|
+
DataMapper::Sweatshop.model_map[Class.new][:unnamed].should be_is_a(Array)
|
32
|
+
end
|
41
33
|
end
|
42
34
|
|
43
|
-
|
44
|
-
|
35
|
+
describe ".add" do
|
36
|
+
it "should app a generator proc to the model map" do
|
37
|
+
proc = lambda {}
|
38
|
+
lambda {
|
39
|
+
DataMapper::Sweatshop.add(Parent, :default, &proc)
|
40
|
+
}.should change {
|
41
|
+
DataMapper::Sweatshop.model_map[Parent][:default].first
|
42
|
+
}.from(nil).to(proc)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should push repeat procs onto the mapped array" do
|
46
|
+
proc1, proc2 = lambda {}, lambda {}
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
DataMapper::Sweatshop.add(Parent, :default, &proc1)
|
49
|
+
DataMapper::Sweatshop.add(Parent, :default, &proc2)
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
DataMapper::Sweatshop.model_map[Parent][:default].first.should == proc1
|
52
|
+
DataMapper::Sweatshop.model_map[Parent][:default].last.should == proc2
|
53
|
+
end
|
51
54
|
end
|
52
|
-
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
describe ".expand_callable_values" do
|
57
|
+
it 'evalues values that respond to call' do
|
58
|
+
DataMapper::Sweatshop.
|
59
|
+
expand_callable_values({ :value => Proc.new { "a" + "b" } }).
|
60
|
+
should == { :value => "ab" }
|
61
|
+
end
|
59
62
|
end
|
60
|
-
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
describe ".attributes" do
|
65
|
+
it "should return an attributes hash" do
|
66
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
67
|
+
:first_name => /\w+/.gen.capitalize,
|
68
|
+
:last_name => /\w+/.gen.capitalize
|
69
|
+
}}
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
DataMapper::Sweatshop.attributes(Parent, :default).should be_is_a(Hash)
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
it "should call the attribute proc on each call to attributes" do
|
75
|
+
calls = 0
|
76
|
+
proc = lambda {{:calls => (calls += 1)}}
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
DataMapper::Sweatshop.add(Parent, :default, &proc)
|
79
|
+
DataMapper::Sweatshop.attributes(Parent, :default).should == {:calls => 1}
|
80
|
+
DataMapper::Sweatshop.attributes(Parent, :default).should == {:calls => 2}
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
it "expands callable values" do
|
84
|
+
DataMapper::Sweatshop.add(Parent, :default) do
|
85
|
+
{ :value => Proc.new { "a" + "b" } }
|
86
|
+
end
|
87
|
+
DataMapper::Sweatshop.attributes(Parent, :default).should == {
|
88
|
+
:value => "ab"
|
89
|
+
}
|
84
90
|
end
|
85
|
-
DataMapper::Sweatshop.attributes(Parent, :default).should == {
|
86
|
-
:value => "ab"
|
87
|
-
}
|
88
|
-
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
92
|
+
it "should call attributes with the superclass if the class is not mapped" do
|
93
|
+
DataMapper::Sweatshop.add(Parent, :default) {{:first_name => 'Bob'}}
|
94
|
+
DataMapper::Sweatshop.attributes(Child, :default).should == {:first_name => 'Bob'}
|
95
|
+
end
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
it "should raise an error if neither the class or it's parent class(es) have been mapped" do
|
98
|
+
lambda { DataMapper::Sweatshop.attributes(Child, :default) }.
|
99
|
+
should raise_error(DataMapper::Sweatshop::NoFixtureExist, /default fixture was not found for class/)
|
100
|
+
end
|
98
101
|
end
|
99
|
-
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
describe ".create" do
|
104
|
+
it "should call create on the model class with the attributes generated from a mapped proc" do
|
105
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
106
|
+
:first_name => 'Kenny',
|
107
|
+
:last_name => 'Rogers'
|
108
|
+
}}
|
107
109
|
|
108
|
-
|
110
|
+
Parent.should_receive(:create).with(:first_name => 'Kenny', :last_name => 'Rogers')
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
+
DataMapper::Sweatshop.create(Parent, :default)
|
113
|
+
end
|
112
114
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
it "should call create on the model with a parent class' mapped attributes proc when the original class has not been maped" do
|
116
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
117
|
+
:first_name => 'Kenny',
|
118
|
+
:last_name => 'Rogers'
|
119
|
+
}}
|
118
120
|
|
119
|
-
|
121
|
+
Child.should_receive(:create).with(:first_name => 'Kenny', :last_name => 'Rogers')
|
120
122
|
|
121
|
-
|
122
|
-
|
123
|
+
DataMapper::Sweatshop.create(Child, :default)
|
124
|
+
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
126
|
+
it "should merge in any attributes as an argument" do
|
127
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
128
|
+
:first_name => 'Kenny',
|
129
|
+
:last_name => 'Rogers'
|
130
|
+
}}
|
129
131
|
|
130
|
-
|
132
|
+
Parent.should_receive(:create).with(:first_name => 'Roddy', :last_name => 'Rogers')
|
131
133
|
|
132
|
-
|
134
|
+
DataMapper::Sweatshop.create(Parent, :default, :first_name => 'Roddy')
|
135
|
+
end
|
133
136
|
end
|
134
|
-
end
|
135
137
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
describe ".make" do
|
139
|
+
it "should call new on the model class with the attributes generated from a mapped proc" do
|
140
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
141
|
+
:first_name => 'Kenny',
|
142
|
+
:last_name => 'Rogers'
|
143
|
+
}}
|
142
144
|
|
143
|
-
|
145
|
+
Parent.should_receive(:new).with(:first_name => 'Kenny', :last_name => 'Rogers')
|
144
146
|
|
145
|
-
|
147
|
+
DataMapper::Sweatshop.make(Parent, :default)
|
148
|
+
end
|
146
149
|
end
|
147
|
-
end
|
148
150
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
describe ".pick" do
|
152
|
+
it "should return a pre existing instance of a model from the record map" do
|
153
|
+
DataMapper::Sweatshop.add(Parent, :default) {{
|
154
|
+
:first_name => 'George',
|
155
|
+
:last_name => 'Clinton'
|
156
|
+
}}
|
155
157
|
|
156
|
-
|
158
|
+
DataMapper::Sweatshop.create(Parent, :default)
|
157
159
|
|
158
|
-
|
160
|
+
DataMapper::Sweatshop.pick(Parent, :default).should be_is_a(Parent)
|
161
|
+
end
|
159
162
|
end
|
163
|
+
|
160
164
|
end
|
165
|
+
|
161
166
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,40 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
# Use local dm-core if running from a typical dev checkout.
|
4
|
-
lib = File.join('..', '..', 'dm-core', 'lib')
|
5
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
6
|
-
require 'dm-core'
|
7
|
-
|
8
|
-
# use local dm-validations if running from a typical dev checkout.
|
9
|
-
lib = File.join('..', 'dm-validations', 'lib')
|
10
|
-
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
11
|
-
require 'dm-validations'
|
12
|
-
|
13
|
-
# Support running specs with 'rake spec' and 'spec'
|
14
|
-
$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
|
1
|
+
require 'dm-core/spec/setup'
|
2
|
+
require 'dm-core/spec/lib/adapter_helpers'
|
15
3
|
|
16
4
|
require 'dm-sweatshop'
|
5
|
+
require 'dm-migrations'
|
6
|
+
require 'dm-validations'
|
17
7
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
begin
|
22
|
-
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
23
|
-
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
24
|
-
true
|
25
|
-
rescue LoadError => e
|
26
|
-
warn "Could not load do_#{name}: #{e}"
|
27
|
-
false
|
28
|
-
end
|
8
|
+
Spec::Runner.configure do |config|
|
9
|
+
config.extend(DataMapper::Spec::Adapters::Helpers)
|
29
10
|
end
|
30
11
|
|
31
|
-
ENV['ADAPTER'] ||= 'sqlite3'
|
32
|
-
|
33
|
-
HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
|
34
|
-
HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
|
35
|
-
HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
|
36
|
-
|
37
|
-
|
38
12
|
begin
|
39
13
|
Randexp::Dictionary.load_dictionary
|
40
14
|
rescue RuntimeError
|
@@ -0,0 +1,18 @@
|
|
1
|
+
desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
|
2
|
+
task :local_gemfile do |t|
|
3
|
+
|
4
|
+
root = Pathname(__FILE__).dirname.parent
|
5
|
+
datamapper = root.parent
|
6
|
+
|
7
|
+
source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
|
8
|
+
gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
|
9
|
+
|
10
|
+
root.join('Gemfile.local').open('w') do |f|
|
11
|
+
root.join('Gemfile').open.each do |line|
|
12
|
+
line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
|
13
|
+
line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
|
14
|
+
f.puts line
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-sweatshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- rc1
|
10
|
+
version: 1.0.0.rc1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Ben Burkert
|
@@ -9,49 +15,66 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-05-19 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: dm-core
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
25
|
requirements:
|
21
26
|
- - ~>
|
22
27
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- rc1
|
33
|
+
version: 1.0.0.rc1
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: randexp
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
40
|
requirements:
|
31
41
|
- - ~>
|
32
42
|
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 1
|
46
|
+
- 4
|
33
47
|
version: 0.1.4
|
34
|
-
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
35
50
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
name: dm-validations
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
54
|
requirements:
|
41
55
|
- - ~>
|
42
56
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
-
|
46
|
-
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 0
|
60
|
+
- 0
|
61
|
+
- rc1
|
62
|
+
version: 1.0.0.rc1
|
47
63
|
type: :development
|
48
|
-
|
49
|
-
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rspec
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
69
|
requirements:
|
51
70
|
- - ~>
|
52
71
|
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 3
|
75
|
+
version: "1.3"
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
55
78
|
description: DataMapper plugin for building pseudo random models
|
56
79
|
email: ben [a] benburkert [d] com
|
57
80
|
executables: []
|
@@ -62,6 +85,8 @@ extra_rdoc_files:
|
|
62
85
|
- LICENSE
|
63
86
|
- README.rdoc
|
64
87
|
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
65
90
|
- LICENSE
|
66
91
|
- README.rdoc
|
67
92
|
- Rakefile
|
@@ -78,12 +103,13 @@ files:
|
|
78
103
|
- spec/spec.opts
|
79
104
|
- spec/spec_helper.rb
|
80
105
|
- tasks/ci.rake
|
106
|
+
- tasks/local_gemfile.rake
|
81
107
|
- tasks/metrics.rake
|
82
108
|
- tasks/spec.rake
|
83
109
|
- tasks/yard.rake
|
84
110
|
- tasks/yardstick.rake
|
85
111
|
has_rdoc: true
|
86
|
-
homepage: http://github.com/datamapper/dm-
|
112
|
+
homepage: http://github.com/datamapper/dm-sweatshop
|
87
113
|
licenses: []
|
88
114
|
|
89
115
|
post_install_message:
|
@@ -95,20 +121,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
121
|
requirements:
|
96
122
|
- - ">="
|
97
123
|
- !ruby/object:Gem::Version
|
124
|
+
segments:
|
125
|
+
- 0
|
98
126
|
version: "0"
|
99
|
-
version:
|
100
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
128
|
requirements:
|
102
|
-
- - "
|
129
|
+
- - ">"
|
103
130
|
- !ruby/object:Gem::Version
|
104
|
-
|
105
|
-
|
131
|
+
segments:
|
132
|
+
- 1
|
133
|
+
- 3
|
134
|
+
- 1
|
135
|
+
version: 1.3.1
|
106
136
|
requirements: []
|
107
137
|
|
108
138
|
rubyforge_project: datamapper
|
109
|
-
rubygems_version: 1.3.
|
139
|
+
rubygems_version: 1.3.6
|
110
140
|
signing_key:
|
111
141
|
specification_version: 3
|
112
142
|
summary: DataMapper plugin for building pseudo random models
|
113
|
-
test_files:
|
114
|
-
|
143
|
+
test_files:
|
144
|
+
- spec/dm-sweatshop/model_spec.rb
|
145
|
+
- spec/dm-sweatshop/sweatshop_spec.rb
|
146
|
+
- spec/dm-sweatshop/unique_spec.rb
|
147
|
+
- spec/spec_helper.rb
|