Sha256: 5b9e1f3bf035bc30c8517923958acaef047a1919ece254aa45b22ccd4896b355

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require "spec_helper"
require "tmpdir"

require "rails/generators"
require "generators/pundit/install/install_generator"
require "generators/pundit/policy/policy_generator"

RSpec.describe "generators" do
  before(:all) do
    @tmpdir = Dir.mktmpdir

    Dir.chdir(@tmpdir) do
      Pundit::Generators::InstallGenerator.new([], { quiet: true }).invoke_all
      Pundit::Generators::PolicyGenerator.new(%w[Widget], { quiet: true }).invoke_all

      require "./app/policies/application_policy"
      require "./app/policies/widget_policy"
    end
  end

  after(:all) do
    FileUtils.remove_entry(@tmpdir)
  end

  describe "WidgetPolicy", type: :policy do
    permissions :index?, :show?, :create?, :new?, :update?, :edit?, :destroy? do
      it "has safe defaults" do
        expect(WidgetPolicy).not_to permit(double("User"), double("Widget"))
      end
    end

    describe "WidgetPolicy::Scope" do
      describe "#resolve" do
        it "raises a descriptive error" do
          scope = WidgetPolicy::Scope.new(double("User"), double("User.all"))
          expect { scope.resolve }.to raise_error(NotImplementedError, /WidgetPolicy::Scope/)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/pundit-2.2.0/spec/generators_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/pundit-2.2.0/spec/generators_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/pundit-2.2.0/spec/generators_spec.rb
pundit-2.3.1 spec/generators_spec.rb
pundit-2.3.0 spec/generators_spec.rb
pundit-2.2.0 spec/generators_spec.rb