cell_set 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ module CellSet
8
8
  include Attributes
9
9
  include ActiveModel::Serializers::JSON
10
10
  include ActiveModel::Serializers::Xml
11
+ self.include_root_in_json = false
11
12
 
12
13
  def as_json(options = nil)
13
14
  # Strangely couldn't use options = {} in JRuby
@@ -15,7 +16,11 @@ module CellSet
15
16
  json = super(options)
16
17
  unless (options.has_key?(:only) && !options[:only].include?("cells")) ||
17
18
  (options.has_key?(:except) && options[:except].include?("cells"))
18
- json.first[1]["cells"] = @cellHash
19
+ if options[:root]
20
+ json.first[1]["cells"] = @cellHash
21
+ else
22
+ json["cells"] = @cellHash
23
+ end
19
24
  end
20
25
  json
21
26
  end
@@ -1,3 +1,3 @@
1
1
  module Version
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -74,6 +74,15 @@ describe CellSet::CellSetAxis do
74
74
  }
75
75
  end
76
76
 
77
+ it "should serialize with root" do
78
+ axis.as_json(:root => true).should == {
79
+ "cell_set_axis" => {
80
+ "axis_ordinal" => 0,
81
+ "positions" => [position1, position2]
82
+ }
83
+ }
84
+ end
85
+
77
86
  it "should deserialize" do
78
87
  ::CellSet::CellSetAxis.new.from_json(axis.to_json).should == axis
79
88
  end
@@ -152,6 +152,13 @@ describe CellSet::CellSet do
152
152
  context "JSON" do
153
153
  it "should serialize" do
154
154
  cell_set.as_json.should == {
155
+ "axes" => [column_axis, row_axis],
156
+ "cells" => {}
157
+ }
158
+ end
159
+
160
+ it "should serialize with root" do
161
+ cell_set.as_json(:root => true).should == {
155
162
  "cell_set" => {
156
163
  "axes" => [column_axis, row_axis],
157
164
  "cells" => {}
@@ -161,25 +168,19 @@ describe CellSet::CellSet do
161
168
 
162
169
  it "should serialize only cells" do
163
170
  cell_set.as_json(:only => "cells").should == {
164
- "cell_set" => {
165
- "cells" => {}
166
- }
171
+ "cells" => {}
167
172
  }
168
173
  end
169
174
 
170
175
  it "should serialize excluding cells" do
171
176
  cell_set.as_json(:except => "cells").should == {
172
- "cell_set" => {
173
- "axes" => [column_axis, row_axis]
174
- }
177
+ "axes" => [column_axis, row_axis]
175
178
  }
176
179
  end
177
180
 
178
181
  it "should serialize only axes" do
179
182
  cell_set.as_json(:only => "axes").should == {
180
- "cell_set" => {
181
- "axes" => [column_axis, row_axis]
182
- }
183
+ "axes" => [column_axis, row_axis]
183
184
  }
184
185
  end
185
186
 
@@ -56,6 +56,26 @@ describe CellSet::Member do
56
56
  }
57
57
  end
58
58
 
59
+ it "should serialize with root" do
60
+ member.as_json(:root => true).should == {
61
+ "member" => {
62
+ "caption" => nil,
63
+ "childMembers" => [],
64
+ "depth" => nil,
65
+ "description" => nil,
66
+ "dimension" => nil,
67
+ "expression" => nil,
68
+ "hierarchy" => nil,
69
+ "level" => nil,
70
+ "memberType" => nil,
71
+ "name" => name,
72
+ "ordinal" => 0,
73
+ "parentMember" => nil,
74
+ "uniqueName" => unique_name
75
+ }
76
+ }
77
+ end
78
+
59
79
  it "should deserialize" do
60
80
  ::CellSet::Member.new.from_json(member.to_json).should == member
61
81
  end
@@ -66,8 +66,17 @@ describe CellSet::Position do
66
66
  context "JSON" do
67
67
  it "should serialize" do
68
68
  position.as_json.should == {
69
+ "ordinal" => 0,
70
+ "members" => [member1, member2]
71
+ }
72
+ end
73
+
74
+ it "should serialize with root" do
75
+ position.as_json(:root => true).should == {
76
+ "position" => {
69
77
  "ordinal" => 0,
70
78
  "members" => [member1, member2]
79
+ }
71
80
  }
72
81
  end
73
82
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cell_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: