Skip to content

Commit

Permalink
Add method TransformationMapping#service_template_transformation_plans.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Apr 9, 2018
1 parent c9e7f02 commit 2c33e10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/models/transformation_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ class TransformationMapping < ApplicationRecord

validates :name, :presence => true, :uniqueness => true

virtual_has_many :service_template_transformation_plans

def destination(source)
transformation_mapping_items.find_by(:source => source).try(:destination)
end

def service_template_transformation_plans
ServiceResource.where(:resource => self).includes(:service_template).collect(&:service_template)
end
end
27 changes: 18 additions & 9 deletions spec/models/transformation_mapping_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
describe TransformationMapping do
describe '#destination' do
let(:src) { FactoryGirl.create(:ems_cluster) }
let(:dst) { FactoryGirl.create(:ems_cluster) }
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
let(:mapping) do
FactoryGirl.create(
:transformation_mapping,
:transformation_mapping_items => [TransformationMappingItem.new(:source => src, :destination => dst)]
)
end

describe '#destination' do
it "finds the destination" do
expect(mapping.destination(src)).to eq(dst)
end
Expand All @@ -18,4 +18,13 @@
expect(mapping.destination(FactoryGirl.create(:ems_cluster))).to be_nil
end
end

describe '#service_template_transformation_plans' do
let(:plan) { FactoryGirl.create(:service_template_transformation_plan) }
before { FactoryGirl.create(:service_resource, :resource => mapping, :service_template => plan) }

it 'finds the transformation plans' do
expect(mapping.service_template_transformation_plans).to match([plan])
end
end
end

0 comments on commit 2c33e10

Please sign in to comment.