fix card and section delete

This commit is contained in:
Torsten 2023-01-05 21:34:14 +02:00
parent b28b28da02
commit db82bc5655
8 changed files with 42 additions and 6 deletions

View File

@ -31,7 +31,7 @@ module Merged
end
def destroy
@card.delete_save!
@card.delete_and_reset_index
redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed"
end

View File

@ -27,7 +27,7 @@ module Merged
end
def destroy
@section.delete_save!
@section.delete_and_reset_index
redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.header} removed"
end

View File

@ -38,6 +38,12 @@ module Merged
CardStyle.find_by_template( self.template )
end
def delete_and_reset_index
delete_save!
section.reset_index
save
end
def self.new_card(card_template , section_id , index)
data = { section_id: section_id , index: index}
template = CardStyle.find_by_template( card_template )

View File

@ -76,6 +76,12 @@ module Merged
delete_save!()
end
def delete_and_reset_index
delete
page.reset_index
save
end
def self.new_section(template , page_id , index)
data = { template: template , index: index , page_id: page_id}
style = SectionStyle.find_by_template( template)

View File

@ -9,10 +9,11 @@
background: solid_blue
color: white
align: left
:updated_at: &1 2022-12-09 17:50:02.733622073 +02:00
:updated_at: 2023-01-05 21:33:46.577677395 +02:00
:section_id: 11
:index: 1
:image_id: 35
:updated_by: torsten@villataika.fi
- :header: Large
:text: The old four patient rooms are basically twice the size as the small. They
are large enough to be shared. The size is about 30m2 and the cost 240e. Like
@ -23,7 +24,7 @@
background: solid_blue
color: white
align: left
:updated_at: *1
:updated_at: &1 2022-12-09 17:50:02.733622073 +02:00
:section_id: 11
:index: 2
:image_id: 17
@ -129,6 +130,7 @@
:section_id: 13
:index: 4
:image_id:
:options: {}
- :id: 17
:header: Message
:text: ''

View File

@ -12,6 +12,13 @@ module Merged
assert_raises(ActiveHash::RecordNotFound) {Card.find(id) }
end
def test_delete_index
section = first.section
index = first.index
first.delete_and_reset_index
assert_equal index , section.cards.second.index
end
def test_adds
card = Card.first.section.new_card
card.add_save!

View File

@ -12,7 +12,7 @@ module Merged
assert spacer
end
def test_has_sections
assert_equal SectionStyle.all.length , 9
assert SectionStyle.all.length > 9
end
def test_finds_section_by_template
spacer = SectionStyle.find_by_template("section_spacer")

View File

@ -1,7 +1,7 @@
require "test_helper"
module Merged
class SectionTest < ActiveSupport::TestCase
class SectionWriteTest < ActiveSupport::TestCase
include SectionHelper
include Cleanup
@ -23,6 +23,21 @@ module Merged
assert_raises(ActiveHash::RecordNotFound){Section.find(last_id) }
end
def test_delete_index_section
eleven = Section.find 11
page = eleven.page
eleven.delete
assert_equal eleven.index + 1 , page.sections.second.index
end
def test_delete_index_page
eleven = Section.find 11
page = eleven.page
index = eleven.index
eleven.delete_and_reset_index
assert_equal index , page.sections.second.index
end
def test_destroys
last_id = last.id
last.delete