Project

General

Profile

« Previous | Next » 

Revision 5655a7ac

Added by Ondřej Pražák almost 6 years ago

Fixes #23705 - Do not associate ptable snippets

View differences:

app/models/ptable.rb
has_and_belongs_to_many :operatingsystems, :join_table => :operatingsystems_ptables, :association_foreign_key => :operatingsystem_id, :foreign_key => :ptable_id
validates :layout, :presence => true
validates :name, :uniqueness => true
validates :os_family, :absence => true, :if => Proc.new { |ptable| ptable.snippet }
validate_inclusion_in_families :os_family
# these can't be shared in parent class, scoped search can't handle STI properly
db/migrate/20180625082051_remove_associations_from_ptable_snippets.rb
class RemoveAssociationsFromPtableSnippets < ActiveRecord::Migration[5.1]
def up
Ptable.unscoped.where(:snippet => true).where.not(:os_family => [nil, ""]).map do |ptable|
ptable.os_family = nil
ptable.save!
end
end
end
test/models/ptable_test.rb
end
end
end
test 'should be invalid when snippet has os_family' do
ptable = Ptable.new(:name => 'invalid snippet', :snippet => true, :os_family => 'Debian', :template => 'foo')
ptable.save
refute ptable.valid?
assert_equal ['must be blank'], ptable.errors.messages[:os_family]
end
end
webpack/assets/javascripts/foreman_editor.js
$('#kind_selector').toggle(!checked);
$('#snippet_message').toggle(checked);
$('#association').toggle(!checked);
if (checked) {
$('#ptable_os_family').val('');
$('#ptable_os_family').trigger('change');
}
}
function createEditor() {

Also available in: Unified diff