Merge pull request #3585 from consul/images_and_documents_settings
Images and documents settings
This commit is contained in:
@@ -17,6 +17,16 @@ describe Setting do
|
||||
expect(described_class.where(key: "official_level_1_name", value: "Stormtrooper")).to exist
|
||||
end
|
||||
|
||||
describe "#prefix" do
|
||||
it "returns the prefix of its key" do
|
||||
expect(Setting.create(key: "prefix.key_name").prefix).to eq "prefix"
|
||||
end
|
||||
|
||||
it "returns the whole key for a non prefixed key" do
|
||||
expect(Setting.create(key: "key_name").prefix).to eq "key_name"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#type" do
|
||||
it "returns the key prefix for 'process' settings" do
|
||||
process_setting = Setting.create(key: "process.whatever")
|
||||
@@ -70,6 +80,26 @@ describe Setting do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#content_type?" do
|
||||
it "returns true if the last part of the key is content_types" do
|
||||
expect(Setting.create(key: "key_name.content_types").content_type?).to be true
|
||||
end
|
||||
|
||||
it "returns false if the last part of the key is not content_types" do
|
||||
expect(Setting.create(key: "key_name.whatever").content_type?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#content_type_group" do
|
||||
it "returns the group for content_types settings" do
|
||||
images = Setting.create(key: "update.images.content_types")
|
||||
documents = Setting.create(key: "update.documents.content_types")
|
||||
|
||||
expect(images.content_type_group).to eq "images"
|
||||
expect(documents.content_type_group).to eq "documents"
|
||||
end
|
||||
end
|
||||
|
||||
describe ".rename_key" do
|
||||
it "renames the setting keeping the original value and deletes the old setting" do
|
||||
Setting["old_key"] = "old_value"
|
||||
@@ -118,6 +148,24 @@ describe Setting do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".accepted_content_types_for" do
|
||||
it "returns the formats accepted according to the setting value" do
|
||||
Setting["uploads.images.content_types"] = "image/jpeg image/gif"
|
||||
Setting["uploads.documents.content_types"] = "application/pdf application/msword"
|
||||
|
||||
expect(Setting.accepted_content_types_for("images")).to eq ["jpg", "gif"]
|
||||
expect(Setting.accepted_content_types_for("documents")).to eq ["pdf", "doc"]
|
||||
end
|
||||
|
||||
it "returns empty array if setting does't exist" do
|
||||
Setting.remove("uploads.images.content_types")
|
||||
Setting.remove("uploads.documents.content_types")
|
||||
|
||||
expect(Setting.accepted_content_types_for("images")).to be_empty
|
||||
expect(Setting.accepted_content_types_for("documents")).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe ".add_new_settings" do
|
||||
context "default settings with strings" do
|
||||
before do
|
||||
|
||||
Reference in New Issue
Block a user