Last active
December 12, 2020 06:07
-
-
Save dsandstrom/917a9b6fff195704dc90bef9f4574bb7 to your computer and use it in GitHub Desktop.
Revisions
-
dsandstrom revised this gist
Dec 12, 2020 . 2 changed files with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # spec/support/authorizaton.rb module TestHelpers module Authorization def expect_to_be_unauthorized(response) expect(response).to redirect_to(:unauthorized) end def enable_devise_user(controller, user = nil) without_partial_double_verification do @request.env['devise.mapping'] = Devise.mappings[:user] allow(controller).to receive(:resource) { user } if user end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,5 @@ RSpec.configure do |config| .. config.include TestHelpers::Authentication, type: :view config.include TestHelpers::Authorization, type: :controller end -
dsandstrom revised this gist
Dec 12, 2020 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ module TestHelpers module Authentication # set the current_user def enable_can(view, user) without_partial_double_verification do allow(view).to receive(:can?) do |action, record| @@ -20,5 +21,15 @@ def enable_can(view, user) allow(view).to receive(:current_user) { user } end end # setup a guest user for devise def enable_devise_user(view) without_partial_double_verification do allow(view).to receive(:resource) { User.new } allow(view).to receive(:resource_class) { User } allow(view).to receive(:resource_name) { :user } allow(view).to receive(:devise_mapping) { Devise.mappings[:user] } end end end end -
dsandstrom revised this gist
Oct 28, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ # before { enable_can(view, admin) } # ``` module TestHelpers module Authentication def enable_can(view, user) -
dsandstrom revised this gist
Oct 28, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,14 @@ # spec/support/authentication.rb # Enable can? method in view specs for cancancan gem # # Example: # # ``` # let(:admin) { Fabricate(:user_admin) } # before { enable_can(view, admin) } # ``` module TestHelpers module Authentication -
dsandstrom revised this gist
Oct 28, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,5 +6,5 @@ RSpec.configure do |config| .. config.include TestHelpers::Authentication, type: :view end -
dsandstrom created this gist
Oct 28, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # spec/support/authentication.rb # Enable can? method in view specs for cancancan gem module TestHelpers module Authentication def enable_can(view, user) without_partial_double_verification do allow(view).to receive(:can?) do |action, record| ability = Ability.new(user) ability.can?(action, record) end allow(view).to receive(:current_user) { user } end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ # spec/rails_helper.rb .. Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } RSpec.configure do |config| .. config.include TestHelpers::Authentication, type: :controller end