blob: ab1cc5dfdaccc4812dfd53ff50411825d5ea1f04 (
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
50
51
52
53
54
55
56
|
require 'test_helper'
class AssetTest < ActiveSupport::TestCase
test "related assets get destroyed when assets get destroyed" do
Asset.delete_all
RelatedAsset.delete_all
assert asset = Asset.create
assert node = Node.root.children.create( :slug => "asset" )
assert_equal [], node.draft.assets
draft = node.draft
draft.assets << asset
assert_equal 1, draft.assets.length
asset.destroy
draft.reload
assert_equal 0, draft.assets.length
assert_equal 0, RelatedAsset.count
end
test "image? is true for supported image content types" do
assert Asset.new(:upload_content_type => "image/png").image?
assert Asset.new(:upload_content_type => "image/jpeg").image?
end
test "image? is false for non-image content types" do
assert_not Asset.new(:upload_content_type => "application/pdf").image?
assert_not Asset.new(:upload_content_type => nil).image?
end
test "license_key must be a known dictionary key" do
asset = Asset.new(:license_key => "not_a_real_license")
I18n.with_locale(:en) do
assert_not asset.valid?
assert_includes asset.errors[:license_key], "is not included in the list"
end
end
test "license_key may be blank" do
assert Asset.new(:license_key => nil).valid?
end
test "pdf? is true only for application/pdf" do
assert Asset.new(:upload_content_type => "application/pdf").pdf?
assert_not Asset.new(:upload_content_type => "image/png").pdf?
end
test "show_credit? is false for a PDF even with every credit field present" do
asset = Asset.new(:name => "demo", :upload_content_type => "application/pdf",
:creator => "Jane Doe", :source_url => "https://example.org", :license_key => "cc_by_4")
assert asset.has_credit?
assert_not asset.show_credit?
end
end
|