Skip to content

Commit

Permalink
fixed bug that did not properly construct object with its dependencie…
Browse files Browse the repository at this point in the history
…s when using a bound method

git-svn-id: svn+ssh://rubyforge.org/var/svn/atomicobjectrb/trunk/diy@111 7bd720c3-caf9-44c9-a48d-612f81e63739
  • Loading branch information
dewind committed May 21, 2008
1 parent a540c30 commit 169e84e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/diy.rb
Expand Up @@ -64,7 +64,8 @@ def get_object(obj_name)
unless obj
case @defs[key]
when MethodDef
@cache[key] = construct_method(key)
obj = construct_method(key)
@cache[key] = obj
else
obj = construct_object(key)
@cache[key] = obj if @defs[key].singleton?
Expand Down
6 changes: 6 additions & 0 deletions test/diy_test.rb
Expand Up @@ -564,6 +564,12 @@ def test_building_bounded_method_uses_object_in_diy_context_correctly
assert_not_equal(@diy['build_thing'], @diy['thing_builder'].method(:build))
end

def test_composing_bounded_methods_into_other_objects
load_context "functions/objects.yml"
@diy.build_everything
assert_same(@diy['build_thing'], @diy['things_builder'].build_thing)
end

def test_raises_construction_error_if_invalid_method_specified
load_context "functions/invalid_method.yml"
assert_raises DIY::ConstructionError do
Expand Down
6 changes: 5 additions & 1 deletion test/files/functions/objects.yml
Expand Up @@ -4,4 +4,8 @@ method_extractor:

method build_thing:
object: thing_builder
method: build
method: build

things_builder:
compose:
- build_thing
3 changes: 3 additions & 0 deletions test/files/functions/things_builder.rb
@@ -0,0 +1,3 @@
class ThingsBuilder
constructor :build_thing, :accessors => true
end

0 comments on commit 169e84e

Please sign in to comment.