Permalink
Browse files

Merge remote branch 'flogic/master'

* flogic/master:
  Setting version in README (0.4.2)
  Fixing specs for direct-call inherited generators.
  Keeping superclass generators when overriding some.
  • Loading branch information...
2 parents c4e383e + 2f5ebc2 commit 9512683a64c4bb8f83934e2e2efde66d038cd8e9 @nofxx nofxx committed Feb 28, 2010
Showing with 38 additions and 22 deletions.
  1. +1 −1 README.markdown
  2. +4 −1 lib/object_daddy.rb
  3. +33 −20 spec/object_daddy_spec.rb
View
@@ -1,6 +1,6 @@
Object Daddy
============
-_Version 0.4.1 (April 28, 2009)_
+_Version 0.4.2 (July 28, 2009)_
__Authors:__ [Rick Bradley](mailto:blogicx@rickbradley.com), [Yossef Mendelssohn](mailto:ymendel@pobox.com)
View
@@ -90,15 +90,18 @@ def generates_subclass(subclass_name)
def gather_exemplars
return if exemplars_generated
+
+ self.generators ||= {}
if superclass.respond_to?(:gather_exemplars)
superclass.gather_exemplars
- self.generators = (superclass.generators || {}).dup
+ self.generators = (superclass.generators).merge(generators).dup
end
exemplar_path.each do |raw_path|
path = File.join(raw_path, "#{underscore(name)}_exemplar.rb")
load(path) if File.exists?(path)
end
+
self.exemplars_generated = true
end
View
@@ -506,7 +506,7 @@ def self.generator_value_method(prev)
SubWidget.stubs(:exemplar_path).returns(@subfile_path)
File.open(@file_name, 'w') do |f|
- f.puts "class Widget\ngenerator_for :blah do |prev| 'blah'; end\nend\n"
+ f.puts "class Widget\ngenerator_for :blah do |prev| 'blah'; end\ngenerator_for :other do |prev| 'bang'; end\nend\n"
end
end
@@ -516,35 +516,48 @@ def self.generator_value_method(prev)
end
it 'should use generators from the parent class' do
- SubWidget.spawn.blah.should == 'blah'
+ SubWidget.spawn.other.should == 'bang'
+ SubWidget.spawn.blah.should == 'blah'
end
- it 'should let subclass generators override parent generators' do
- File.open(@subfile_name, 'w') do |f|
- f.puts "class SubWidget\ngenerator_for :blah do |prev| 'blip'; end\nend\n"
+ describe 'with subclass generators' do
+ before :each do
+ File.open(@subfile_name, 'w') do |f|
+ f.puts "class SubWidget\ngenerator_for :blah do |prev| 'blip'; end\nend\n"
+ end
+ end
+
+ it 'should still use generators from the parent class' do
+ SubWidget.spawn.other.should == 'bang'
+ end
+
+ it 'should allow overriding parent generators' do
+ SubWidget.spawn.blah.should == 'blip'
end
- SubWidget.spawn.blah.should == 'blip'
end
end
-
+
describe 'using generators called directly' do
+ before :each do
+ @class.generator_for :other do |prev| 'bang'; end
+ @class.generator_for :blah do |prev| 'blah'; end
+ end
+
it 'should use generators from the parent class' do
- @class.generator_for :blah do |prev| 'blah'; end
- @subclass.spawn.blah.should == 'blah'
+ @subclass.spawn.other.should == 'bang'
+ @subclass.spawn.blah.should == 'blah'
end
- it 'should let subclass generators override parent generators' do
- pending 'figuring out what to do about this, including deciding whether or not this is even important' do
- @class.generator_for :blah do |prev| 'blah'; end
- # p @class
- # p @subclass
- # @subclass.send(:gather_exemplars)
- # p @subclass.generators
+ describe 'with subclass generators' do
+ before :each do
@subclass.generator_for :blah do |prev| 'blip'; end
- # @subclass.send(:gather_exemplars)
- # p @subclass.generators
- # p @subclass.generators[:blah][:generator][:block].call
- # @subclass.send(:gather_exemplars)
+ end
+
+ it 'should still use generators from the parent class' do
+ @subclass.spawn.other.should == 'bang'
+ end
+
+ it 'should allow overriding parent generators' do
@subclass.spawn.blah.should == 'blip'
end
end

0 comments on commit 9512683

Please sign in to comment.