redisarray 0.0.1

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.
@@ -0,0 +1,41 @@
1
+ ---
2
+ - - (five rows) row 1 cell 1
3
+ - (five rows) row 1 cell 2
4
+ - (five rows) row 1 cell 3
5
+ - (five rows) row 1 cell 4
6
+ - (five rows) row 1 cell 5
7
+ -
8
+ -
9
+ -
10
+ - - (five rows) row 2 cell 1
11
+ - (five rows) row 2 cell 2
12
+ - (five rows) row 2 cell 3
13
+ - (five rows) row 2 cell 4
14
+ - (five rows) row 2 cell 5
15
+ -
16
+ -
17
+ -
18
+ - - (five rows) row 3 cell 1
19
+ - (five rows) row 3 cell 2
20
+ - (five rows) row 3 cell 3
21
+ - (five rows) row 3 cell 4
22
+ - (five rows) row 3 cell 5
23
+ -
24
+ -
25
+ -
26
+ - - (five rows) row 4 cell 1
27
+ - (five rows) row 4 cell 2
28
+ - (five rows) row 4 cell 3
29
+ - (five rows) row 4 cell 4
30
+ - (five rows) row 4 cell 5
31
+ -
32
+ -
33
+ -
34
+ - - (five rows) row 5 cell 1
35
+ - (five rows) row 5 cell 2
36
+ - (five rows) row 5 cell 3
37
+ - (five rows) row 5 cell 4
38
+ - (five rows) row 5 cell 5
39
+ -
40
+ -
41
+ -
@@ -0,0 +1,9 @@
1
+ ---
2
+ - - (one row) row 1 cell 1
3
+ - (one row) row 1 cell 2
4
+ - (one row) row 1 cell 3
5
+ - (one row) row 1 cell 4
6
+ - (one row) row 1 cell 5
7
+ -
8
+ -
9
+ -
@@ -0,0 +1,37 @@
1
+ ---
2
+ - HEADER
3
+ - HEADER
4
+ - HEADER
5
+ - HEADER
6
+ - HEADER
7
+ - HEADER
8
+ - HEADER
9
+ - HEADER
10
+ - HEADER
11
+ - HEADER
12
+ - HEADER
13
+ - HEADER
14
+ - HEADER
15
+ - HEADER
16
+ - HEADER
17
+ - HEADER
18
+ - HEADER
19
+ - HEADER
20
+ - HEADER
21
+ - HEADER
22
+ - HEADER
23
+ - HEADER
24
+ - HEADER
25
+ - HEADER
26
+ - HEADER
27
+ - HEADER
28
+ - HEADER
29
+ - HEADER
30
+ - HEADER
31
+ - HEADER
32
+ - HEADER
33
+ - HEADER
34
+ - HEADER
35
+ - HEADER
36
+ - HEADER
37
+ - HEADER
@@ -0,0 +1,37 @@
1
+ ---
2
+ - - (one row with header) row 1 cell 1
3
+ - (one row with header) row 1 cell 2
4
+ - (one row with header) row 1 cell 3
5
+ - (one row with header) row 1 cell 4
6
+ - (one row with header) row 1 cell 5
7
+ -
8
+ -
9
+ -
10
+ -
11
+ -
12
+ -
13
+ -
14
+ -
15
+ -
16
+ -
17
+ -
18
+ -
19
+ -
20
+ -
21
+ -
22
+ -
23
+ -
24
+ -
25
+ -
26
+ -
27
+ -
28
+ -
29
+ -
30
+ -
31
+ -
32
+ -
33
+ -
34
+ -
35
+ -
36
+ -
37
+ -
@@ -0,0 +1,25 @@
1
+ ---
2
+ - - "11000000"
3
+ - 1st row 1st cell
4
+ - 1st row 2nd cell
5
+ -
6
+ - 1st row 4th cell
7
+ -
8
+ -
9
+ -
10
+ - - "12000000"
11
+ - 2nd row 1st cell
12
+ - 2nd row 2nd cell
13
+ - 2nd row 3rd cell
14
+ -
15
+ -
16
+ -
17
+ -
18
+ - - "13000000"
19
+ -
20
+ - 3rd row 2nd cell
21
+ -
22
+ -
23
+ -
24
+ -
25
+ -
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ describe RedisArray::RedisHashGroup do
4
+
5
+ before(:each) do
6
+ end
7
+
8
+ describe "#initialize" do
9
+ before(:each) do
10
+ end
11
+
12
+ it "generates new group name with specified prefix" do
13
+ @redis_hash_group_name = RedisHashGroup.new(:prefix => 'leb_standard_product').name
14
+ @redis_hash_group_name.
15
+ should =~ /^leb_standard_product/
16
+ end
17
+
18
+ it "generates new group name without specified prefix" do
19
+ @redis_hash_group_name = RedisHashGroup.new.name
20
+ @redis_hash_group_name.
21
+ should =~ /^\d/
22
+ end
23
+
24
+ it "retrieves existing group name when specified the group name" do
25
+ group_name = RedisHashGroup.new.name
26
+ @workbook = RedisWorkbook.new group_name, 'matrix'
27
+ @sheet_name = '__Status__'
28
+
29
+ @workbook.set_sheet_data @sheet_name,
30
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml"))),
31
+ :start_from_row => 3
32
+
33
+ @redis_hash_group_name = RedisHashGroup.new(:existing_group_name => group_name).name
34
+
35
+ @redis_hash_group_name.
36
+ should == group_name
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,239 @@
1
+ require File.dirname(__FILE__) + "/spec_helper"
2
+
3
+ include RedisArray
4
+
5
+ describe RedisWorkbook do
6
+
7
+ before(:each) do
8
+ group_name = RedisHashGroup.new.name
9
+ @workbook = RedisWorkbook.new group_name, 'matrix'
10
+ end
11
+
12
+ describe "#set_sheet_data" do
13
+ before(:each) do
14
+ @sheet_name = '__Status__'
15
+ end
16
+
17
+ it "saves all sheet rows in redis starting at given row index" do
18
+ @workbook.set_sheet_data @sheet_name,
19
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml"))),
20
+ :start_from_row => 3
21
+ @workbook.get_sheet_data(@sheet_name).
22
+ should include({5 => "(five rows) row 3 cell 1,(five rows) row 3 cell 2,(five rows) row 3 cell 3,(five rows) row 3 cell 4,(five rows) row 3 cell 5,,,"})
23
+ end
24
+
25
+ it "saves a single sheet row in redis at given row index" do
26
+ @workbook.set_sheet_data @sheet_name,
27
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row.yaml"))),
28
+ :start_from_row => 0
29
+ @workbook.get_sheet_data(@sheet_name).
30
+ should == {0 => "(one row) row 1 cell 1,(one row) row 1 cell 2,(one row) row 1 cell 3,(one row) row 1 cell 4,(one row) row 1 cell 5,,,"}
31
+ end
32
+
33
+ context ":skip_headers option used" do
34
+ it "saves only sheet data without header (i.e. omitting the 0 index and starting at 1 index) when specified to :skip_headers" do
35
+
36
+ options = {:skip_headers => true}
37
+ @workbook.set_sheet_data @sheet_name,
38
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/one_row.yaml"))),
39
+ options.merge(:header_row => YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/headers.yaml"))))
40
+
41
+ @workbook.get_sheet_data(@sheet_name).
42
+ should == {1 => "(one row with header) row 1 cell 1,(one row with header) row 1 cell 2,(one row with header) row 1 cell 3,(one row with header) row 1 cell 4,(one row with header) row 1 cell 5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}
43
+
44
+
45
+ # the same for case where there is not :header_row specified
46
+ @workbook.set_sheet_data @sheet_name,
47
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/one_row.yaml"))),
48
+ options
49
+
50
+ @workbook.get_sheet_data(@sheet_name).
51
+ should == {1 => "(one row with header) row 1 cell 1,(one row with header) row 1 cell 2,(one row with header) row 1 cell 3,(one row with header) row 1 cell 4,(one row with header) row 1 cell 5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}
52
+ end
53
+
54
+
55
+ it "does not save anything when there is no data and when specified to :skip_headers" do
56
+ options = {:skip_headers => true}
57
+ @workbook.set_sheet_data @sheet_name,
58
+ rows = [],
59
+ options.merge(:header_row => YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/headers.yaml"))))
60
+
61
+ @workbook.get_sheet_data(@sheet_name).
62
+ should == {}
63
+
64
+ # the same for case where there is not :header_row specified
65
+ @workbook.set_sheet_data @sheet_name,
66
+ rows = [],
67
+ options
68
+
69
+ @workbook.get_sheet_data(@sheet_name).
70
+ should == {}
71
+ end
72
+
73
+ it "follows a rule that :start_from_row option takes precedence over :skip_headers" do
74
+ options = {:skip_headers => true, :start_from_row => 4}
75
+ @workbook.set_sheet_data @sheet_name,
76
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/one_row.yaml"))),
77
+ options.merge(:header_row => YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/headers.yaml"))))
78
+
79
+ @workbook.get_sheet_data(@sheet_name).
80
+ should == {4 => "(one row with header) row 1 cell 1,(one row with header) row 1 cell 2,(one row with header) row 1 cell 3,(one row with header) row 1 cell 4,(one row with header) row 1 cell 5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}
81
+
82
+ # the same for case where there is no :header_row specified
83
+ @workbook.set_sheet_data @sheet_name,
84
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/one_row_with_headers/one_row.yaml"))),
85
+ options
86
+
87
+ @workbook.get_sheet_data(@sheet_name).
88
+ should == {4 => "(one row with header) row 1 cell 1,(one row with header) row 1 cell 2,(one row with header) row 1 cell 3,(one row with header) row 1 cell 4,(one row with header) row 1 cell 5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#append_sheet_data" do
94
+ before(:each) do
95
+ @sheet_name = '__Status__'
96
+ end
97
+
98
+ context "the sheet is empty" do
99
+ it "writes all rows in redis starting at row 0" do
100
+ @workbook.append_sheet_data @sheet_name,
101
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml")))
102
+ @workbook.get_sheet_data(@sheet_name).length.should == 5
103
+ @workbook.get_sheet_data(@sheet_name).
104
+ should include({0 => "(five rows) row 1 cell 1,(five rows) row 1 cell 2,(five rows) row 1 cell 3,(five rows) row 1 cell 4,(five rows) row 1 cell 5,,,"})
105
+ end
106
+ end
107
+
108
+ context "the sheet contains a few rows already" do
109
+ before(:each) do
110
+ @sheet_name = '__Status__'
111
+ @workbook.set_sheet_data @sheet_name,
112
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml"))),
113
+ :start_from_row => 0
114
+ end
115
+
116
+ it "appends all rows in redis starting at the first empty row" do
117
+ @workbook.append_sheet_data @sheet_name,
118
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/three_rows.yaml")))
119
+ @workbook.get_sheet_data(@sheet_name).length.should == 8
120
+ @workbook.get_sheet_data(@sheet_name).
121
+ should include({0 => "(five rows) row 1 cell 1,(five rows) row 1 cell 2,(five rows) row 1 cell 3,(five rows) row 1 cell 4,(five rows) row 1 cell 5,,,"})
122
+ @workbook.get_sheet_data(@sheet_name).
123
+ should include({7 => '13000000,,3rd row 2nd cell,,,,,'})
124
+ end
125
+ end
126
+
127
+ context "the sheet contains a few hundred rows already" do
128
+ before(:each) do
129
+ @sheet_name = '__Status__'
130
+ @workbook.set_sheet_data @sheet_name,
131
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/328_rows.yaml"))),
132
+ :start_from_row => 0
133
+ end
134
+
135
+ context "appending only a few rows" do
136
+ before(:each) do
137
+ @workbook.append_sheet_data @sheet_name,
138
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/three_rows.yaml")))
139
+ end
140
+ it "leaves existing data intact" do
141
+ @workbook.get_sheet_data(@sheet_name).
142
+ should include({0 => '10000000,random data,random data,,random data,,,'})
143
+ @workbook.get_sheet_data(@sheet_name).
144
+ should include({327 => '10000000,random data,random data,,random data,,,'})
145
+ end
146
+ it "appends all rows in redis starting at the first empty row" do
147
+ @workbook.get_sheet_data(@sheet_name).length.should == 331
148
+ @workbook.get_sheet_data(@sheet_name).
149
+ should include({328 => '11000000,1st row 1st cell,1st row 2nd cell,,1st row 4th cell,,,'})
150
+ @workbook.get_sheet_data(@sheet_name).
151
+ should include({330 => "13000000,,3rd row 2nd cell,,,,,"})
152
+ @workbook.get_sheet_data(@sheet_name).
153
+ should include({331 => nil}) # i.e. the hash should not have key 331
154
+ end
155
+ end
156
+
157
+ context "appending a few hundred rows" do
158
+ before(:each) do
159
+ @workbook.append_sheet_data @sheet_name,
160
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/256_rows.yaml")))
161
+ end
162
+ it "leaves existing data intact" do
163
+ @workbook.get_sheet_data(@sheet_name).
164
+ should include({0 => '10000000,random data,random data,,random data,,,'})
165
+ @workbook.get_sheet_data(@sheet_name).
166
+ should include({327 => '10000000,random data,random data,,random data,,,'})
167
+ end
168
+ it "appends all rows in redis starting at the first empty row" do
169
+ @workbook.get_sheet_data(@sheet_name).length.should == 584
170
+ @workbook.get_sheet_data(@sheet_name).
171
+ should include({328 => "23400000,some data,,some data,some data,,,"})
172
+ @workbook.get_sheet_data(@sheet_name).
173
+ should include({583 => "23400000,some data,,some data,some data,,,"})
174
+ @workbook.get_sheet_data(@sheet_name).
175
+ should include({584 => nil}) # i.e. the hash should not have the key
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ context "retrieving data" do
182
+ before(:each) do
183
+ @sheet_name = '__Status__'
184
+ @workbook.set_sheet_data @sheet_name,
185
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml"))),
186
+ :start_from_row => 0
187
+ end
188
+
189
+ describe "#get_sheet_data" do
190
+ before(:each) do
191
+ end
192
+
193
+ it "retrieves all sheet rows from redis" do
194
+ @workbook.get_sheet_data(@sheet_name, rows = 0..-1).
195
+ should include({4 => "(five rows) row 5 cell 1,(five rows) row 5 cell 2,(five rows) row 5 cell 3,(five rows) row 5 cell 4,(five rows) row 5 cell 5,,,"})
196
+ end
197
+
198
+ it "retrieves single sheet row from redis" do
199
+ @workbook.get_sheet_data(@sheet_name, rows = 2).
200
+ should == {2 => "(five rows) row 3 cell 1,(five rows) row 3 cell 2,(five rows) row 3 cell 3,(five rows) row 3 cell 4,(five rows) row 3 cell 5,,,"}
201
+ end
202
+ end
203
+
204
+ describe "#get_sheet_data_as_array" do
205
+ before(:each) do
206
+ @sheet_name = '__Status__'
207
+ @workbook.set_sheet_data @sheet_name,
208
+ rows = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__), "fixtures/five_rows.yaml"))),
209
+ :start_from_row => 0
210
+ @third_row = YAML::load(
211
+ <<-YAML
212
+ ---
213
+ - !str:CSV::Cell (five rows) row 3 cell 1
214
+ - !str:CSV::Cell (five rows) row 3 cell 2
215
+ - !str:CSV::Cell (five rows) row 3 cell 3
216
+ - !str:CSV::Cell (five rows) row 3 cell 4
217
+ - !str:CSV::Cell (five rows) row 3 cell 5
218
+ - !str:CSV::Cell
219
+ - !str:CSV::Cell
220
+ - !str:CSV::Cell
221
+ YAML
222
+ )
223
+ end
224
+
225
+ it "retrieves all sheet rows from redis" do
226
+ @workbook.get_sheet_data_as_array(@sheet_name, rows = 0..-1)[2].
227
+ should == @third_row
228
+ end
229
+
230
+ it "retrieves single sheet row from redis" do
231
+ @workbook.get_sheet_data_as_array(@sheet_name, rows = 2)[0].
232
+ should == @third_row
233
+ end
234
+ end
235
+ end
236
+
237
+
238
+ end
239
+
@@ -0,0 +1,10 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'fileutils'
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ require 'rspec'
8
+
9
+ require 'redisarray'
10
+ require 'yaml'