Permalink
Browse files

Merge pull request #46 from greis/fix_default_value

Fix reader to always return the same object
  • Loading branch information...
2 parents 3ae708c + c2a603b commit 076f78c5481bbc08d54f0bd9424fd83ab8eda540 @Empact committed Jun 15, 2012
Showing with 7 additions and 4 deletions.
  1. +2 −3 lib/roxml.rb
  2. +5 −1 spec/examples/search_query_spec.rb
View
5 lib/roxml.rb
@@ -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
View
6 spec/examples/search_query_spec.rb
@@ -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 076f78c

Please sign in to comment.