Files
grecia/spec/models/abilities/sdg/manager_spec.rb
Javi Martín 7aee4f6241 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.
2021-01-14 17:40:02 +01:00

22 lines
774 B
Ruby

require "rails_helper"
require "cancan/matchers"
describe "Abilities::SDG::Manager" do
subject(:ability) { Ability.new(user) }
let(:user) { sdg_manager.user }
let(:sdg_manager) { create(:sdg_manager) }
it { should be_able_to(:read, SDG::Target) }
it { should be_able_to(:manage, SDG::LocalTarget) }
it { should_not be_able_to(:read, SDG::Manager) }
it { should_not be_able_to(:create, SDG::Manager) }
it { should_not be_able_to(:delete, SDG::Manager) }
it { should_not be_able_to(:update, create(:widget_card)) }
it { should be_able_to(:update, create(:widget_card, cardable: SDG::Phase.sample)) }
it { should_not be_able_to(:create, build(:widget_card)) }
it { should be_able_to(:create, build(:widget_card, cardable: SDG::Phase.sample)) }
end