diff --git a/db/migrate/20180810144738_update_default_internal_attribute.rb b/db/migrate/20180810144738_update_default_internal_attribute.rb new file mode 100644 index 000000000..1c2add0c9 --- /dev/null +++ b/db/migrate/20180810144738_update_default_internal_attribute.rb @@ -0,0 +1,11 @@ +class UpdateDefaultInternalAttribute < ActiveRecord::Migration[5.0] + class ServiceTemplate < ActiveRecord::Base + self.inheritance_column = :_type_disabled + end + + def up + say_with_time("Set ServiceTemplate internal") do + ServiceTemplate.where.not(:type => "ServiceTemplateTransformationPlan").update_all(:internal => false) + end + end +end diff --git a/spec/migrations/20180810144738_update_default_internal_attribute_spec.rb b/spec/migrations/20180810144738_update_default_internal_attribute_spec.rb new file mode 100644 index 000000000..82cf8600e --- /dev/null +++ b/spec/migrations/20180810144738_update_default_internal_attribute_spec.rb @@ -0,0 +1,23 @@ +require_migration + +describe UpdateDefaultInternalAttribute do + let(:service_template_stub) { migration_stub(:ServiceTemplate) } + + migration_context :up do + it "sets internal to false when type is ServiceTemplateTransformationPlan" do + st = service_template_stub.create!(:type => 'ServiceTemplateTransformationPlan', :internal => true) + + migrate + + expect(st.reload.internal).to be_truthy + end + + it "sets internal to false when type is not ServiceTemplateTransformationPlan" do + st = service_template_stub.create!(:type => 'OtherServiceTemplateTransformationPlan') + + migrate + + expect(st.reload.internal).to be(false) + end + end +end