Fix managing widget cards for homepage
The condition `params[:page_id] != 0` didn't work properly when editing the homepage because in that case the parameter was `nil`, and the line `SiteCustomization::Page.find(@card.site_customization_page_id)` raised an exception because it couldn't find a page with a `nil` ID. Fixing the issue while maintaining the check against `0` lead to complex code, and so allowing `nil` in the database and assuming cards with no `site_customization_page_id` belonged in the homepage seemed to be the easiest solution.
This commit is contained in:
@@ -26,11 +26,14 @@ describe Widget::Card do
|
||||
|
||||
it "returns cards for the homepage body" do
|
||||
header = create(:widget_card, header: true)
|
||||
card1 = create(:widget_card, header: false, title: "Card 1", site_customization_page_id: 0)
|
||||
card2 = create(:widget_card, header: false, title: "Card 2", site_customization_page_id: 0)
|
||||
card3 = create(:widget_card, header: false, title: "Card 3", site_customization_page_id: 0)
|
||||
card1 = create(:widget_card, header: false)
|
||||
card2 = create(:widget_card, header: false)
|
||||
page_card = create(:widget_card, header: false, page: create(:site_customization_page))
|
||||
|
||||
expect(Widget::Card.body).to eq([card1, card2, card3])
|
||||
expect(Widget::Card.body).to include(card1)
|
||||
expect(Widget::Card.body).to include(card2)
|
||||
expect(Widget::Card.body).not_to include(header)
|
||||
expect(Widget::Card.body).not_to include(page_card)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user