Sha256: 274523937d94ec5d91352057af7685f6937a69e0fd1e6d752bfa1a8d7a23bd84

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents

module MnoEnterprise::TestingSupport::JpiV1TestHelper

  # Expect 'user' to be assigned
  shared_examples "jpi v1 protected action" do
    context "with guest user" do
      it "prevents access" do
        sign_out user
        expect(subject).to_not be_successful
        expect(subject.code).to eq('401')
      end
    end

    context 'with signed in user' do
      it "authorizes access" do
        sign_in user
        expect(subject).to be_successful
      end
    end
  end

  # Expect 'user' to be assigned
  # Expect 'ability' to be assigned
  shared_examples "jpi v1 authorizable action" do
    context "with guest user" do
      it "prevents access" do
        sign_out user
        expect(subject).to_not be_successful
        expect(subject.code).to eq('401')
      end
    end

    context 'with unauthorized signed in user' do
      it "prevents access" do
        sign_in user
        allow(ability).to receive(:can?).with(any_args).and_return(false)
        expect(subject).to_not be_successful
      end
    end

    context 'with authorized signed in user' do
      it "authorizes access" do
        sign_in user
        allow(ability).to receive(:can?).with(any_args).and_return(true)
        expect(subject).to be_successful
      end
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mno-enterprise-core-3.1.4 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.7 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.9 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.1.3 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.6 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.8 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.1.2 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.5 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.7 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.6 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.5 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.1.1 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.4 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.4 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.1.0 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.3 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.3 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.2 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-2.0.2 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb
mno-enterprise-core-3.0.1 lib/mno_enterprise/testing_support/jpi_v1_test_helper.rb