blob: 1d289bb15ebf01eac6871a0ee54cd8aa993b90e7 (
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
 | require "rails_helper"
RSpec.describe "FeatureChecker", type: :controller do
  login_user
  controller do
    include FeatureChecker
    requires_feature :test, only: :protected
    def protected; render text: "protected"; end
    def not_protected; render text: "not protected"; end
    def current_organisation
      @organisation ||= Organisation.new
    end
  end
  before do
    routes.draw do
      get "protected" => "anonymous#protected"
      get "not_protected" => "anonymous#not_protected"
    end
  end
  it "refuse access when organisation does not have the feature" do
    expect{ get(:protected) }.to raise_error(FeatureChecker::NotAuthorizedError)
  end
  it "accept access on unprotected action" do
    get :not_protected
  end
  it 'accept access when organisation has feature' do
    controller.current_organisation.features << "test"
    get :protected
  end
end
 |