aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/controller_spec_helper.rb
blob: ac4bfe06ca1755a2f6f1dce17fc4b033ea53e6ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module ControllerSpecHelper
  def with_permission permission, &block
    context "with permission #{permission}" do
      login_user
      before(:each) do
        @user.permissions << permission
        @user.save!
        sign_in @user
      end
      context('', &block) if block_given?
    end
  end

  def without_permission permission, &block
    context "without permission #{permission}" do
      login_user
      before(:each) do
        @user.permissions.delete permission
        @user.save!
        sign_in @user
      end
      context('', &block) if block_given?
    end
  end

  def with_feature feature, &block
    context "with feature #{feature}" do
      login_user
      before(:each) do
        organisation = @user.organisation
        unless organisation.has_feature?(feature)
          organisation.features << feature
          organisation.save!
        end
        sign_in @user
      end
      context('', &block) if block_given?
    end
  end

end

RSpec.configure do |config|
  config.extend ControllerSpecHelper, type: :controller
end