Sha256: 2936c99b8ea3f5139d912b3e0881bf480180b81ee5b357f67f2ec5bed50af72a

Contents?: true

Size: 1.45 KB

Versions: 30

Compression:

Stored size: 1.45 KB

Contents

module MnoEnterprise
  
  # Expect user to be defined
  shared_examples "a navigatable protected user action" do
    context "with guest user" do
      before { sign_out(user) }
      before { subject }
      it { expect(response).to redirect_to(new_user_session_path) }
    end
    
    context 'with signed in and unconfirmed user' do
      before { allow_any_instance_of(MnoEnterprise::User).to receive(:confirmed?).and_return(false) }
      before { sign_in user }
      before { subject }
      it { expect(response).to redirect_to(user_confirmation_lounge_path) }
    end
    
    context 'with signed in and confirmed user' do
      before { sign_in user }
      before { subject }
      it { expect(response.code).to match(/(200|302)/) }
    end
  end
  
  shared_examples "a user protected resource" do
    context "with guest user" do
      before { sign_out(user) }
      before { subject }
      it { expect(response).to redirect_to(new_user_session_path) }
    end
    
    context 'with authorized user' do
      before { allow(ability).to receive(:can?).with(any_args).and_return(true) }
      before { sign_in user }
      before { subject }
      it { expect(response.code).to match(/20\d|302/) }
    end
    
    context 'with unauthorized user' do
      before { allow(ability).to receive(:can?).with(any_args).and_return(false) }
      before { sign_in user }
      before { subject }
      it { expect(response.code).to match(/(302|401)/) }
    end
  end
  
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
mno-enterprise-core-2.0.4 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-3.1.0 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-3.0.3 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-2.0.3 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-3.0.2 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-2.0.2 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-3.0.1 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-2.0.1 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-3.0.0 lib/mno_enterprise/testing_support/user_action_shared.rb
mno-enterprise-core-2.0.0 lib/mno_enterprise/testing_support/user_action_shared.rb