Permalink
Browse files

Fix reader to always return the same object

  • Loading branch information...
1 parent 3ae708c commit c2a603b274a56f7fd651c5a8830db912ebbf6cf1 @greis greis committed Jun 6, 2012
Showing with 7 additions and 4 deletions.
  1. +2 −3 lib/roxml.rb
  2. +5 −1 spec/examples/search_query_spec.rb
View
@@ -480,10 +480,9 @@ def xml_accessor(*syms, &block)
def add_reader(attr)
define_method(attr.accessor) do
if instance_variable_get(attr.instance_variable_name).nil?
- attr.default
- else
- instance_variable_get(attr.instance_variable_name)
+ instance_variable_set(attr.instance_variable_name, attr.default)
end
+ instance_variable_get(attr.instance_variable_name)
end
end
end
@@ -15,8 +15,12 @@
@search.max_results == 20
end
+ it 'should return the same object for the default value' do
+ @search.language.object_id.should == @search.language.object_id
+ end
+
it 'should respect the defaults when loading from xml' do
@saved_search.language.should == 'EN'
@saved_search.max_results == 20
end
-end
+end

0 comments on commit c2a603b

Please sign in to comment.