diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-01-05 23:05:16 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-01-05 23:05:16 -0200 |
commit | dfd22638c2773d843ea1d2e56992a6ac355b3ecb (patch) | |
tree | 1bf97bcb2f6928a32b6acb93ea9886925a0e21b4 /test/nodes/test_case.rb | |
parent | 347c7786f8e7ea0e9643ff707ce1ace8b3969d6c (diff) | |
parent | 4c7e50f9328aca4e294b41fce0832bf6ac4a939a (diff) | |
download | rails-dfd22638c2773d843ea1d2e56992a6ac355b3ecb.tar.gz rails-dfd22638c2773d843ea1d2e56992a6ac355b3ecb.tar.bz2 rails-dfd22638c2773d843ea1d2e56992a6ac355b3ecb.zip |
Merge pull request #400 from felixbuenemann/case-node
Implement CASE Conditional Expression
Diffstat (limited to 'test/nodes/test_case.rb')
-rw-r--r-- | test/nodes/test_case.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/test/nodes/test_case.rb b/test/nodes/test_case.rb new file mode 100644 index 0000000000..a813ec7e69 --- /dev/null +++ b/test/nodes/test_case.rb @@ -0,0 +1,82 @@ +require 'helper' + +module Arel + module Nodes + describe 'Case' do + describe '#initialize' do + it 'sets case expression from first argument' do + node = Case.new 'foo' + + assert_equal 'foo', node.case + end + + it 'sets default case from second argument' do + node = Case.new nil, 'bar' + + assert_equal 'bar', node.default + end + end + + describe '#clone' do + it 'clones case, conditions and default' do + foo = Nodes.build_quoted 'foo' + + node = Case.new + node.case = foo + node.conditions = [When.new(foo, foo)] + node.default = foo + + dolly = node.clone + + assert_equal dolly.case, node.case + refute_same dolly.case, node.case + + assert_equal dolly.conditions, node.conditions + refute_same dolly.conditions, node.conditions + + assert_equal dolly.default, node.default + refute_same dolly.default, node.default + end + end + + describe 'equality' do + it 'is equal with equal ivars' do + foo = Nodes.build_quoted 'foo' + one = Nodes.build_quoted 1 + zero = Nodes.build_quoted 0 + + case1 = Case.new foo + case1.conditions = [When.new(foo, one)] + case1.default = Else.new zero + + case2 = Case.new foo + case2.conditions = [When.new(foo, one)] + case2.default = Else.new zero + + array = [case1, case2] + + assert_equal 1, array.uniq.size + end + + it 'is not equal with different ivars' do + foo = Nodes.build_quoted 'foo' + bar = Nodes.build_quoted 'bar' + one = Nodes.build_quoted 1 + zero = Nodes.build_quoted 0 + + case1 = Case.new foo + case1.conditions = [When.new(foo, one)] + case1.default = Else.new zero + + case2 = Case.new foo + case2.conditions = [When.new(bar, one)] + case2.default = Else.new zero + + array = [case1, case2] + + assert_equal 2, array.uniq.size + end + end + end + end +end |