Skip to content

Commit

Permalink
Nil parameter won't yield errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
razielgn committed Feb 22, 2013
1 parent a74a0d4 commit a9ce280
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/formulas.rb
Expand Up @@ -11,7 +11,7 @@ def self.included(base)
module ClassMethods module ClassMethods
def calculated_field(field) def calculated_field(field)
define_method("#{field}_calc") do define_method("#{field}_calc") do
code = send(field) code = send(field).to_s
sandbox_run(field, code) sandbox_run(field, code)
end end


Expand Down
9 changes: 9 additions & 0 deletions spec/formulas_spec.rb
Expand Up @@ -86,5 +86,14 @@ def initialize(params = {})
subject.attr1_error.should == 'SyntaxError' subject.attr1_error.should == 'SyntaxError'
end end
end end

context 'nil parameter' do
subject{ SimpleAttributes.new(attr1: nil) }

it 'should not store any errors' do
subject.attr1_calc.should be_nil
subject.attr1_error.should be_nil
end
end
end end
end end

0 comments on commit a9ce280

Please sign in to comment.