Skip to content

Commit

Permalink
Merge pull request #105 from tigris/numbers
Browse files Browse the repository at this point in the history
Convert param input to String
  • Loading branch information
djmattyg007 authored Jun 20, 2024
2 parents 7cef2f7 + 8a843b9 commit caf4c4f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/stackup/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def to_a
if value == :use_previous_value
record[:use_previous_value] = true
else
record[:parameter_value] = value
record[:parameter_value] = ParameterValue.new(value).to_param
end
end
end
Expand Down Expand Up @@ -75,7 +75,26 @@ def value
if use_previous_value
:use_previous_value
else
parameter_value
ParameterValue.new(parameter_value).to_param
end
end

end

class ParameterValue

def initialize(value)
@value = value
end

def to_param
case @value
when TrueClass, FalseClass, Integer then
@value.to_s
when Array
@value.map { |v| ParameterValue.new(v).to_param }.join(",")
else
@value
end
end

Expand Down
45 changes: 45 additions & 0 deletions spec/stackup/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,51 @@

end

context "with non-string values" do

let(:input_records) do
[
{ :parameter_key => "Integer", :parameter_value => 123_456_789 },
{ :parameter_key => "Truthy", :parameter_value => true },
{ :parameter_key => "Falsey", :parameter_value => false },
{ :parameter_key => "Null", :parameter_value => nil },
{ :parameter_key => "Array", :parameter_value => ["one", 2] },
{ :parameter_key => "String", :parameter_value => "string" }
]
end

subject(:parameters) { Stackup::Parameters.new(input_records) }

describe "#to_hash" do
it "converts the to strings where appropriate" do
expected = {
"Integer" => "123456789",
"Truthy" => "true",
"Falsey" => "false",
"Null" => nil,
"Array" => "one,2",
"String" => "string"
}
expect(parameters.to_hash).to eql(expected)
end
end

describe "#to_a" do
it "converts the to strings where appropriate" do
expected = [
{ :parameter_key => "Integer", :parameter_value => "123456789" },
{ :parameter_key => "Truthy", :parameter_value => "true" },
{ :parameter_key => "Falsey", :parameter_value => "false" },
{ :parameter_key => "Null", :parameter_value => nil },
{ :parameter_key => "Array", :parameter_value => "one,2" },
{ :parameter_key => "String", :parameter_value => "string" }
]
expect(parameters.to_a).to eql(expected)
end
end

end

context "with empty parameter file" do

let(:input_records) { false }
Expand Down

0 comments on commit caf4c4f

Please sign in to comment.