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 end
def destroy def destroy
@card.delete_save! @card.delete_and_reset_index
redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed" redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed"
end end

View File

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

View File

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

View File

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

View File

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

View File

@ -12,6 +12,13 @@ module Merged
assert_raises(ActiveHash::RecordNotFound) {Card.find(id) } assert_raises(ActiveHash::RecordNotFound) {Card.find(id) }
end 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 def test_adds
card = Card.first.section.new_card card = Card.first.section.new_card
card.add_save! card.add_save!

View File

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

View File

@ -1,7 +1,7 @@
require "test_helper" require "test_helper"
module Merged module Merged
class SectionTest < ActiveSupport::TestCase class SectionWriteTest < ActiveSupport::TestCase
include SectionHelper include SectionHelper
include Cleanup include Cleanup
@ -23,6 +23,21 @@ module Merged
assert_raises(ActiveHash::RecordNotFound){Section.find(last_id) } assert_raises(ActiveHash::RecordNotFound){Section.find(last_id) }
end 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 def test_destroys
last_id = last.id last_id = last.id
last.delete last.delete