cirandas.net

ref: master

plugins/spaminator/test/unit/spaminator_plugin/report_test.rb


 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
require 'test_helper'

class SpaminatorPlugin::ReportTest < ActiveSupport::TestCase

  should 'must belong to an environment' do
    report = SpaminatorPlugin::Report.new
    report.valid?
    assert report.errors.include?(:environment)

    report.environment = Environment.default
    report.valid?
    refute report.errors.include?(:environment)
  end

  should 'have scope of all reports from an environment' do
    environment = Environment.default
    r1 = SpaminatorPlugin::Report.create(:environment => environment)
    r2 = SpaminatorPlugin::Report.create(:environment => environment)
    r3 = SpaminatorPlugin::Report.create(:environment => environment)
    r4 = SpaminatorPlugin::Report.create(:environment => fast_create(Environment))

    reports = SpaminatorPlugin::Report.from_environment(environment)

    assert_includes reports, r1
    assert_includes reports, r2
    assert_includes reports, r3
    assert_not_includes reports, r4
  end

  should 'initialize failed hash' do
    report = SpaminatorPlugin::Report.new

    assert report.failed.kind_of?(Hash)
    assert report.failed.has_key?(:people)
    assert report.failed.has_key?(:comments)
    assert_equal [], report.failed[:people]
    assert_equal [], report.failed[:comments]
  end

end