aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-08 18:00:01 +0200
committerTeddy Wing2017-06-08 18:00:01 +0200
commit5d9ed9d90ada31f9ee895111613d970473981096 (patch)
tree29175b939153bdc64cc9416ecc4bccf0899db355
parenta2fc8b0253819fa5585a04cf9c8232a689184b29 (diff)
downloadchouette-core-5d9ed9d90ada31f9ee895111613d970473981096.tar.bz2
TableBuilder spec: Get past Pundit errors
Add a bunch of mocks etc. to get past errors related to using Pundit inside the helper. These errors included: * No method `policy` (included `Pundit` in `TableBuilderHelper`) * No method `authenticate` (mocked a `current_user` method on the helper) * Need to return a `user_context` from `current_user` to make policy's `#new` happy (no method `user` on `User`) At first tried to use the `create_user_context` method from spec/support/pundit, but it wasn't in scope so I just did it directly to get it working. Don't like all the mocks at all. A lot of pre-work to do just to get the helper to execute without exceptions. Refs #3479
-rw-r--r--spec/helpers/table_builder_helper_spec.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index f3db493ce..b1c2b9a3f 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -1,11 +1,25 @@
require 'spec_helper'
+module TableBuilderHelper
+ include Pundit
+end
+
describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- referentials = [
- build_stubbed(:referential)
- ]
+ referential = build_stubbed(:referential)
+
+ # user_context = create_user_context(
+ # user: build_stubbed(:user),
+ # referential: referential
+ # )
+ user_context = OpenStruct.new(
+ user: build_stubbed(:user),
+ context: { referential: referential }
+ )
+ allow(helper).to receive(:current_user).and_return(user_context)
+
+ referentials = [referential]
allow(referentials).to receive(:model).and_return(Referential)