Commit b3fd1440 authored by Andreas Brandl's avatar Andreas Brandl

Support passing an array of columns

parent 94f7724f
......@@ -8,9 +8,9 @@ module IgnorableColumns
#
# Indicate the earliest date and release we can stop ignoring the column with +remove_after+ (a date string) and +remove_with+ (a release)
def ignore_columns(*columns, remove_after:, remove_with:)
raise 'Please indicate when we can stop ignoring columns with remove_after, example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_after && remove_with
raise ArgumentError, 'Please indicate when we can stop ignoring columns with remove_after, example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_after && remove_with
self.ignored_columns += columns
self.ignored_columns += columns.flatten
end
alias_method :ignore_column, :ignore_columns
......
......@@ -3,22 +3,32 @@
require 'spec_helper'
describe IgnorableColumns do
class User < ApplicationRecord
include IgnorableColumns
let(:record_class) do
Class.new(ApplicationRecord) do
include IgnorableColumns
end
end
subject { record_class }
it 'adds columns to ignored_columns' do
expect do
User.ignore_columns(:name, :created_at, remove_after: '2019-12-01', remove_with: '12.6')
end.to change { User.ignored_columns }.from([]).to(%w(name created_at))
subject.ignore_columns(:name, :created_at, remove_after: '2019-12-01', remove_with: '12.6')
end.to change { subject.ignored_columns }.from([]).to(%w(name created_at))
end
it 'adds columns to ignored_columns (array version)' do
expect do
subject.ignore_columns(%i[name created_at], remove_after: '2019-12-01', remove_with: '12.6')
end.to change { subject.ignored_columns }.from([]).to(%w(name created_at))
end
it 'requires remove_after attribute to be set' do
expect { User.ignore_columns(:name, remove_after: nil, remove_with: 12.6) }.to raise_error
expect { subject.ignore_columns(:name, remove_after: nil, remove_with: 12.6) }.to raise_error(ArgumentError, /Please indicate/)
end
it 'requires remove_with attribute to be set' do
expect { User.ignore_columns(:name, remove_after: '2019-12-01', remove_with: nil) }.to raise_error
expect { subject.ignore_columns(:name, remove_after: '2019-12-01', remove_with: nil) }.to raise_error(ArgumentError, /Please indicate/)
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment