Skip to content

Commit

Permalink
Cover more with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remear committed Apr 1, 2016
1 parent 01e39c6 commit a84e1c1
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions test/active_model_serializers/transform_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
require 'test_helper'

class ActiveModelSerializers::TransformTest < ActiveSupport::TestCase
def test_camel
obj = Object.new
scenarios = [
{
value: { :some_key => 'value' },
expected: { :SomeKey => 'value' }
},
{
value: { 'some_key' => 'value' },
expected: { 'SomeKey' => 'value' }
},
{
value: :some_value,
expected: :SomeValue
},
{
value: obj,
expected: obj
},
{
value: nil,
expected: nil
}
]
scenarios.each do |s|
result = ActiveModelSerializers::Transform.camel(s[:value])
assert_equal s[:expected], result
end
end

def test_camel_lower
obj = Object.new
scenarios = [
{
value: { :some_key => 'value' },
expected: { :someKey => 'value' }
},
{
value: { 'some_key' => 'value' },
expected: { 'someKey' => 'value' }
},
{
value: :some_value,
expected: :someValue
},
{
value: obj,
expected: obj
},
{
value: nil,
expected: nil
}
]
scenarios.each do |s|
result = ActiveModelSerializers::Transform.camel_lower(s[:value])
assert_equal s[:expected], result
end
end

def test_dash
obj = Object.new
scenarios = [
{
value: { :some_key => 'value' },
expected: { :"some-key" => 'value' }
},
{
value: { 'some_key' => 'value' },
expected: { 'some-key' => 'value' }
},
{
value: :some_value,
expected: :"some-value"
},
{
value: obj,
expected: obj
},
{
value: nil,
expected: nil
}
]
scenarios.each do |s|
result = ActiveModelSerializers::Transform.dash(s[:value])
assert_equal s[:expected], result
end
end

def test_underscore
obj = Object.new
scenarios = [
{
value: { :"some-key" => 'value' },
expected: { :some_key => 'value' }
},
{
value: { 'some-key' => 'value' },
expected: { 'some_key' => 'value' }
},
{
value: :"some-value",
expected: :some_value
},
{
value: obj,
expected: obj
},
{
value: nil,
expected: nil
}
]
scenarios.each do |s|
result = ActiveModelSerializers::Transform.underscore(s[:value])
assert_equal s[:expected], result
end
end
end

0 comments on commit a84e1c1

Please sign in to comment.