Created
June 28, 2019 11:55
-
-
Save sideshowbandana/e01a786b0b4969a28a21a4a1c6165fd2 to your computer and use it in GitHub Desktop.
This file contains 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 characters
# spec/helpers/rails_helper.rb | |
RSpec.shared_context "Authorization helpers" do | |
let(:current_ability){ | |
Abilities::Base.new(user).tap do |ability| | |
ability.can(:manage, :all) | |
end | |
} | |
let(:user){ | |
build(:user) | |
} | |
end | |
RSpec.shared_context "graphiti contexts", type: :resource do |parameter| | |
let(:graphiti_context){ | |
OpenStruct.new.tap do |ctx| | |
ctx.current_user = user | |
ctx.current_ability = current_ability | |
class << ctx | |
delegate :authorize!, to: :current_ability | |
end | |
end | |
} | |
end | |
module SharedContexts | |
def self.included(klass) | |
::RSpec.configure do |rspec| | |
rspec.include_context "Authorization helpers" | |
rspec.include_context "graphiti contexts", type: :resource | |
end | |
end | |
end | |
RSpec.configure do |config| | |
# ... | |
config.include SharedContexts | |
# ... | |
config.before :each do | |
# ... | |
allow(Abilities::Factory).to receive(:ability_for).and_return(current_ability) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment