diff options
| author | Alban Peignier | 2017-12-20 21:30:22 +0100 |
|---|---|---|
| committer | GitHub | 2017-12-20 21:30:22 +0100 |
| commit | 6b4b00a57d2c96ea9f2c663dd9892ccdd4fdbd29 (patch) | |
| tree | a7f69ebd48e32bf14d2da6ba47c84a8e2e57aae2 /spec | |
| parent | 0a1e40a31c27c59018cbdb8821b530ccfd59b878 (diff) | |
| parent | 462c1c257e954c77f1dedfc770d3c78111c1b499 (diff) | |
| download | chouette-core-6b4b00a57d2c96ea9f2c663dd9892ccdd4fdbd29.tar.bz2 | |
Merge pull request #164 from af83/5339-organisation-and-features
Create Organisation#features and FeatureChecker. Refs #5339
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/controllers/concerns/feature_checker_spec.rb | 37 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 22 |
2 files changed, 59 insertions, 0 deletions
diff --git a/spec/controllers/concerns/feature_checker_spec.rb b/spec/controllers/concerns/feature_checker_spec.rb new file mode 100644 index 000000000..1d289bb15 --- /dev/null +++ b/spec/controllers/concerns/feature_checker_spec.rb @@ -0,0 +1,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 diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 359417d88..595b08058 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -62,4 +62,26 @@ describe Organisation, :type => :model do expect{Organisation.portail_sync}.to change{ Organisation.count }.by(4) end end + + describe "#has_feature?" do + + let(:organisation) { Organisation.new } + + it 'return false if Organisation features is nil' do + organisation.features = nil + expect(organisation.has_feature?(:dummy)).to be_falsy + end + + it 'return true if Organisation features contains given feature' do + organisation.features = %w{present} + expect(organisation.has_feature?(:present)).to be_truthy + end + + it "return false if Organisation features doesn't contains given feature" do + organisation.features = %w{other} + expect(organisation.has_feature?(:absent)).to be_falsy + end + + end + end |
