Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue with context including module that defines options method…

… which would raise error when trying to remove method
  • Loading branch information...
commit 55abbc7587c6cc467336169e4f0118857caa0209 1 parent a5f9656
@andriusch authored
Showing with 25 additions and 1 deletion.
  1. +5 −1 lib/blueprints/blueprint.rb
  2. +20 −0 spec/unit/blueprint_spec.rb
View
6 lib/blueprints/blueprint.rb
@@ -109,7 +109,11 @@ def with_method(environment, name, value)
environment.singleton_class.class_eval do
if method_defined?(name)
old_method = environment.method(name)
- remove_method(name)
+ if old_method.owner == self
+ remove_method(name)
+ else
+ old_method = nil
+ end
end
define_method(name) { value }
end
View
20 spec/unit/blueprint_spec.rb
@@ -112,6 +112,26 @@ def stage.attributes
stage.attributes.should == :attributes
end
+ it "should not try to remove options and attributes methods if they're not defined by singleton class" do
+ mod = Module.new do
+ def options
+ :options
+ end
+ def attributes
+ :attributes
+ end
+ end
+
+ stage_class = Class.new do
+ include mod
+ end
+ stage = stage_class.new
+
+ blueprint2.build(stage, :options => {:option => 'value'})
+ stage.options.should == :options
+ stage.attributes.should == :attributes
+ end
+
it "should normalize options and attributes" do
blueprint
stage.instance_variable_set(:@value, 2)
Please sign in to comment.
Something went wrong with that request. Please try again.