-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16787 from bzwei/v2v_models
Introduce model changes for v2v
- Loading branch information
Showing
5 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class TransformationMapping < ApplicationRecord | ||
has_many :transformation_mapping_items, :dependent => :destroy | ||
|
||
validates :name, :presence => true, :uniqueness => true | ||
|
||
def destination(source) | ||
transformation_mapping_items.find_by(:source => source).try(:destination) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class TransformationMappingItem < ApplicationRecord | ||
belongs_to :transformation_mapping | ||
belongs_to :source, :polymorphic => true | ||
belongs_to :destination, :polymorphic => true | ||
|
||
validates :source_id, :uniqueness => {:scope => [:transformation_mapping_id, :source_type]} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryGirl.define do | ||
factory :transformation_mapping do | ||
sequence(:name) { |n| "Transformation Mapping #{seq_padded_for_sorting(n)}" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FactoryGirl.define do | ||
factory :transformation_mapping_item | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
describe TransformationMapping do | ||
describe '#destination' do | ||
let(:src) { FactoryGirl.create(:ems_cluster) } | ||
let(:dst) { FactoryGirl.create(:ems_cluster) } | ||
|
||
let(:mapping) do | ||
FactoryGirl.create( | ||
:transformation_mapping, | ||
:transformation_mapping_items => [TransformationMappingItem.new(:source => src, :destination => dst)] | ||
) | ||
end | ||
|
||
it "finds the destination" do | ||
expect(mapping.destination(src)).to eq(dst) | ||
end | ||
|
||
it "returns nil for unmapped source" do | ||
expect(mapping.destination(FactoryGirl.create(:ems_cluster))).to be_nil | ||
end | ||
end | ||
end |