mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: Move more service code to core (#26613)
This is to enable :array type attributes for Contract attributes in services, this is a followup to the move of services from chat to core here: cab178a40557e205e9c3e75fcb411a5e0e164d15 Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
@ -1,49 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Chat::Types::Array do
|
||||
subject(:type) { described_class.new }
|
||||
|
||||
describe "#cast" do
|
||||
subject(:casted_value) { type.cast(value) }
|
||||
|
||||
context "when 'value' is a string" do
|
||||
let(:value) { "first,second,third" }
|
||||
|
||||
it "splits it" do
|
||||
expect(casted_value).to eq(%w[first second third])
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'value' is an array" do
|
||||
let(:value) { %w[existing array] }
|
||||
|
||||
it "returns it" do
|
||||
expect(casted_value).to eq(value)
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'value' is an array of numbers as string" do
|
||||
let(:value) { %w[1 2] }
|
||||
|
||||
it "returns it with string casted as integer" do
|
||||
expect(casted_value).to eq([1, 2])
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'value' is an array of numbers" do
|
||||
let(:value) { [1, 2] }
|
||||
|
||||
it "returns it" do
|
||||
expect(casted_value).to eq([1, 2])
|
||||
end
|
||||
end
|
||||
|
||||
context "when 'value' is something else" do
|
||||
let(:value) { Time.current }
|
||||
|
||||
it "wraps it in a new array" do
|
||||
expect(casted_value).to eq([value])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user