Skip to content

Commit

Permalink
Merge pull request #5 from leifg/rename_to_morfer
Browse files Browse the repository at this point in the history
Name Test Morfer consistently
  • Loading branch information
leifg committed Jan 13, 2014
2 parents fef7a64 + dae690b commit 44af2ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions benchmarks/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ def stringify_keys hash
hash
end

class SimpleMappingSymbol < Morfo::Base
class SimpleMorferSymbol < Morfo::Base
BenchmarkData.row.keys.each do |field|
field(:"#{field}_mapped", from: field)
end
end

class SimpleMappingString < Morfo::Base
class SimpleMorferString < Morfo::Base
BenchmarkData.row_string_keys.keys.each do |field|
field("#{field}_mapped", from: field)
end
end

class NestedMappingSymbol < Morfo::Base
class NestedMorferSymbol < Morfo::Base
BenchmarkData.row_nested.each do |key, value|
value.keys.each do |field|
field(:"#{field}_mapped", from: [key, field])
end
end
end

class NestedMappingString < Morfo::Base
class NestedMorferString < Morfo::Base
BenchmarkData.row_nested_string_keys.each do |key, value|
value.keys.each do |field|
field("#{field}_mapped", from: [key, field])
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
{
label: 'Simple (strings)',
row: BenchmarkData.row_string_keys,
morf_class: BenchmarkData::SimpleMappingString
morf_class: BenchmarkData::SimpleMorferString
},
{
label: 'Simple (symbols)',
row: BenchmarkData.row,
morf_class: BenchmarkData::SimpleMappingSymbol
morf_class: BenchmarkData::SimpleMorferSymbol
},
{
label: 'Nested (strings)',
row: BenchmarkData.row_nested_string_keys,
morf_class: BenchmarkData::NestedMappingString
morf_class: BenchmarkData::NestedMorferString
},
{
label: 'Nested (symbols)',
row: BenchmarkData.row_nested,
morf_class: BenchmarkData::NestedMappingSymbol
morf_class: BenchmarkData::NestedMorferSymbol
},
]

Expand Down
2 changes: 1 addition & 1 deletion lib/morfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.field field_name, definition={}, &blk
else
raise(
ArgumentError,
"No field to map from is specified for #{field_name.inspect}"
"No field to get value from is specified for #{field_name.inspect}"
) unless definition[:from]
mapping_actions << Morfo::Actions::MapAction.new(definition[:from], field_name)
end
Expand Down
40 changes: 20 additions & 20 deletions spec/lib/morfo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
describe '#morf' do
context 'errors' do
subject(:no_from) do
class NilMapper < Morfo::Base
class NilMorfer < Morfo::Base
field :my_field, {}
end
NilMapper
NilMorfer
end
it 'raises error for nil field' do
expect{no_from.morf([])}.to raise_error(ArgumentError)
Expand All @@ -45,10 +45,10 @@ class NilMapper < Morfo::Base

context '1 to 1 conversion' do
subject do
class TitleMapper < Morfo::Base
class TitleMorfer < Morfo::Base
field :tv_show_title, from: :title
end
TitleMapper
TitleMorfer
end

it 'maps title correctly' do
Expand All @@ -65,10 +65,10 @@ class TitleMapper < Morfo::Base

context '1 to 1 conversion with transformation' do
subject do
class NumCastMapper < Morfo::Base
class NumCastMorfer < Morfo::Base
field(:cast_num, from: :cast){|v,r| v.size}
end
NumCastMapper
NumCastMorfer
end

it 'calls transformation correctly' do
Expand All @@ -79,11 +79,11 @@ class NumCastMapper < Morfo::Base

context '1 to many conversion' do
subject do
class MutliTitleMapper < Morfo::Base
class MutliTitleMorfer < Morfo::Base
field :title, from: :title
field :also_title, from: :title
end
MutliTitleMapper
MutliTitleMorfer
end

it 'maps title to multiple fields' do
Expand All @@ -95,24 +95,24 @@ class MutliTitleMapper < Morfo::Base
context 'nested conversion' do
context 'nested source' do
subject(:valid_path) do
class ImdbRatingMapper < Morfo::Base
class ImdbRatingMorfer < Morfo::Base
field :rating, from: [:ratings, :imdb]
end
ImdbRatingMapper
ImdbRatingMorfer
end

subject(:valid_path_with_transformation) do
class ImdbRatingMapper < Morfo::Base
class ImdbRatingMorfer < Morfo::Base
field(:rating, from: [:ratings, :imdb]){|v| "Rating: #{v}"}
end
ImdbRatingMapper
ImdbRatingMorfer
end

subject(:invalid_path) do
class InvalidImdbRatingMapper < Morfo::Base
class InvalidImdbRatingMorfer < Morfo::Base
field :rating, from: [:very, :long, :path, :that, :might, :not, :exist]
end
InvalidImdbRatingMapper
InvalidImdbRatingMorfer
end

it 'maps nested attributes' do
Expand All @@ -133,11 +133,11 @@ class InvalidImdbRatingMapper < Morfo::Base

context 'nested destination' do
subject do
class WrapperMapper < Morfo::Base
class WrapperMorfer < Morfo::Base
field([:tv_show, :title], from: :title)
field([:tv_show, :channel], from: :channel){|v| "Channel: #{v}"}
end
WrapperMapper
WrapperMorfer
end

it 'maps to nested destination' do
Expand All @@ -156,10 +156,10 @@ class WrapperMapper < Morfo::Base

context 'calculations' do
subject do
class TitlePrefixMapper < Morfo::Base
class TitlePrefixMorfer < Morfo::Base
field(:title_with_channel){|v,r| "#{r[:title]}, (#{r[:channel]})"}
end
TitlePrefixMapper
TitlePrefixMorfer
end

it 'maps calculation correctly' do
Expand All @@ -174,10 +174,10 @@ class TitlePrefixMapper < Morfo::Base

context 'static values' do
subject do
class StaticTitleMapper < Morfo::Base
class StaticTitleMorfer < Morfo::Base
field(:new_title){ 'Static Title' }
end
StaticTitleMapper
StaticTitleMorfer
end

it 'maps static value correctly' do
Expand Down

0 comments on commit 44af2ec

Please sign in to comment.