According to the README [1]: > To mask previously collected IPs, use: > Ahoy::Visit.find_each do |visit| > visit.update_column :ip, Ahoy.mask_ip(visit.ip) > end We're adapting the code with our version, since we use the `Visit` model instead of the `Ahoy::Visit` model. [1] https://github.com/ankane/ahoy/blob/v5.0.2/README.md#ip-masking
28 lines
685 B
Ruby
28 lines
685 B
Ruby
require "rails_helper"
|
|
|
|
describe "rake db:mask_ips" do
|
|
before { Rake::Task["db:mask_ips"].reenable }
|
|
|
|
it "mask IPs on all tenants" do
|
|
create(:visit, ip: "1.1.1.1")
|
|
create(:visit, ip: "1.1.1.2")
|
|
create(:visit, ip: "1.1.2.2")
|
|
|
|
create(:tenant, schema: "myhometown")
|
|
|
|
Tenant.switch("myhometown") do
|
|
create(:visit, ip: "1.1.1.1")
|
|
create(:visit, ip: "1.1.1.2")
|
|
create(:visit, ip: "1.1.3.3")
|
|
end
|
|
|
|
Rake.application.invoke_task("db:mask_ips")
|
|
|
|
expect(Visit.pluck(:ip)).to match_array %w[1.1.1.0 1.1.1.0 1.1.2.0]
|
|
|
|
Tenant.switch("myhometown") do
|
|
expect(Visit.pluck(:ip)).to match_array %w[1.1.1.0 1.1.1.0 1.1.3.0]
|
|
end
|
|
end
|
|
end
|