Sha256: e3f45b2fff2e85624437c35c2be33d3b140fd4a2d1b5f0a1377475e2334d5dcb

Contents?: true

Size: 947 Bytes

Versions: 6

Compression:

Stored size: 947 Bytes

Contents

RSpec.shared_examples_for "deletable" do |attrs|
  let(:model) { described_class }

  describe "works ok!" do
    let(:obj) { FactoryBot.create(model.to_s.underscore.to_sym) }
    subject do
      obj
    end

    it "when model deleted" do
      model = subject
      model.deleted_at = Time.current
      model.save
      expect(model.deleted?).to be true
    end

    it "when model deleted do update" do
      model = subject
      model.deleted_at = Time.current
      model.save
      model.created_at = Time.current
      expect{model.save}.to raise_error(ActiveRecord::RecordInvalid)
    end

    it "when model not deleted" do
      model = subject
      model.deleted_at = nil
      model.save
      expect(subject.deleted?).to be false
    end

    it "when model not deleted save" do
      model = subject
      model.deleted_at = nil
      model.created_at = Time.current
      expect{model.save}.not_to raise_error
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
commons_yellowme-0.16.0 spec/support/shared-examples/deletable.rb
commons_yellowme-0.15.0 spec/support/shared-examples/deletable.rb
commons_yellowme-0.12.0 spec/support/shared-examples/deletable.rb
commons_yellowme-0.11.3 spec/support/shared-examples/deletable.rb
commons_yellowme-0.11.2 spec/support/shared-examples/deletable.rb
commons_yellowme-0.11.1 spec/support/shared-examples/deletable.rb