dm-sweatshop 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,16 @@
1
- === 0.9.7
1
+ === 0.9.8 / 2008-12-07
2
2
 
3
- * 2 major enhancements
3
+ * 1 minor enhancement:
4
+
5
+ * callable values now automatically expanded
6
+
7
+ * 1 bug fix:
8
+
9
+ * Now requiring with gem() calls and tested versions
10
+
11
+ === 0.9.7 / 2008-11-18
12
+
13
+ * 2 major enhancements:
4
14
 
5
15
  * Reworked unique model generator.
6
16
  * Improved documentation.
data/Manifest.txt CHANGED
@@ -2,7 +2,6 @@ History.txt
2
2
  LICENSE
3
3
  Manifest.txt
4
4
  README.textile
5
- README.txt
6
5
  Rakefile
7
6
  TODO
8
7
  lib/dm-sweatshop.rb
@@ -15,3 +14,5 @@ spec/dm-sweatshop/sweatshop_spec.rb
15
14
  spec/dm-sweatshop/unique_spec.rb
16
15
  spec/spec.opts
17
16
  spec/spec_helper.rb
17
+ tasks/install.rb
18
+ tasks/spec.rb
data/README.textile CHANGED
@@ -288,6 +288,7 @@ The suggested way to use dm-sweatshop with test specs is to create a @spec/spec_
288
288
  <code>
289
289
  Merb.start_environment(:testing => true, :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'test')
290
290
 
291
+ require 'dm-sweatshop'
291
292
  require File.join(File.dirname(__FILE__), 'spec_fixtures')
292
293
  </code>
293
294
  </pre>
data/Rakefile CHANGED
@@ -1,63 +1,25 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'spec/rake/spectask'
4
1
  require 'pathname'
2
+ require 'rubygems'
3
+
4
+ ROOT = Pathname(__FILE__).dirname.expand_path
5
+ JRUBY = RUBY_PLATFORM =~ /java/
6
+ WINDOWS = Gem.win_platform?
7
+ SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
5
8
 
6
- ROOT = Pathname(__FILE__).dirname.expand_path
7
9
  require ROOT + 'lib/dm-sweatshop/version'
8
10
 
9
- AUTHOR = "Ben Burkert"
10
- EMAIL = "ben@benburkert.com"
11
- GEM_NAME = "dm-sweatshop"
11
+ AUTHOR = 'Ben Burkert'
12
+ EMAIL = 'ben [a] benburkert [d] com'
13
+ GEM_NAME = 'dm-sweatshop'
12
14
  GEM_VERSION = DataMapper::Sweatshop::VERSION
13
- GEM_DEPENDENCIES = [["dm-core", GEM_VERSION], "randexp"]
14
- GEM_CLEAN = ["log", "pkg"]
15
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.textile LICENSE TODO ] }
16
-
17
- PROJECT_NAME = "datamapper"
18
- PROJECT_URL = "http://github.com/sam/dm-more/tree/master/dm-Sweatshop"
19
- PROJECT_DESCRIPTION = PROJECT_SUMMARY = "DataMapper plugin for building pseudo random models"
20
-
21
- require ROOT.parent + 'tasks/hoe'
22
-
23
- task :default => [ :spec ]
24
-
25
- WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
26
- SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
27
-
28
- desc "Install #{GEM_NAME} #{GEM_VERSION} (default ruby)"
29
- task :install => [ :package, :install_randexp ] do
30
- sh "#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources", :verbose => false
31
- end
32
-
33
- desc "Install the randexp gem from rubyforge"
34
- task :install_randexp do
35
- sh "#{SUDO} gem install randexp --no-update-sources", :verbose => false
36
- end
37
-
38
- desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
39
- task :uninstall => [ :clobber ] do
40
- sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
41
- end
42
-
43
- namespace :jruby do
44
- desc "Install #{GEM_NAME} #{GEM_VERSION} with JRuby"
45
- task :install => [ :package ] do
46
- sh %{#{SUDO} jruby -S gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}, :verbose => false
47
- end
48
- end
15
+ GEM_DEPENDENCIES = [['dm-core', "~>#{GEM_VERSION}"], ['randexp', '~>0.1.4']]
16
+ GEM_CLEAN = %w[ log pkg coverage ]
17
+ GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.textile LICENSE TODO History.txt ] }
49
18
 
50
- desc 'Run specifications'
51
- Spec::Rake::SpecTask.new(:spec) do |t|
52
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
53
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
19
+ PROJECT_NAME = 'datamapper'
20
+ PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
21
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for building pseudo random models'
54
22
 
55
- begin
56
- t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
57
- t.rcov_opts << '--exclude' << 'spec'
58
- t.rcov_opts << '--text-summary'
59
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
60
- rescue Exception
61
- # rcov not installed
62
- end
23
+ [ ROOT, ROOT.parent ].each do |dir|
24
+ Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
63
25
  end
@@ -101,12 +101,31 @@ module DataMapper
101
101
  proc = model_map[klass][name.to_sym].pick
102
102
 
103
103
  if proc
104
- proc.call
104
+ expand_callable_values(proc.call)
105
105
  elsif klass.superclass.is_a?(DataMapper::Model)
106
106
  attributes(klass.superclass, name)
107
107
  else
108
108
  raise NoFixtureExist, "#{name} fixture was not found for class #{klass}"
109
109
  end
110
110
  end
111
+
112
+ # Returns a Hash with callable values evaluated.
113
+ #
114
+ # @param hash [Hash]
115
+ #
116
+ # @returns [Hash] existing instance of a model from the model map
117
+ #
118
+ # @api private
119
+ def self.expand_callable_values(hash)
120
+ expanded = {}
121
+ hash.each do |key, value|
122
+ if value.respond_to?(:call)
123
+ expanded[key] = value.call
124
+ else
125
+ expanded[key] = value
126
+ end
127
+ end
128
+ expanded
129
+ end
111
130
  end
112
131
  end
@@ -57,6 +57,7 @@ module DataMapper
57
57
  MAX_TRIES = 10
58
58
 
59
59
  begin
60
+ gem 'ParseTree', '~>3.0.2'
60
61
  require 'parse_tree'
61
62
  rescue LoadError
62
63
  puts "DataMapper::Sweatshop::Unique - ParseTree could not be loaded, anonymous uniques will not be allowed"
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  class Sweatshop
3
- VERSION = "0.9.7"
3
+ VERSION = '0.9.8'
4
4
  end
5
5
  end
data/lib/dm-sweatshop.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require 'rubygems'
2
2
 
3
- gem 'dm-core', '~>0.9.7'
3
+ gem 'dm-core', '~>0.9.8'
4
4
  require 'dm-core'
5
+
6
+ gem 'randexp', '~>0.1.4'
5
7
  require 'randexp'
6
8
 
7
9
  dir = Pathname(__FILE__).dirname.expand_path / 'dm-sweatshop'
8
10
 
9
- require dir / "version"
10
- require dir / "sweatshop"
11
- require dir / "model"
12
- require dir / "unique"
11
+ require dir / 'version'
12
+ require dir / 'sweatshop'
13
+ require dir / 'model'
14
+ require dir / 'unique'
@@ -142,8 +142,14 @@ describe DataMapper::Model do
142
142
  :price => 30
143
143
  }}
144
144
 
145
+ Widget.fix(:blue) {{
146
+ :name => Proc.new { "b" + "lu" },
147
+ :price => 40
148
+ }}
149
+
145
150
  @red = Widget.gen(:red)
146
151
  @yellow = Widget.gen(:yellow)
152
+ @blue = Widget.gen(:blue)
147
153
  end
148
154
 
149
155
  it "returns a pre existing object with named attributes hash" do
@@ -153,6 +159,10 @@ describe DataMapper::Model do
153
159
  @yellow.name.should == "giallo"
154
160
  @yellow.price.should == 30
155
161
  end
162
+
163
+ it "expands callable values of attributes hash" do
164
+ @blue.name.should == "blu"
165
+ end
156
166
  end
157
167
 
158
168
 
@@ -51,6 +51,14 @@ describe DataMapper::Sweatshop do
51
51
  end
52
52
  end
53
53
 
54
+ describe ".expand_callable_values" do
55
+ it 'evalues values that respond to call' do
56
+ DataMapper::Sweatshop.
57
+ expand_callable_values({ :value => Proc.new { "a" + "b" } }).
58
+ should == { :value => "ab" }
59
+ end
60
+ end
61
+
54
62
  describe ".attributes" do
55
63
  it "should return an attributes hash" do
56
64
  DataMapper::Sweatshop.add(Parent, :default) {{
@@ -70,6 +78,15 @@ describe DataMapper::Sweatshop do
70
78
  DataMapper::Sweatshop.attributes(Parent, :default).should == {:calls => 2}
71
79
  end
72
80
 
81
+ it "expands callable values" do
82
+ DataMapper::Sweatshop.add(Parent, :default) do
83
+ { :value => Proc.new { "a" + "b" } }
84
+ end
85
+ DataMapper::Sweatshop.attributes(Parent, :default).should == {
86
+ :value => "ab"
87
+ }
88
+ end
89
+
73
90
  it "should call attributes with the superclass if the class is not mapped" do
74
91
  DataMapper::Sweatshop.add(Parent, :default) {{:first_name => 'Bob'}}
75
92
  DataMapper::Sweatshop.attributes(Child, :default).should == {:first_name => 'Bob'}
@@ -1,73 +1,83 @@
1
1
  require(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
2
 
3
+ begin
4
+ require 'parse_tree'
5
+ rescue LoadError
6
+ skip_tests = true
7
+ end
8
+
3
9
  describe DataMapper::Sweatshop::Unique do
4
- describe '#unique' do
5
- before(:each) do
6
- @ss = DataMapper::Sweatshop
7
- DataMapper::Sweatshop::UniqueWorker.class_eval do
8
- self.count_map = Hash.new() { 0 }
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
9
17
  end
10
- end
11
-
12
- it 'for the same block, yields an incrementing value' do
13
- (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
14
- %w(a0 a1 a2)
15
- end
16
-
17
- it 'for the different blocks, yields separately incrementing values' do
18
- (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
19
- %w(a0 a1 a2)
20
- (1..3).to_a.collect { @ss.unique {|x| "b#{x}"} }.should ==
21
- %w(b0 b1 b2)
22
- (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
23
- %w(a3 a4 a5)
24
- end
25
18
 
26
- it 'allows an optional key to be specified' do
27
- (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
28
- %w(a0 a1 a2)
29
- (1..3).to_a.collect { @ss.unique(:a) {|x| "a#{x}"} }.should ==
30
- %w(a0 a1 a2)
31
- end
19
+ it 'for the same block, yields an incrementing value' do
20
+ (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
21
+ %w(a0 a1 a2)
22
+ end
32
23
 
33
- describe 'when the block has an arity less than 1' do
34
- it 'keeps yielding until a unique value is generated' do
35
- a = [1,1,1,2]
36
- (1..2).collect { @ss.unique { a.shift }}.should ==
37
- [1, 2]
24
+ it 'for the different blocks, yields separately incrementing values' do
25
+ (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
26
+ %w(a0 a1 a2)
27
+ (1..3).to_a.collect { @ss.unique {|x| "b#{x}"} }.should ==
28
+ %w(b0 b1 b2)
29
+ (1..3).to_a.collect { @ss.unique {|x| "a#{x}"} }.should ==
30
+ %w(a3 a4 a5)
38
31
  end
39
32
 
40
- it 'raises when a unique value cannot be generated' do
41
- a = [1,1,1, nil]
42
- lambda {
43
- (1..3).collect { @ss.unique { a.shift }}
44
- }.should raise_error(DataMapper::Sweatshop::Unique::TooManyTriesException)
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)
45
38
  end
46
- end
47
39
 
48
- describe 'when ParseTree is unavilable' do
49
- it 'raises when no key is provided' do
50
- Object.stub!(:const_defined?).with("ParseTree").and_return(false)
51
- lambda {
52
- @ss.unique {}
53
- }.should raise_error
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
54
53
  end
55
54
 
56
- it 'does not raise when a key is provided' do
57
- lambda {
58
- @ss.unique(:a) {}
59
- }.should_not raise_error
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
62
+
63
+ it 'does not raise when a key is provided' do
64
+ lambda {
65
+ @ss.unique(:a) {}
66
+ }.should_not raise_error
67
+ end
60
68
  end
61
69
  end
62
- end
63
70
 
64
- describe 'when mixing into an object' do
65
- it 'only the unique method is added to the public interface' do
66
- obj = Object.new
67
- old = obj.public_methods
68
- obj.extend(DataMapper::Sweatshop::Unique)
69
- new = obj.public_methods
70
- (new - old).should == ["unique"]
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"]
78
+ end
71
79
  end
80
+ else
81
+ it 'requires the ParseTree gem to test'
72
82
  end
73
83
  end
data/spec/spec.opts CHANGED
@@ -1,2 +1 @@
1
- --format specdoc
2
1
  --colour
data/tasks/install.rb ADDED
@@ -0,0 +1,13 @@
1
+ def sudo_gem(cmd)
2
+ sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
3
+ end
4
+
5
+ desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
+ task :install => [ :package ] do
7
+ sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
+ end
9
+
10
+ desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
11
+ task :uninstall => [ :clobber ] do
12
+ sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
13
+ end
data/tasks/spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ begin
2
+ gem 'rspec', '~>1.1.11'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => [ :spec ]
7
+
8
+ desc 'Run specifications'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ 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)
12
+
13
+ begin
14
+ gem 'rcov', '~>0.8'
15
+ t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
+ t.rcov_opts << '--exclude' << 'spec'
17
+ t.rcov_opts << '--text-summary'
18
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
+ rescue LoadError
20
+ # rcov not installed
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # rspec not installed
25
+ end
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.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Burkert
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-18 00:00:00 -08:00
12
+ date: 2008-12-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,9 +18,9 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "="
21
+ - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.7
23
+ version: 0.9.8
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: randexp
@@ -28,23 +28,13 @@ dependencies:
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 1.8.2
33
+ version: 0.1.4
44
34
  version:
45
35
  description: DataMapper plugin for building pseudo random models
46
36
  email:
47
- - ben@benburkert.com
37
+ - ben [a] benburkert [d] com
48
38
  executables: []
49
39
 
50
40
  extensions: []
@@ -53,12 +43,12 @@ extra_rdoc_files:
53
43
  - README.textile
54
44
  - LICENSE
55
45
  - TODO
46
+ - History.txt
56
47
  files:
57
48
  - History.txt
58
49
  - LICENSE
59
50
  - Manifest.txt
60
51
  - README.textile
61
- - README.txt
62
52
  - Rakefile
63
53
  - TODO
64
54
  - lib/dm-sweatshop.rb
@@ -71,8 +61,10 @@ files:
71
61
  - spec/dm-sweatshop/unique_spec.rb
72
62
  - spec/spec.opts
73
63
  - spec/spec_helper.rb
64
+ - tasks/install.rb
65
+ - tasks/spec.rb
74
66
  has_rdoc: true
75
- homepage: http://github.com/sam/dm-more/tree/master/dm-Sweatshop
67
+ homepage: http://github.com/sam/dm-more/tree/master/dm-sweatshop
76
68
  post_install_message:
77
69
  rdoc_options:
78
70
  - --main
data/README.txt DELETED
@@ -1,45 +0,0 @@
1
- = DM sweatshop
2
-
3
- Part of dm-more gems collection.
4
-
5
- == DESCRIPTION:
6
-
7
- * DM Sweatshop is a YAML fixture alternative that uses pure Ruby.
8
-
9
- == SYNOPSIS:
10
-
11
- See README.textile
12
-
13
- == REQUIREMENTS:
14
-
15
- * randexp
16
- * ParseTree (if you want to use uniq records generator)
17
-
18
- == INSTALL:
19
-
20
- * FIX (sudo gem install, anything else)
21
-
22
- == LICENSE:
23
-
24
- (The MIT License)
25
-
26
- Copyright (c) 2008 Ben Burkert & contributors
27
-
28
- Permission is hereby granted, free of charge, to any person obtaining
29
- a copy of this software and associated documentation files (the
30
- 'Software'), to deal in the Software without restriction, including
31
- without limitation the rights to use, copy, modify, merge, publish,
32
- distribute, sublicense, and/or sell copies of the Software, and to
33
- permit persons to whom the Software is furnished to do so, subject to
34
- the following conditions:
35
-
36
- The above copyright notice and this permission notice shall be
37
- included in all copies or substantial portions of the Software.
38
-
39
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
40
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
43
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
44
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.