Add SDG phases cards management

These cards will be displayed in the SDG homepage.

Note there seems to be a strange behavior in cancancan. If we define
these rules:

can :manage, Widget::Card, page_type: "SDG::Phase"
can :manage, Widget::Card

The expected behavior is the first rule will always be ignored because
the second one overwrites it. However, when creating a new card with
`load_and_authorize_resource` will automatically add `page_type:
"SDG::Phase"`.

Similarly, if we do something like:

can :manage, Widget::Card, id: 3
can :manage, Widget::Card

Then the new card will have `3` as an ID.

Maybe upgrading cancancan solves the issue; we haven't tried it. For now
we're defining a different rule when creating widget cards.
This commit is contained in:
Javi Martín
2021-01-09 18:23:19 +01:00
parent 739236d585
commit 7aee4f6241
17 changed files with 127 additions and 0 deletions

View File

@@ -195,6 +195,15 @@ describe "Polymorphic routes" do
expect(sdg_management_polymorphic_path(target)).to eq sdg_management_local_target_path(target)
end
it "routes SDG phases widget cards" do
phase = SDG::Phase.sample
card = create(:widget_card, cardable: phase)
expect(sdg_management_polymorphic_path(card)).to eq(
sdg_management_sdg_phase_widget_card_path(phase, card)
)
end
end
end