diff options
| author | Teddy Wing | 2017-06-14 18:24:17 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-14 18:24:17 +0200 |
| commit | d2b1ab114348ee0895703cd650734f585b11e781 (patch) | |
| tree | dc90e30d2b828d8395f861b889e6e84b0026a661 | |
| parent | 07c50e21b45b8fcf219410cbfb71f1c1e67e81b6 (diff) | |
| download | chouette-core-d2b1ab114348ee0895703cd650734f585b11e781.tar.bz2 | |
TableBuilderHelper::CustomLinks: Fix policy check for unhandled actions
In `#actions_after_policy_check`, we weren't correctly including actions
that weren't handled by the prior policy checks. Thus actions that
weren't [:delete, :edit, :archive, :unarchive] wouldn't get included in
the resulting list of actions.
Fix my logic error.
Refs #3479
| -rw-r--r-- | app/helpers/table_builder_helper/custom_links.rb | 4 | ||||
| -rw-r--r-- | spec/helpers/table_builder_helper/custom_links_spec.rb | 27 |
2 files changed, 28 insertions, 3 deletions
diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb index 9703940d6..f47ef1a11 100644 --- a/app/helpers/table_builder_helper/custom_links.rb +++ b/app/helpers/table_builder_helper/custom_links.rb @@ -52,9 +52,7 @@ module TableBuilderHelper !Pundit.policy(@user_context, @obj).present?) || (action == :archive && !@obj.archived?) || (action == :unarchive && @obj.archived?) || - - # TODO: Something wrong here for actions not handled - ([:delete, :edit, :archive, :unarchive].include?(action)) + (![:delete, :edit, :archive, :unarchive].include?(action)) end end end diff --git a/spec/helpers/table_builder_helper/custom_links_spec.rb b/spec/helpers/table_builder_helper/custom_links_spec.rb new file mode 100644 index 000000000..b64e97527 --- /dev/null +++ b/spec/helpers/table_builder_helper/custom_links_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe TableBuilderHelper::CustomLinks do + describe "#actions_after_policy_check" do + it "includes :show" do + referential = build_stubbed(:referential) + user_context = UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'boiv:read-offer' + ] + ), + referential: referential + ) + + expect( + TableBuilderHelper::CustomLinks.new( + referential, + user_context, + [:show] + ).actions_after_policy_check + ).to eq([:show]) + end + end +end |
