summaryrefslogtreecommitdiff
path: root/spec/models/concerns/ignorable_column_spec.rb
blob: 6b82825d2cc7c800a4849978eaba1529ca8dfb14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'

describe IgnorableColumn do
  let :base_class do
    Class.new do
      def self.columns
        # This method does not have access to "double"
        [
          Struct.new(:name).new('id'),
          Struct.new(:name).new('title'),
          Struct.new(:name).new('date')
        ]
      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
      model.ignore_column(:title, :date)

      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
      model.ignore_column(:title, :date)

      expect(model.ignored_columns).to eq(Set.new(%w(title date)))
    end
  end
end