Sha256: 9726c86be143c9999f6af1c4e30cc8c2dc6816053536335f0e2deb9d2322214f

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

RSpec.describe ActsAsScrubbable::Scrub do

  describe '.scrub' do

    # update_columns cannot be run on a new record
    subject{ ScrubbableModel.new }
    before(:each) { subject.save }

    it 'changes the first_name attribute when scrub is run' do
      subject.first_name = "Ted"
      allow(Faker::Name).to receive(:first_name).and_return("John")
      subject.scrub!
      expect(subject.first_name).to eq "John"
    end

    it 'calls street address on faker and updates address1' do
      subject.address1 = "123 abc"
      subject.save
      allow(Faker::Address).to receive(:street_address).and_return("1 Embarcadero")
      subject.scrub!
      expect(subject.address1).to eq "1 Embarcadero"
    end

    it "doesn't update the field if it's blank" do
      subject.address1 = nil
      subject.save
      allow(Faker::Address).to receive(:street_address).and_return("1 Embarcadero")
      subject.scrub!
      expect(subject.address1).to be_nil
    end

    it 'runs scrub callbacks' do
      subject.scrub!
      expect(subject.scrubbing_begun).to be(true)
      expect(subject.scrubbing_finished).to be(true)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_scrubbable-1.0.2 spec/lib/acts_as_scrubbable/scrub_spec.rb
acts_as_scrubbable-1.0.1 spec/lib/acts_as_scrubbable/scrub_spec.rb
acts_as_scrubbable-1.0.0 spec/lib/acts_as_scrubbable/scrub_spec.rb