|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | +require "ruby-pg-extras" |
| 5 | + |
| 6 | +describe RubyPgExtras::IgnoreList do |
| 7 | + describe "#ignored?" do |
| 8 | + it "returns false when ignore_list is nil" do |
| 9 | + list = described_class.new(nil) |
| 10 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(false) |
| 11 | + end |
| 12 | + |
| 13 | + it "supports '*' to ignore everything" do |
| 14 | + list = described_class.new(["*"]) |
| 15 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 16 | + expect(list.ignored?(table: "users", column_name: "customer_id")).to eq(true) |
| 17 | + end |
| 18 | + |
| 19 | + it "supports 'table.*' to ignore all columns for a table" do |
| 20 | + list = described_class.new(["posts.*"]) |
| 21 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 22 | + expect(list.ignored?(table: "posts", column_name: "user_id")).to eq(true) |
| 23 | + expect(list.ignored?(table: "users", column_name: "topic_id")).to eq(false) |
| 24 | + end |
| 25 | + |
| 26 | + it "supports 'column' to ignore a column name globally" do |
| 27 | + list = described_class.new(["topic_id"]) |
| 28 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 29 | + expect(list.ignored?(table: "users", column_name: "topic_id")).to eq(true) |
| 30 | + expect(list.ignored?(table: "posts", column_name: "user_id")).to eq(false) |
| 31 | + end |
| 32 | + |
| 33 | + it "supports 'table.column' to ignore a specific table+column" do |
| 34 | + list = described_class.new(["posts.topic_id"]) |
| 35 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 36 | + expect(list.ignored?(table: "users", column_name: "topic_id")).to eq(false) |
| 37 | + expect(list.ignored?(table: "posts", column_name: "user_id")).to eq(false) |
| 38 | + end |
| 39 | + |
| 40 | + it "accepts ignore_list as a comma-separated string" do |
| 41 | + list = described_class.new("posts.topic_id, customer_id") |
| 42 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 43 | + expect(list.ignored?(table: "users", column_name: "customer_id")).to eq(true) |
| 44 | + expect(list.ignored?(table: "users", column_name: "topic_id")).to eq(false) |
| 45 | + end |
| 46 | + |
| 47 | + it "strips whitespace, drops empty entries and de-duplicates" do |
| 48 | + list = described_class.new([" posts.topic_id ", "", "posts.topic_id", " "]) |
| 49 | + expect(list.ignored?(table: "posts", column_name: "topic_id")).to eq(true) |
| 50 | + expect(list.ignored?(table: "users", column_name: "topic_id")).to eq(false) |
| 51 | + end |
| 52 | + |
| 53 | + it "raises ArgumentError for unsupported ignore_list types" do |
| 54 | + expect { described_class.new(123) }.to raise_error(ArgumentError) |
| 55 | + expect { described_class.new({}) }.to raise_error(ArgumentError) |
| 56 | + end |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | + |
0 commit comments