active_record_serialize_spec.rb 835 Bytes
Newer Older
1 2 3
require 'spec_helper'
require 'rubocop'
require 'rubocop/rspec/support'
4
require_relative '../../../rubocop/cop/active_record_serialize'
5

6
describe RuboCop::Cop::ActiveRecordSerialize do
7 8 9 10 11 12
  include CopHelper

  subject(:cop) { described_class.new }

  context 'inside the app/models directory' do
    it 'registers an offense when serialize is used' do
13
      allow(cop).to receive(:in_model?).and_return(true)
14 15 16 17 18 19 20 21 22 23 24 25

      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
26
      allow(cop).to receive(:in_model?).and_return(false)
27 28 29 30 31 32 33

      inspect_source(cop, 'serialize :foo')

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