Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the message for undefined scrub #36

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/acts_as_scrubbable/scrub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def scrubbed_values
if ActsAsScrubbable.scrub_map.keys.include?(value)
_updates[_field] = ActsAsScrubbable.scrub_map[value].call
else
puts "Undefined scrub: #{value} for #{self.class}#{_field}"
puts "Undefined scrub: #{value} for #{self.class}.#{_field}"
end
end

Expand Down
25 changes: 25 additions & 0 deletions spec/lib/acts_as_scrubbable/scrub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,30 @@
expect(subject.scrubbing_begun).to be(true)
expect(subject.scrubbing_finished).to be(true)
end

it 'output no information when all scrubbers found' do
expect(STDOUT).to_not receive(:puts)

_updates = subject.scrubbed_values
end

context "scrubbable" do
subject { MissingScrubbableModel.new }

it 'outputs warning message' do
subject.first_name = "Johnny"
subject.last_name = "Frank"

allow(Faker::Name).to receive(:first_name).and_return("Larry")
allow(Faker::Name).to receive(:last_name).and_return("Baker")

expect(STDOUT).to receive(:puts).with('Undefined scrub: fake_first_name for MissingScrubbableModel.first_name')
expect(Faker::Name).to_not receive(:first_name)

_updates = subject.scrubbed_values
expect(_updates[:last_name]).to eq('Baker')
expect(_updates[:first_name]).to be_nil
end
end
end
end
3 changes: 2 additions & 1 deletion spec/lib/acts_as_scrubbable/task_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
it "scrubs all scrubbable classes", :aggregate_failures do
runner.extract_ar_classes
runner.scrub(num_of_batches: 1)
expect(processor).to have_received(:process).with(1).exactly(3).times
expect(processor).to have_received(:process).with(1).exactly(4).times
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(ScrubbableModel)
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AnotherScrubbableModel)
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AThirdScrubbableModel)
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(MissingScrubbableModel)
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(NonScrubbableModel)
end

Expand Down
6 changes: 6 additions & 0 deletions spec/support/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ class AnotherScrubbableModel < ActiveRecord::Base
class AThirdScrubbableModel < ActiveRecord::Base
acts_as_scrubbable :active => :boolean
end

class MissingScrubbableModel < ActiveRecord::Base
attr_accessor :first_name, :last_name

acts_as_scrubbable :last_name, :first_name => :fake_first_name
end