spec/renderer_spec.rb in chartnado-0.0.2 vs spec/renderer_spec.rb in chartnado-0.1.0

- old
+ new

@@ -15,10 +15,16 @@ expect(chart_json({[:a, 1] => 10, [:b, 1] => 20}, show_total: true)). to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, {name: :a, data: [[1, 10]]}, {name: :b, data: [[1, 20]]}] end + it "can add multiply by 100 to create a percentage" do + expect(chart_json({[:a, 1] => 0.1, [:b, 1] => 0.2}, percentage: true, show_total: true)). + to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, + {name: :a, data: [[1, 10.0]]}, + {name: :b, data: [[1, 20.0]]}] + end describe "with multiple scalar series" do it "can handle scalars" do expect(chart_json({:a => 10, :b => 20})). to eq([[:a, 10], [:b, 20]]) end @@ -33,9 +39,21 @@ expect(chart_json([[:a, {1 => 10}], [:b, {1 => 20}]])). to eq [{name: :a, data: [[1, 10]]}, {name: :b, data: [[1,20]]}] end it "can add totals" do expect(chart_json([[:a, {1 => 10}], [:b, {1 => 20}]], show_total: true)). + to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, + {name: :a, data: [[1, 10]]}, + {name: :b, data: [[1, 20]]}] + end + end + describe "for multiple series organized as a hash" do + it "can generate chartkick compatible series" do + expect(chart_json({:a => {1 => 10}, :b => {1 => 20}})). + to eq [{name: :a, data: [[1, 10]]}, {name: :b, data: [[1,20]]}] + end + it "can add totals" do + expect(chart_json({:a => {1 => 10}, :b => {1 => 20}}, show_total: true)). to eq [{name: 'Total', data: [[1, 0]], tooltip: [[1, 30.0]]}, {name: :a, data: [[1, 10]]}, {name: :b, data: [[1, 20]]}] end end