summaryrefslogtreecommitdiff
path: root/test/models/subnet_ban_test.rb
blob: 2fc49d1b0c33cb66d4f6d949e0ca38ff18ab60c1 (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
45
46
47
48
49
# frozen_string_literal: true

# == Schema Information
#
# Table name: subnet_bans
#
#  id               :integer          not null, primary key
#  enabled          :boolean          default(TRUE), not null
#  note             :string
#  reason           :string           not null
#  specification    :inet
#  valid_until      :datetime         not null
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#  banning_user_id  :integer          not null
#  generated_ban_id :string           not null
#
# Indexes
#
#  index_subnet_bans_on_banning_user_id  (banning_user_id)
#  index_subnet_bans_on_created_at       (created_at)
#
# Foreign Keys
#
#  fk_rails_...  (banning_user_id => users.id) ON DELETE => restrict ON UPDATE => cascade
#
require 'test_helper'

class SubnetBanTest < ActiveSupport::TestCase
  setup do
    @ban = build(:subnet_ban)
  end

  test 'should be valid' do
    assert @ban.valid?
  end

  test '.banned? should return the active ban when banned' do
    @ban.save
    assert_equal @ban, SubnetBan.banned?(@ban.specification)
  end

  test '.banned? should return false when not banned' do
    assert_not SubnetBan.banned?(@ban.specification) # did not save

    @ban = create(:expired_subnet_ban)
    assert_not SubnetBan.banned?(@ban.specification)
  end
end