tests for changes and simplifying api as we go
This commit is contained in:
@ -1,26 +1,21 @@
|
||||
module Merged
|
||||
class ActiveBase < ActiveYaml::Base
|
||||
|
||||
def save
|
||||
def edit_save!
|
||||
ChangeSet.current.edit(self.class.name , self.change_name)
|
||||
super
|
||||
save!()
|
||||
self.class.save_all
|
||||
end
|
||||
|
||||
def add_save
|
||||
def add_save!
|
||||
ChangeSet.current.add(self.class.name , self.change_name)
|
||||
super.save()
|
||||
save!()
|
||||
self.class.save_all
|
||||
end
|
||||
|
||||
|
||||
def delete
|
||||
def delete_save!
|
||||
ChangeSet.current.delete(self.class.name , self.change_name)
|
||||
self.class.delete(self.id)
|
||||
end
|
||||
|
||||
def destroy
|
||||
delete
|
||||
self.class.save_all
|
||||
end
|
||||
|
||||
|
@ -38,11 +38,6 @@ module Merged
|
||||
CardStyle.find_by_template( self.template )
|
||||
end
|
||||
|
||||
def delete(reindex = true)
|
||||
super()
|
||||
section.reset_index if reindex
|
||||
end
|
||||
|
||||
def self.new_card(card_template , section_id , index)
|
||||
data = { section_id: section_id , index: index}
|
||||
template = CardStyle.find_by_template( card_template )
|
||||
|
@ -8,6 +8,10 @@ module Merged
|
||||
attr_reader :adds , :edits , :deletes
|
||||
|
||||
def initialize
|
||||
zero
|
||||
end
|
||||
|
||||
def zero
|
||||
@adds = []
|
||||
@edits = []
|
||||
@deletes = []
|
||||
|
@ -35,7 +35,7 @@ module Merged
|
||||
PageStyle.find_by_type( type )
|
||||
end
|
||||
|
||||
def new_section(section_template)
|
||||
def new_section(section_template = nil)
|
||||
section_template = "section_spacer" if section_template.blank?
|
||||
section = Section.new_section(section_template, self.id , sections.length + 1)
|
||||
section
|
||||
@ -59,21 +59,9 @@ module Merged
|
||||
sections.each_with_index{|section, index| section.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_sections , has_cards = delete()
|
||||
Page.save_all
|
||||
if has_sections > 0
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
has_sections = sections.length
|
||||
has_cards = 0
|
||||
sections.each {|section| has_cards += section.delete(false) }
|
||||
super
|
||||
[has_sections , has_cards]
|
||||
sections.each {|section| section.delete }
|
||||
delete_save!
|
||||
end
|
||||
|
||||
def save(editor)
|
||||
|
@ -67,18 +67,9 @@ module Merged
|
||||
cards.each_with_index{|card, index| card.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_cards = delete()
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
|
||||
def delete( reindex = true )
|
||||
has_cards = cards.length
|
||||
cards.each {|card| card.delete(false) }
|
||||
super()
|
||||
page.reset_index if reindex
|
||||
has_cards
|
||||
def delete
|
||||
cards.each {|card| card.delete_save! }
|
||||
delete_save!()
|
||||
end
|
||||
|
||||
def self.new_section(template , page_id , index)
|
||||
|
@ -12,10 +12,16 @@ module Merged
|
||||
|
||||
fields :options , :updated_at , :updated_by
|
||||
|
||||
def save( editor )
|
||||
def edit_save( editor )
|
||||
self.updated_at = Time.now
|
||||
self.updated_by = editor
|
||||
super()
|
||||
edit_save!
|
||||
end
|
||||
|
||||
def add_save( editor )
|
||||
self.updated_at = Time.now
|
||||
self.updated_by = editor
|
||||
add_save!
|
||||
end
|
||||
|
||||
def has_option?(option)
|
||||
|
Reference in New Issue
Block a user