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.
@@ -1,3 +1,7 @@
1
+ === 0.10.0 / 2009-10-15
2
+
3
+ * Updated to work with dm-core 0.10.0
4
+
1
5
  === 0.9.11 / 2009-03-29
2
6
 
3
7
  * No changes this version
data/Manifest.txt CHANGED
@@ -1,7 +1,7 @@
1
- History.txt
1
+ History.rdoc
2
2
  LICENSE
3
3
  Manifest.txt
4
- README.textile
4
+ README.rdoc
5
5
  Rakefile
6
6
  TODO
7
7
  lib/dm-sweatshop.rb
@@ -1,6 +1,6 @@
1
- h1. dm-sweatshop
1
+ = dm-sweatshop
2
2
 
3
- h2. Overview
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
- h2. How it works
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
- h2. Examples
39
+ == Examples
40
40
 
41
41
  Starting off with a simple user model.
42
- <pre>
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
- <pre>
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
- <pre>
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
- <pre>
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
- <pre>
98
- <code>
99
- Person.fixture(:valid) {{
100
- :first_name => %w(Michael Adam Guiseppe)[rand(3)],
101
- :last_name => %w(Smith Black White)[rand(3)],
102
- :email => "#{/\w{10}/.gen}@somedomain.info",
103
- :password_salt => (salt = /\w{20}/.gen),
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
- <pre>
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
- <pre>
120
- <code>
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
- h3. Associations
103
+ === Associations
128
104
 
129
105
  The real power of sweatshop is generating working associations.
130
- <pre>
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
- </code>
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
- h3. Contexts
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
- h3. Overriding a fixture
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 @generate@.
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
- h2. Unique values
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
- <pre><code>include DataMapper::Sweatshop::Unique # Use DataMapper::Sweatshop.unique if you don't want to pollute your namespace
217
+ include DataMapper::Sweatshop::Unique # Use DataMapper::Sweatshop.unique if you don't want to pollute your namespace
263
218
 
264
- User.fix {{
265
- :name => unique { /\w+/.gen }
266
- :email => unique {|x| "person-#{x}@example.com" }
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
- :name => (name = names.shift)
275
- :email => unique(name) {|x| "#{name}-#{x}@example.com" }
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"]</code></pre>
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
- h2. Best Practices
236
+ == Best Practices
282
237
 
283
- h3. Specs
238
+ === Specs
284
239
 
285
- The suggested way to use dm-sweatshop with test specs is to create a @spec/spec_fixtures.rb@ file, then declare your fixtures in there. Next, @require@ it in your @spec/spec_helper.rb@ file, after your models have loaded.
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 @.generate@ calls in your @before@ setup. Make sure to clear your tables or @auto_migrate@ your models after each spec!
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
- h2. Possible Improvements
249
+ == Possible Improvements
299
250
 
300
- h3. Enforcing Validations
251
+ === Enforcing Validations
301
252
 
302
253
  Enforce validations at generation time, before the call to @new@/@create@.
303
254
 
304
- h3. Better Exception Handling
255
+ === Better Exception Handling
305
256
 
306
- h3. Smarter @pick@
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.textile LICENSE TODO History.txt ] }
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/sam/dm-more/tree/master/#{GEM_NAME}"
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|
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  class Sweatshop
3
- VERSION = '0.9.11'
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
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
- dir = Pathname(__FILE__).dirname.expand_path / 'dm-sweatshop'
10
-
11
- require dir / 'version'
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 File.dirname(__FILE__) + '/../spec_helper'
2
- require 'dm-validations'
1
+ require 'spec_helper'
3
2
 
4
3
  describe DataMapper::Model do
5
4
 
6
- class ::Widget
5
+ class Widget
7
6
  include DataMapper::Resource
8
- property :id, Integer, :serial => true
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 ::Wonket < Widget
16
+ class Wonket < Widget
18
17
  property :size, String
19
18
  end
20
19
 
21
- class ::Order
20
+ class Order
22
21
  include DataMapper::Resource
23
22
 
24
- property :id, Integer, :serial => true
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
- it "should allow handle complex named fixtures" do
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 be_new_record
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.should_not be_new_record
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 be_new_record
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.should_not be_new_record
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 File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Sweatshop do
4
4
 
5
- class ::Parent
5
+ class Parent
6
6
  include DataMapper::Resource
7
- property :id, Integer, :serial => true
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 ::Child < Parent
13
+ class Child < Parent
14
14
  property :age, Integer
15
15
  end
16
16
 
@@ -1,4 +1,4 @@
1
- require(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
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
- unless skip_tests
11
- describe '#unique' do
12
- before(:each) do
13
- @ss = DataMapper::Sweatshop
14
- DataMapper::Sweatshop::UniqueWorker.class_eval do
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
- it 'allows an optional key to be specified' do
34
- (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
35
- %w(a0 a1 a2)
36
- (1..3).to_a.collect { @ss.unique(:a) {|x| "a#{x}"} }.should ==
37
- %w(a0 a1 a2)
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
- describe 'when the block has an arity less than 1' do
41
- it 'keeps yielding until a unique value is generated' do
42
- a = [1,1,1,2]
43
- (1..2).collect { @ss.unique { a.shift }}.should ==
44
- [1, 2]
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
- describe 'when ParseTree is unavilable' do
56
- it 'raises when no key is provided' do
57
- Object.stub!(:const_defined?).with("ParseTree").and_return(false)
58
- lambda {
59
- @ss.unique {}
60
- }.should raise_error
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
- it 'does not raise when a key is provided' do
64
- lambda {
65
- @ss.unique(:a) {}
66
- }.should_not raise_error
67
- end
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
- describe 'when mixing into an object' do
72
- it 'only the unique method is added to the public interface' do
73
- obj = Object.new
74
- old = obj.public_methods
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
- else
81
- it 'requires the ParseTree gem to test'
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
@@ -1 +1,2 @@
1
1
  --colour
2
+ --loadby random
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,43 @@
1
- require 'pathname'
2
1
  require 'rubygems'
3
2
 
4
- gem 'dm-core', '0.9.11'
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
- ROOT = Pathname(__FILE__).dirname.parent.expand_path
8
-
9
- # use local dm-validations if running from dm-more directly
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
- require ROOT + 'lib/dm-sweatshop'
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
- DataMapper.setup(:default, 'sqlite3::memory:')
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 --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
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.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
9
+ t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
12
10
 
13
11
  begin
14
- gem 'rcov', '~>0.8'
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.9.11
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-03-29 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
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.textile
24
+ - README.rdoc
44
25
  - LICENSE
45
26
  - TODO
46
- - History.txt
27
+ - History.rdoc
47
28
  files:
48
- - History.txt
29
+ - History.rdoc
49
30
  - LICENSE
50
31
  - Manifest.txt
51
- - README.textile
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/sam/dm-more/tree/master/dm-sweatshop
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.txt
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.1
72
+ rubygems_version: 1.3.5
90
73
  signing_key:
91
- specification_version: 2
74
+ specification_version: 3
92
75
  summary: DataMapper plugin for building pseudo random models
93
76
  test_files: []
94
77