-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_all_the_things_spec.rb
113 lines (71 loc) · 2.49 KB
/
test_all_the_things_spec.rb
1
2
3
4
5
6
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'spec_helper'
require 'google_sheets'
RSpec.describe GoogleSheets::Session do
describe 'self.start_session' do
it 'starts session, can add & delete sheets' do
session = GoogleSheets::Session.start_session(
client_id: ENV['test_client_id'],
client_secret: ENV['test_client_secret'],
token_path: './tmp'
)
spreadsheet = session.spreadsheet_from_key '13kc3I2yn0jE-Fg-cAeGl3EvP7lAkxpqvZq6a7pQZJwY'
existing_sheet_names = spreadsheet.sheets.map &:title
sheet = spreadsheet.sheets[0]
sheet1_values = [
%w(first last age), %w(bob jones 92), %w(steve johnson 22)
]
expect(sheet.values).to eq(sheet1_values)
values = [['1','2'],['3','4']]
new_sheet_name = 'yoyo10'
sheet = spreadsheet.add_sheet(new_sheet_name, values: values)
expect(sheet.values).to eq(values)
new_sheet_names = existing_sheet_names + [new_sheet_name]
expect(spreadsheet.sheets.map(&:title)).to eq(new_sheet_names)
# dememoize the sheets
spreadsheet.refresh!
# hit the api again to ensure operation actually succeeded
expect(spreadsheet.sheets.map(&:title)).to eq(new_sheet_names)
sheet = spreadsheet.sheets[-1]
expect(sheet.title).to eq(new_sheet_name)
expect(sheet.values).to eq(values)
sheet.delete!
# same deal
spreadsheet.refresh!
expect(spreadsheet.sheets.map(&:title)).to eq(existing_sheet_names)
sheet1 = spreadsheet.sheets[0]
sheet1_json = [
{
first: 'bob',
last: 'jones',
age: '92'
},
{
first: 'steve',
last: 'johnson',
age: '22'
}
]
expect(sheet1.to_json).to eq(sheet1_json)
sheet1_json[0][:first] = 'bobby'
sheet1.set_values_from_json sheet1_json
expect(sheet1.values[1][0]).to eq('bobby')
sheet1.save!
spreadsheet.refresh!
sheet1 = spreadsheet.sheets[0]
expected_values = [
%w(first last age), %w(bobby jones 92), %w(steve johnson 22)
]
expect(sheet1.values).to eq(expected_values)
sheet1.values[1][0] = 'bob '
sheet1.save!
spreadsheet.refresh!
expect(spreadsheet.sheets[0].values[1][0]).to eq('bob ')
GoogleSheets.strip_all_cells = true
spreadsheet.refresh!
expect(spreadsheet.sheets[0].values[1][0]).to eq('bob')
sheet1 = spreadsheet.sheets[0]
sheet1.values[1][0] = 'bob'
sheet1.save!
end
end
end