From 71f732cf98a6d736c6610ab5247c156724cfd477 Mon Sep 17 00:00:00 2001 From: Lucy Fu Date: Mon, 9 Apr 2018 14:22:51 -0400 Subject: [PATCH] Add association of service_templates to TransformationMapping. --- app/models/transformation_mapping.rb | 2 ++ spec/models/transformation_mapping_spec.rb | 27 ++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/models/transformation_mapping.rb b/app/models/transformation_mapping.rb index 396aab5a584..f797ea3a18b 100644 --- a/app/models/transformation_mapping.rb +++ b/app/models/transformation_mapping.rb @@ -1,5 +1,7 @@ class TransformationMapping < ApplicationRecord has_many :transformation_mapping_items, :dependent => :destroy + has_many :service_resources, :as => :resource, :dependent => :nullify + has_many :service_templates, :through => :service_resources validates :name, :presence => true, :uniqueness => true diff --git a/spec/models/transformation_mapping_spec.rb b/spec/models/transformation_mapping_spec.rb index 8fac97962c8..7dccc5b6381 100644 --- a/spec/models/transformation_mapping_spec.rb +++ b/spec/models/transformation_mapping_spec.rb @@ -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 @@ -18,4 +18,13 @@ expect(mapping.destination(FactoryGirl.create(:ems_cluster))).to be_nil end end + + describe '#service_templates' 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_templates).to match([plan]) + end + end end