Browse files

Typecast gate values for json.

  • Loading branch information...
1 parent 0e7e43a commit fd5f240e122ab42991bc1eb9e1aca98a1c7fa164 @jnunemaker committed Feb 18, 2013
Showing with 13 additions and 2 deletions.
  1. +12 −1 lib/flipper/ui/decorators/gate.rb
  2. +1 −1 spec/flipper/ui/decorators/gate_spec.rb
View
13 lib/flipper/ui/decorators/gate.rb
@@ -17,10 +17,21 @@ def initialize(gate, value = nil)
# Public: Returns instance as hash that is ready to be json dumped.
def as_json
+ value_as_json = case data_type
+ when :set
+ value.to_a
+ when :boolean
+ value == 'true'
+ when :integer
+ value.to_i
+ else
+ value
+ end
+
{
'key' => gate.key.to_s,
'name' => gate.name.to_s,
- 'value' => @value,
+ 'value' => value_as_json,
}
end
end
View
2 spec/flipper/ui/decorators/gate_spec.rb
@@ -41,7 +41,7 @@
end
it "includes value" do
- @result['value'].should eq('false')
+ @result['value'].should be(false)
end
end
end

0 comments on commit fd5f240

Please sign in to comment.