2017-04-12 12:15:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe IgnorableColumn do
|
|
|
|
let :base_class do
|
|
|
|
Class.new do
|
|
|
|
def self.columns
|
|
|
|
# This method does not have access to "double"
|
2017-11-06 10:20:20 -05:00
|
|
|
[
|
|
|
|
Struct.new(:name).new('id'),
|
|
|
|
Struct.new(:name).new('title'),
|
|
|
|
Struct.new(:name).new('date')
|
|
|
|
]
|
2017-04-12 12:15:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let :model do
|
|
|
|
Class.new(base_class) do
|
|
|
|
include IgnorableColumn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.columns' do
|
|
|
|
it 'returns the columns, excluding the ignored ones' do
|
2017-11-06 10:20:20 -05:00
|
|
|
model.ignore_column(:title, :date)
|
2017-04-12 12:15:19 -04:00
|
|
|
|
|
|
|
expect(model.columns.map(&:name)).to eq(%w(id))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.ignored_columns' do
|
|
|
|
it 'returns a Set' do
|
|
|
|
expect(model.ignored_columns).to be_an_instance_of(Set)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the names of the ignored columns' do
|
2017-11-06 10:20:20 -05:00
|
|
|
model.ignore_column(:title, :date)
|
2017-04-12 12:15:19 -04:00
|
|
|
|
2017-11-06 10:20:20 -05:00
|
|
|
expect(model.ignored_columns).to eq(Set.new(%w(title date)))
|
2017-04-12 12:15:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|