summaryrefslogtreecommitdiff
path: root/spec/rubocop/cop/activerecord_serialize_spec.rb
blob: a303b16d264490ab742439d0f9d5356a1df4f57b (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
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../rubocop/cop/activerecord_serialize'

describe RuboCop::Cop::ActiverecordSerialize do
  include CopHelper

  subject(:cop) { described_class.new }

  context 'inside the app/models directory' do
    it 'registers an offense when serialize is used' do
      allow(cop).to receive(:in_models?).and_return(true)

      inspect_source(cop, 'serialize :foo')

      aggregate_failures do
        expect(cop.offenses.size).to eq(1)
        expect(cop.offenses.map(&:line)).to eq([1])
      end
    end
  end

  context 'outside the app/models directory' do
    it 'does nothing' do
      allow(cop).to receive(:in_models?).and_return(false)

      inspect_source(cop, 'serialize :foo')

      expect(cop.offenses).to be_empty
    end
  end
end