Skip to content

Commit

Permalink
Add association of service_templates to TransformationMapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Apr 10, 2018
1 parent 959fcd6 commit 15758bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/models/transformation_mapping.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class TransformationMapping < ApplicationRecord
has_many :transformation_mapping_items, :dependent => :destroy
has_many :service_resources, :as => :resource
has_many :service_templates, :through => :service_resources

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

Expand Down
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_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

0 comments on commit 15758bc

Please sign in to comment.