2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Plugin::Metadata do
|
2022-07-28 00:14:14 +08:00
|
|
|
describe "parse" do
|
2013-08-23 14:21:52 +08:00
|
|
|
it "correctly parses plugin info" do
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# name: plugin-name
|
|
|
|
# about: about: my plugin
|
|
|
|
# version: 0.1
|
|
|
|
# authors: Frank Zappa
|
2021-01-29 00:17:00 +08:00
|
|
|
# contact emails: frankz@example.com
|
2015-02-07 07:08:57 +08:00
|
|
|
# url: http://discourse.org
|
2015-04-28 01:06:53 +08:00
|
|
|
# required version: 1.3.0beta6+48
|
2023-10-10 08:16:13 +08:00
|
|
|
# meta_topic_id: 1234
|
2023-11-30 08:53:17 +08:00
|
|
|
# label: experimental
|
2013-08-23 14:21:52 +08:00
|
|
|
|
|
|
|
some_ruby
|
|
|
|
TEXT
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(metadata.name).to eq("plugin-name")
|
|
|
|
expect(metadata.about).to eq("about: my plugin")
|
|
|
|
expect(metadata.version).to eq("0.1")
|
|
|
|
expect(metadata.authors).to eq("Frank Zappa")
|
2021-01-29 00:17:00 +08:00
|
|
|
expect(metadata.contact_emails).to eq("frankz@example.com")
|
2015-02-07 07:08:57 +08:00
|
|
|
expect(metadata.url).to eq("http://discourse.org")
|
2015-04-28 01:06:53 +08:00
|
|
|
expect(metadata.required_version).to eq("1.3.0beta6+48")
|
2023-11-30 08:53:17 +08:00
|
|
|
expect(metadata.meta_topic_id).to eq(1234)
|
|
|
|
expect(metadata.label).to eq("experimental")
|
2013-08-23 14:21:52 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-15 08:42:55 +08:00
|
|
|
def official(name)
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# name: #{name}
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
expect(metadata.official?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unofficial(name)
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# name: #{name}
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
expect(metadata.official?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correctly detects official vs unofficial plugins" do
|
|
|
|
official("discourse-adplugin")
|
|
|
|
official("discourse-akismet")
|
|
|
|
official("discourse-cakeday")
|
|
|
|
official("discourse-data-explorer")
|
|
|
|
unofficial("babble")
|
|
|
|
end
|
2023-11-30 08:53:17 +08:00
|
|
|
|
|
|
|
it "does not support anything but integer for meta_topic_id" do
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# meta_topic_id: 1234
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
expect(metadata.meta_topic_id).to eq(1234)
|
|
|
|
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# meta_topic_id: t/1234 blah
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
expect(metadata.meta_topic_id).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "truncates long field lengths" do
|
|
|
|
metadata = Plugin::Metadata.parse <<TEXT
|
|
|
|
# name: #{"a" * 100}
|
|
|
|
# about: #{"a" * 400}
|
|
|
|
# authors: #{"a" * 300}
|
|
|
|
# contact_emails: #{"a" * 300}
|
|
|
|
# url: #{"a" * 600}
|
|
|
|
# label: #{"a" * 100}
|
|
|
|
# required_version: #{"a" * 1500}
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
expect(metadata.name.length).to eq(Plugin::Metadata::MAX_FIELD_LENGTHS[:name])
|
|
|
|
expect(metadata.about.length).to eq(Plugin::Metadata::MAX_FIELD_LENGTHS[:about])
|
|
|
|
expect(metadata.authors.length).to eq(Plugin::Metadata::MAX_FIELD_LENGTHS[:authors])
|
|
|
|
expect(metadata.contact_emails.length).to eq(
|
|
|
|
Plugin::Metadata::MAX_FIELD_LENGTHS[:contact_emails],
|
|
|
|
)
|
|
|
|
expect(metadata.url.length).to eq(Plugin::Metadata::MAX_FIELD_LENGTHS[:url])
|
|
|
|
expect(metadata.label.length).to eq(Plugin::Metadata::MAX_FIELD_LENGTHS[:label])
|
|
|
|
expect(metadata.required_version.length).to eq(1000)
|
|
|
|
end
|
2013-08-23 14:21:52 +08:00
|
|
|
end
|