dm-sweatshop 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → History.rdoc} +4 -0
- data/Manifest.txt +2 -2
- data/{README.textile → README.rdoc} +49 -98
- data/Rakefile +2 -3
- data/lib/dm-sweatshop/version.rb +1 -1
- data/lib/dm-sweatshop.rb +3 -12
- data/spec/dm-sweatshop/model_spec.rb +12 -18
- data/spec/dm-sweatshop/sweatshop_spec.rb +4 -4
- data/spec/dm-sweatshop/unique_spec.rb +48 -48
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +36 -9
- data/tasks/install.rb +1 -1
- data/tasks/spec.rb +4 -4
- metadata +14 -31
data/Manifest.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
= dm-sweatshop
|
2
2
|
|
3
|
-
|
3
|
+
== Overview
|
4
4
|
|
5
5
|
dm-sweatshop is a model factory for DataMapper. It makes it easy & painless to crank out complex pseudo random models -- useful for tests and seed data. Production Goals:
|
6
6
|
|
@@ -9,7 +9,7 @@ dm-sweatshop is a model factory for DataMapper. It makes it easy & painless to
|
|
9
9
|
* Add context to model patterns, allowing grouping and
|
10
10
|
* Effortlessly generate or fill in associations for creating complex models with few lines of code.
|
11
11
|
|
12
|
-
|
12
|
+
== How it works
|
13
13
|
|
14
14
|
DataMapper Sweatshop is built around idea of storing attribute hashes associated
|
15
15
|
with a particular class. For instance, you can store two attribute hashes named
|
@@ -36,25 +36,21 @@ Another nice thing is associations. Say we want to have say 20 tags for a
|
|
36
36
|
document or 10 orders for account in tests. DataMapper Sweatshop lets us
|
37
37
|
use associations list in attributes hashes described earlier.
|
38
38
|
|
39
|
-
|
39
|
+
== Examples
|
40
40
|
|
41
41
|
Starting off with a simple user model.
|
42
|
-
|
43
|
-
<code>
|
42
|
+
|
44
43
|
class User
|
45
44
|
include DataMapper::Resource
|
46
|
-
|
45
|
+
|
47
46
|
property :id, Serial
|
48
47
|
property :username, String
|
49
48
|
property :email, String
|
50
49
|
property :password, String
|
51
50
|
end
|
52
|
-
</code>
|
53
|
-
</pre>
|
54
51
|
|
55
52
|
A fixture for the user model can be defined using the @fixture@ method.
|
56
|
-
|
57
|
-
<code>
|
53
|
+
|
58
54
|
User.fixture {{
|
59
55
|
:username => (username = /\w+/.gen),
|
60
56
|
:email => "#{username}@example.com",
|
@@ -64,8 +60,6 @@ A fixture for the user model can be defined using the @fixture@ method.
|
|
64
60
|
# The /\w+/.gen notation is part of the randexp gem:
|
65
61
|
# http://github.com/benburkert/randexp/
|
66
62
|
}}
|
67
|
-
</code>
|
68
|
-
</pre>
|
69
63
|
|
70
64
|
Notice the double curly brace (@{{@), a quick little way to pass a block that returns a hash to the fixture method. This is important because it ensures the data is random when we generate a new instance of the model, by calling the block every time.
|
71
65
|
|
@@ -78,57 +72,38 @@ attributes, and use and abuse it any way you want. It's just a way to memoize
|
|
78
72
|
attributes set associated with a particular class.
|
79
73
|
|
80
74
|
And here's how you generate said model.
|
81
|
-
|
82
|
-
<code>
|
75
|
+
|
83
76
|
User.generate
|
84
|
-
</code>
|
85
|
-
</pre>
|
86
77
|
|
87
78
|
That's it. In fact, it can even be shortened.
|
88
|
-
|
89
|
-
<code>
|
79
|
+
|
90
80
|
User.gen
|
91
|
-
</code>
|
92
|
-
</pre>
|
93
81
|
|
94
82
|
But what if we want to use some name for that attributes set? Just pass an
|
95
83
|
argument to @fixture@ method like this:
|
96
84
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
:password_hash => Digest::SHA1.hexdigest("#{salt}@--,-`--secret")
|
105
|
-
}}
|
106
|
-
</code>
|
107
|
-
</pre>
|
85
|
+
Person.fixture(:valid) {{
|
86
|
+
:first_name => %w(Michael Adam Guiseppe)[rand(3)],
|
87
|
+
:last_name => %w(Smith Black White)[rand(3)],
|
88
|
+
:email => "#{/\w{10}/.gen}@somedomain.info",
|
89
|
+
:password_salt => (salt = /\w{20}/.gen),
|
90
|
+
:password_hash => Digest::SHA1.hexdigest("#{salt}@--,-`--secret")
|
91
|
+
}}
|
108
92
|
|
109
93
|
Now to a model that has given attributes, use
|
110
94
|
|
111
|
-
|
112
|
-
<code>
|
113
|
-
Person.gen(:valid)
|
114
|
-
</code>
|
115
|
-
</pre>
|
95
|
+
Person.gen(:valid)
|
116
96
|
|
117
97
|
@generate@ (or @gen@) method uses @create@ method of DataMapper models. This means that validations are run on the model. There are two other methods you can use to creat data - @make@ to build a model that has not been saved, and @generate!@ to force saving of the model even if it is invalid (it uses @create!@ internally).
|
118
98
|
|
119
|
-
|
120
|
-
|
121
|
-
Person.make(:valid)
|
122
|
-
Person.generate!(:invalid) # You can also use #gen!
|
123
|
-
</code>
|
124
|
-
</pre>
|
99
|
+
Person.make(:valid)
|
100
|
+
Person.generate!(:invalid) # You can also use #gen!
|
125
101
|
|
126
102
|
|
127
|
-
|
103
|
+
=== Associations
|
128
104
|
|
129
105
|
The real power of sweatshop is generating working associations.
|
130
|
-
|
131
|
-
<code>
|
106
|
+
|
132
107
|
DataMapper.setup(:default, "sqlite3::memory:")
|
133
108
|
|
134
109
|
class Tweet
|
@@ -178,13 +153,10 @@ The real power of sweatshop is generating working associations.
|
|
178
153
|
|
179
154
|
# now lets generate 100 users, each with 500 tweets. Also, the tweet's have 0 to 10 tags!
|
180
155
|
users = 10.of {User.gen}
|
181
|
-
|
182
|
-
</pre>
|
156
|
+
|
183
157
|
|
184
158
|
That's going to generate alot of tags, way more than you would see in the production app. Let's recycle some already generated tags instead.
|
185
159
|
|
186
|
-
<pre>
|
187
|
-
<code>
|
188
160
|
User.fix {{
|
189
161
|
:username => /\w+/.gen,
|
190
162
|
:tweets => 500.of {Tweet.make}
|
@@ -202,27 +174,20 @@ That's going to generate alot of tags, way more than you would see in the produc
|
|
202
174
|
50.times {Tag.gen}
|
203
175
|
|
204
176
|
users = 10.of {User.gen}
|
205
|
-
</code>
|
206
|
-
</pre>
|
207
177
|
|
208
|
-
|
178
|
+
|
179
|
+
=== Contexts
|
209
180
|
|
210
181
|
You can add multiple fixtures to a mode, dm-sweatshop will randomly pick between the available fixtures when it generates a new model.
|
211
182
|
|
212
|
-
<pre>
|
213
|
-
<code>
|
214
183
|
Tweet.fix {{
|
215
184
|
# a @reply for some user
|
216
185
|
:message => /\@#{User.pick.name} [:sentence:]/.gen[0..140],
|
217
186
|
:tags => (0..10).of {Tag.pick}
|
218
187
|
}}
|
219
|
-
</code>
|
220
|
-
</pre>
|
221
188
|
|
222
189
|
To keep track of all of our new fixtures, we can even give them a context.
|
223
190
|
|
224
|
-
<pre>
|
225
|
-
<code>
|
226
191
|
Tweet.fix(:at_reply) {{
|
227
192
|
:message => /\@#{User.pick.name} [:sentence:]/.gen[0..140],
|
228
193
|
:tags => (0..10).of {Tag.pick}
|
@@ -232,77 +197,63 @@ To keep track of all of our new fixtures, we can even give them a context.
|
|
232
197
|
:message => /\@#{(tweet = Tweet.pick(:at_reply)).user.name} [:sentence:]/.gen[0..140],
|
233
198
|
:tags => tweet.tags
|
234
199
|
}}
|
235
|
-
</code>
|
236
|
-
</pre>
|
237
200
|
|
238
|
-
|
201
|
+
=== Overriding a fixture
|
239
202
|
|
240
|
-
Sometimes you will want to change one of your fixtures a little bit. You can create a new fixture with a whole new context, but this can be overkill. The other option is to specify attributes in the call to
|
203
|
+
Sometimes you will want to change one of your fixtures a little bit. You can create a new fixture with a whole new context, but this can be overkill. The other option is to specify attributes in the call to <tt>generate</tt>.
|
241
204
|
|
242
|
-
<pre>
|
243
|
-
<code>
|
244
205
|
User.gen(:username => 'datamapper') #uses 'datamapper' as the user name instead of the randomly generated word
|
245
|
-
</code>
|
246
|
-
</pre>
|
247
206
|
|
248
207
|
This works with contexts too.
|
249
208
|
|
250
|
-
<pre>
|
251
|
-
<code>
|
252
209
|
User.gen(:conversation, :tags => Tag.all) #a very, very broad conversation
|
253
|
-
</code>
|
254
|
-
</pre>
|
255
210
|
|
256
|
-
|
211
|
+
== Unique values
|
257
212
|
|
258
213
|
Data for fields with a uniqueness constraint (for example, e-mail addresses) can be generated using the @unique@ method. The simplest usage is to guarantee that random data is unique - wrap your generator in a @unique@ block with no parameters, and the block will be repeatedly executed until it generates a unique value (don't worry, it raises after a few tries).
|
259
214
|
|
260
215
|
For repeatable data, provide a block with one parameter. An incrementing value will be passed in on each invocation of that block. You can also name a unique block to override the block's identity (yeah that sentence is dense, just see the examples).
|
261
216
|
|
262
|
-
|
217
|
+
include DataMapper::Sweatshop::Unique # Use DataMapper::Sweatshop.unique if you don't want to pollute your namespace
|
263
218
|
|
264
|
-
User.fix {{
|
265
|
-
|
266
|
-
|
267
|
-
}}
|
219
|
+
User.fix {{
|
220
|
+
:name => unique { /\w+/.gen }
|
221
|
+
:email => unique {|x| "person-#{x}@example.com" }
|
222
|
+
}}
|
268
223
|
|
269
|
-
[User.gen.email, User.gen.email]
|
270
|
-
# => ["person-0@example.com", "person-1@example.com"]
|
224
|
+
[User.gen.email, User.gen.email]
|
225
|
+
# => ["person-0@example.com", "person-1@example.com"]
|
271
226
|
|
272
|
-
names = ['bob', 'tom', 'bob']
|
273
|
-
Person.fix {{
|
274
|
-
|
275
|
-
|
276
|
-
}}
|
227
|
+
names = ['bob', 'tom', 'bob']
|
228
|
+
Person.fix {{
|
229
|
+
:name => (name = names.shift)
|
230
|
+
:email => unique(name) {|x| "#{name}-#{x}@example.com" }
|
231
|
+
}}
|
277
232
|
|
278
|
-
[Person.gen.email, Person.gen.email, Person.gen.email]
|
279
|
-
# => ["bob-0@example.com", "tom-0@example.com", "bob-1@example.com"]
|
233
|
+
[Person.gen.email, Person.gen.email, Person.gen.email]
|
234
|
+
# => ["bob-0@example.com", "tom-0@example.com", "bob-1@example.com"]
|
280
235
|
|
281
|
-
|
236
|
+
== Best Practices
|
282
237
|
|
283
|
-
|
238
|
+
=== Specs
|
284
239
|
|
285
|
-
The suggested way to use dm-sweatshop with test specs is to create a
|
240
|
+
The suggested way to use <tt>dm-sweatshop</tt> with test specs is to create a <tt>spec/spec_fixtures.rb</tt> file, then declare your fixtures in there. Next, @require@ it in your @spec/spec_helper.rb@ file, after your models have loaded.
|
286
241
|
|
287
|
-
<pre>
|
288
|
-
<code>
|
289
242
|
Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
|
290
243
|
|
291
244
|
require 'dm-sweatshop'
|
292
245
|
require File.join(File.dirname(__FILE__), 'spec_fixtures')
|
293
|
-
</code>
|
294
|
-
</pre>
|
295
246
|
|
296
|
-
Add the
|
247
|
+
Add the <tt>.generate</tt> calls in your <tt>before</tt> setup. Make sure to clear your tables or <tt>auto_migrate</tt> your models after each spec!
|
297
248
|
|
298
|
-
|
249
|
+
== Possible Improvements
|
299
250
|
|
300
|
-
|
251
|
+
=== Enforcing Validations
|
301
252
|
|
302
253
|
Enforce validations at generation time, before the call to @new@/@create@.
|
303
254
|
|
304
|
-
|
255
|
+
=== Better Exception Handling
|
305
256
|
|
306
|
-
|
257
|
+
=== Smarter <tt>pick</tt>
|
307
258
|
|
308
259
|
Add multiple contexts to pick, or an ability to _fall back_ if one context has no generated models.
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'rubygems'
|
3
2
|
|
4
3
|
ROOT = Pathname(__FILE__).dirname.expand_path
|
5
4
|
JRUBY = RUBY_PLATFORM =~ /java/
|
@@ -14,10 +13,10 @@ GEM_NAME = 'dm-sweatshop'
|
|
14
13
|
GEM_VERSION = DataMapper::Sweatshop::VERSION
|
15
14
|
GEM_DEPENDENCIES = [['dm-core', GEM_VERSION], ['randexp', '~>0.1.4']]
|
16
15
|
GEM_CLEAN = %w[ log pkg coverage ]
|
17
|
-
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.
|
16
|
+
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.rdoc LICENSE TODO History.rdoc ] }
|
18
17
|
|
19
18
|
PROJECT_NAME = 'datamapper'
|
20
|
-
PROJECT_URL = "http://github.com/
|
19
|
+
PROJECT_URL = "http://github.com/datamapper/dm-more/tree/master/#{GEM_NAME}"
|
21
20
|
PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for building pseudo random models'
|
22
21
|
|
23
22
|
[ ROOT, ROOT.parent ].each do |dir|
|
data/lib/dm-sweatshop/version.rb
CHANGED
data/lib/dm-sweatshop.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
gem 'dm-core', '0.9.11'
|
4
|
-
require 'dm-core'
|
5
|
-
|
6
|
-
gem 'randexp', '~>0.1.4'
|
7
1
|
require 'randexp'
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
require
|
12
|
-
require dir / 'sweatshop'
|
13
|
-
require dir / 'model'
|
14
|
-
require dir / 'unique'
|
3
|
+
require 'dm-sweatshop/sweatshop'
|
4
|
+
require 'dm-sweatshop/model'
|
5
|
+
require 'dm-sweatshop/unique'
|
@@ -1,27 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require 'dm-validations'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe DataMapper::Model do
|
5
4
|
|
6
|
-
class
|
5
|
+
class Widget
|
7
6
|
include DataMapper::Resource
|
8
|
-
property :id,
|
7
|
+
property :id, Serial
|
9
8
|
property :type, Discriminator
|
10
9
|
property :name, String
|
11
10
|
property :price, Integer
|
12
11
|
|
13
|
-
belongs_to :order
|
12
|
+
belongs_to :order, :nullable => true
|
14
13
|
validates_present :price
|
15
14
|
end
|
16
15
|
|
17
|
-
class
|
16
|
+
class Wonket < Widget
|
18
17
|
property :size, String
|
19
18
|
end
|
20
19
|
|
21
|
-
class
|
20
|
+
class Order
|
22
21
|
include DataMapper::Resource
|
23
22
|
|
24
|
-
property :id,
|
23
|
+
property :id, Serial
|
25
24
|
|
26
25
|
has n, :widgets
|
27
26
|
end
|
@@ -55,7 +54,7 @@ describe DataMapper::Model do
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
|
-
|
57
|
+
it "should allow handle complex named fixtures" do
|
59
58
|
Wonket.fix {{
|
60
59
|
:name => /\w+ Wonket/.gen.capitalize,
|
61
60
|
:price => /\d{2,3}99/.gen.to_i,
|
@@ -88,7 +87,6 @@ describe DataMapper::Model do
|
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
91
|
-
|
92
90
|
describe ".make" do
|
93
91
|
before :each do
|
94
92
|
Widget.fix(:red) {{
|
@@ -105,11 +103,10 @@ describe DataMapper::Model do
|
|
105
103
|
end
|
106
104
|
|
107
105
|
it "returns a new object" do
|
108
|
-
@widget.should
|
106
|
+
@widget.should be_new
|
109
107
|
end
|
110
108
|
end
|
111
109
|
|
112
|
-
|
113
110
|
describe ".generate" do
|
114
111
|
before :each do
|
115
112
|
Widget.fix(:red) {{
|
@@ -130,12 +127,12 @@ describe DataMapper::Model do
|
|
130
127
|
end
|
131
128
|
|
132
129
|
it "returns a saved object" do
|
133
|
-
@widget.
|
130
|
+
@widget.should be_saved
|
134
131
|
end
|
135
132
|
|
136
133
|
it "does not save invalid model" do
|
137
134
|
blue_widget = Widget.gen(:blue)
|
138
|
-
blue_widget.should
|
135
|
+
blue_widget.should be_new
|
139
136
|
end
|
140
137
|
end
|
141
138
|
|
@@ -146,12 +143,10 @@ describe DataMapper::Model do
|
|
146
143
|
}}
|
147
144
|
|
148
145
|
blue_widget = Widget.gen!(:blue)
|
149
|
-
blue_widget.
|
146
|
+
blue_widget.should be_saved
|
150
147
|
end
|
151
148
|
end
|
152
149
|
|
153
|
-
|
154
|
-
|
155
150
|
describe ".pick" do
|
156
151
|
before :each do
|
157
152
|
Widget.fix(:red) {{
|
@@ -187,7 +182,6 @@ describe DataMapper::Model do
|
|
187
182
|
end
|
188
183
|
end
|
189
184
|
|
190
|
-
|
191
185
|
describe ".generate_attributes" do
|
192
186
|
before :each do
|
193
187
|
Widget.fix(:red) {{
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Sweatshop do
|
4
4
|
|
5
|
-
class
|
5
|
+
class Parent
|
6
6
|
include DataMapper::Resource
|
7
|
-
property :id,
|
7
|
+
property :id, Serial
|
8
8
|
property :type, Discriminator
|
9
9
|
property :first_name, String
|
10
10
|
property :last_name, String
|
11
11
|
end
|
12
12
|
|
13
|
-
class
|
13
|
+
class Child < Parent
|
14
14
|
property :age, Integer
|
15
15
|
end
|
16
16
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'parse_tree'
|
@@ -7,15 +7,15 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe DataMapper::Sweatshop::Unique do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
self.count_map = Hash.new() { 0 }
|
16
|
-
end
|
10
|
+
describe '#unique' do
|
11
|
+
before(:each) do
|
12
|
+
@ss = DataMapper::Sweatshop
|
13
|
+
DataMapper::Sweatshop::UniqueWorker.class_eval do
|
14
|
+
self.count_map = Hash.new() { 0 }
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
18
|
+
unless skip_tests
|
19
19
|
it 'for the same block, yields an incrementing value' do
|
20
20
|
(1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
|
21
21
|
%w(a0 a1 a2)
|
@@ -29,55 +29,55 @@ describe DataMapper::Sweatshop::Unique do
|
|
29
29
|
(1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
|
30
30
|
%w(a3 a4 a5)
|
31
31
|
end
|
32
|
+
else
|
33
|
+
it 'requires the ParseTree gem to test'
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
(1..
|
37
|
-
|
36
|
+
describe 'when the block has an arity less than 1' do
|
37
|
+
it 'keeps yielding until a unique value is generated' do
|
38
|
+
a = [1,1,1,2]
|
39
|
+
(1..2).collect { @ss.unique(:a) { a.shift }}.should ==
|
40
|
+
[1, 2]
|
38
41
|
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
(1..
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'raises when a unique value cannot be generated' do
|
48
|
-
a = [1,1,1, nil]
|
49
|
-
lambda {
|
50
|
-
(1..3).collect { @ss.unique { a.shift }}
|
51
|
-
}.should raise_error(DataMapper::Sweatshop::Unique::TooManyTriesException)
|
52
|
-
end
|
43
|
+
it 'raises when a unique value cannot be generated' do
|
44
|
+
a = [1,1,1, nil]
|
45
|
+
lambda {
|
46
|
+
(1..3).collect { @ss.unique(:a) { a.shift }}
|
47
|
+
}.should raise_error(DataMapper::Sweatshop::Unique::TooManyTriesException)
|
53
48
|
end
|
49
|
+
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
51
|
+
it 'allows an optional key to be specified' do
|
52
|
+
(1..3).to_a.collect { @ss.unique(:a) {|x| "a#{x}"} }.should ==
|
53
|
+
%w(a0 a1 a2)
|
54
|
+
(1..3).to_a.collect { @ss.unique(:b) {|x| "a#{x}"} }.should ==
|
55
|
+
%w(a0 a1 a2)
|
56
|
+
end
|
62
57
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
describe 'when ParseTree is unavilable' do
|
59
|
+
it 'raises when no key is provided' do
|
60
|
+
Object.stub!(:const_defined?).with("ParseTree").and_return(false)
|
61
|
+
lambda {
|
62
|
+
@ss.unique {}
|
63
|
+
}.should raise_error
|
68
64
|
end
|
69
|
-
end
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
obj.extend(DataMapper::Sweatshop::Unique)
|
76
|
-
new = obj.public_methods
|
77
|
-
(new - old).should == ["unique"]
|
66
|
+
it 'does not raise when a key is provided' do
|
67
|
+
lambda {
|
68
|
+
@ss.unique(:a) { "a" }
|
69
|
+
}.should_not raise_error
|
78
70
|
end
|
79
71
|
end
|
80
|
-
|
81
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'when mixing into an object' do
|
75
|
+
it 'only the unique method is added to the public interface' do
|
76
|
+
obj = Object.new
|
77
|
+
old = obj.public_methods
|
78
|
+
obj.extend(DataMapper::Sweatshop::Unique)
|
79
|
+
new = obj.public_methods
|
80
|
+
(new - old).collect {|x| x.to_s }.should == ["unique"]
|
81
|
+
end
|
82
82
|
end
|
83
83
|
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,43 @@
|
|
1
|
-
require 'pathname'
|
2
1
|
require 'rubygems'
|
3
2
|
|
4
|
-
|
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)
|
5
6
|
require 'dm-core'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
lib = ROOT.parent.join('dm-validations', 'lib').expand_path
|
11
|
-
$LOAD_PATH.unshift(lib) if lib.directory?
|
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)
|
12
11
|
require 'dm-validations'
|
13
12
|
|
14
|
-
|
13
|
+
# Support running specs with 'rake spec' and 'spec'
|
14
|
+
$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
|
15
|
+
|
16
|
+
require 'dm-sweatshop'
|
17
|
+
|
18
|
+
def load_driver(name, default_uri)
|
19
|
+
return false if ENV['ADAPTER'] != name.to_s
|
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
|
29
|
+
end
|
30
|
+
|
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
|
+
|
15
37
|
|
16
|
-
|
38
|
+
begin
|
39
|
+
Randexp::Dictionary.load_dictionary
|
40
|
+
rescue RuntimeError
|
41
|
+
warn '[WARNING] Neither /usr/share/dict/words or /usr/dict/words found, skipping dm-sweatshop specs'
|
42
|
+
exit
|
43
|
+
end
|
data/tasks/install.rb
CHANGED
@@ -4,7 +4,7 @@ end
|
|
4
4
|
|
5
5
|
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
6
|
task :install => [ :package ] do
|
7
|
-
sudo_gem "install
|
7
|
+
sudo_gem "install pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
8
|
end
|
9
9
|
|
10
10
|
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
data/tasks/spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
gem 'rspec', '~>1.2'
|
3
|
-
require 'spec'
|
4
2
|
require 'spec/rake/spectask'
|
5
3
|
|
6
4
|
task :default => [ :spec ]
|
@@ -8,16 +6,18 @@ begin
|
|
8
6
|
desc 'Run specifications'
|
9
7
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
8
|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
-
t.
|
9
|
+
t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
|
12
10
|
|
13
11
|
begin
|
14
|
-
|
12
|
+
require 'rcov'
|
15
13
|
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
14
|
t.rcov_opts << '--exclude' << 'spec'
|
17
15
|
t.rcov_opts << '--text-summary'
|
18
16
|
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
17
|
rescue LoadError
|
20
18
|
# rcov not installed
|
19
|
+
rescue SyntaxError
|
20
|
+
# rcov syntax invalid
|
21
21
|
end
|
22
22
|
end
|
23
23
|
rescue LoadError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-sweatshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Burkert
|
@@ -9,29 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: dm-core
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.11
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: randexp
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.4
|
34
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
35
16
|
description: DataMapper plugin for building pseudo random models
|
36
17
|
email:
|
37
18
|
- ben [a] benburkert [d] com
|
@@ -40,15 +21,15 @@ executables: []
|
|
40
21
|
extensions: []
|
41
22
|
|
42
23
|
extra_rdoc_files:
|
43
|
-
- README.
|
24
|
+
- README.rdoc
|
44
25
|
- LICENSE
|
45
26
|
- TODO
|
46
|
-
- History.
|
27
|
+
- History.rdoc
|
47
28
|
files:
|
48
|
-
- History.
|
29
|
+
- History.rdoc
|
49
30
|
- LICENSE
|
50
31
|
- Manifest.txt
|
51
|
-
- README.
|
32
|
+
- README.rdoc
|
52
33
|
- Rakefile
|
53
34
|
- TODO
|
54
35
|
- lib/dm-sweatshop.rb
|
@@ -64,11 +45,13 @@ files:
|
|
64
45
|
- tasks/install.rb
|
65
46
|
- tasks/spec.rb
|
66
47
|
has_rdoc: true
|
67
|
-
homepage: http://github.com/
|
48
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/dm-sweatshop
|
49
|
+
licenses: []
|
50
|
+
|
68
51
|
post_install_message:
|
69
52
|
rdoc_options:
|
70
53
|
- --main
|
71
|
-
- README.
|
54
|
+
- README.rdoc
|
72
55
|
require_paths:
|
73
56
|
- lib
|
74
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -86,9 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
69
|
requirements: []
|
87
70
|
|
88
71
|
rubyforge_project: datamapper
|
89
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.5
|
90
73
|
signing_key:
|
91
|
-
specification_version:
|
74
|
+
specification_version: 3
|
92
75
|
summary: DataMapper plugin for building pseudo random models
|
93
76
|
test_files: []
|
94
77
|
|