cirandas.net

ref: master

test/unit/license_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
require_relative "../test_helper"

class LicenseTest < ActiveSupport::TestCase
  should 'validate presence of name and environment' do
    license = License.new
    license.valid?
    assert license.errors[:name].any?
    assert license.errors[:environment].any?

    license.name = 'GPLv3'
    license.environment = Environment.default
    license.valid?
    refute license.errors[:name].any?
    refute license.errors[:environment].any?
  end

  should 'fill in slug before creation' do
    license = License.new(:name => 'GPLv3', :environment => Environment.default)
    assert license.valid?
    assert_equal license.name.to_slug, license.slug
  end

  should 'not overwrite slug if it is already fill' do
    license = License.new(:name => 'GPLv3', :slug => 'some-slug', :environment => Environment.default)
    license.valid?
    assert_equal 'some-slug', license.slug
  end

  should 'allow equal slugs in different environments' do
    e1 = fast_create(Environment)
    e2 = fast_create(Environment)
    License.create!(:name => 'License', :environment => e1)
    license = License.new(:name => 'License', :environment => e2)

    assert license.valid?
  end
end