Sha256: 7a87372eb7ca9dc14c3f087796f5770a73de9f76296bc244c8ae84ccbccc292d

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

RSpec::Matchers.define :permit_editable_attributes do |*expected_attributes|
  description { "to permit editable attributes:#{expected_attributes}" }
  failure_message { "'#{actual}' does not permit attributes #{expected_attributes - actual.editable_attributes}" }
  match do |actual|
    actual_attributes = expected_attributes - actual.editable_attributes

    actual_attributes.empty?
  end
  match_when_negated do |actual|
    actual_attributes = expected_attributes & actual.editable_attributes

    actual_attributes.empty?
  end
end

RSpec.shared_examples "a standard base model policy" do |factory, check_default_responses: false|
  let(:user) { create(:user) }
  let(:instance) { described_class.new(user, build(factory)) }

  describe "standard_methods" do
    where(:method, :response) do
      [
        [:show?, false],
        [:destroy?, true],
        [:update?, true],
        [:create?, true],
        [:index?, true],
      ]
    end

    with_them do
      it "should " do
        expect(instance).to respond_to(method)
      end
      if check_default_responses
        it "return value" do
          expect(instance.send(method)).to be == response
        end
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
base_editing_bootstrap-0.8.0 spec/support/external_shared/pundit.rb
base_editing_bootstrap-0.7.0 spec/support/external_shared/pundit.rb
base_editing_bootstrap-0.6.0 spec/support/external_shared/pundit.rb