kintone 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.travis.yml +2 -1
- data/README.md +166 -6
- data/kintone.gemspec +4 -2
- data/lib/kintone.rb +1 -0
- data/lib/kintone/api.rb +30 -3
- data/lib/kintone/api/guest.rb +17 -0
- data/lib/kintone/command/apis.rb +22 -0
- data/lib/kintone/command/app.rb +11 -0
- data/lib/kintone/command/guests.rb +15 -0
- data/lib/kintone/command/record.rb +6 -2
- data/lib/kintone/command/records.rb +9 -5
- data/lib/kintone/command/space_guests.rb +11 -0
- data/lib/kintone/command/space_members.rb +16 -0
- data/lib/kintone/command/space_thread.rb +14 -0
- data/lib/kintone/query.rb +146 -0
- data/lib/kintone/query/extension.rb +23 -0
- data/lib/kintone/type.rb +6 -0
- data/lib/kintone/type/extension/enumerable.rb +5 -0
- data/lib/kintone/type/extension/hash.rb +5 -0
- data/lib/kintone/type/extension/object.rb +5 -0
- data/lib/kintone/type/record.rb +11 -0
- data/lib/kintone/version.rb +1 -1
- data/spec/kintone/api/guest_spec.rb +41 -2
- data/spec/kintone/api_spec.rb +83 -20
- data/spec/kintone/command/apis_spec.rb +113 -0
- data/spec/kintone/command/app_spec.rb +33 -0
- data/spec/kintone/command/guests_spec.rb +65 -0
- data/spec/kintone/command/record_spec.rb +55 -37
- data/spec/kintone/command/records_spec.rb +50 -18
- data/spec/kintone/command/space_guests_spec.rb +34 -0
- data/spec/kintone/command/space_members_spec.rb +80 -0
- data/spec/kintone/command/space_spec.rb +1 -1
- data/spec/kintone/command/space_thread_spec.rb +52 -0
- data/spec/kintone/query_spec.rb +294 -0
- data/spec/kintone/type/record_spec.rb +38 -0
- data/spec/spec_helper.rb +1 -0
- metadata +67 -10
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/space_guests'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::SpaceGuests do
|
6
|
+
let(:target) { Kintone::Command::SpaceGuests.new(guest) }
|
7
|
+
let(:guest) { api.guest(guest_id) }
|
8
|
+
let(:guest_id) { 1 }
|
9
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
10
|
+
|
11
|
+
describe '#update' do
|
12
|
+
before(:each) do
|
13
|
+
stub_request(
|
14
|
+
:put,
|
15
|
+
'https://example.cybozu.com/k/guest/1/v1/space/guests.json'
|
16
|
+
)
|
17
|
+
.with(body: { id: id, guests: guests }.to_json)
|
18
|
+
.to_return(body: '{}', status: 200)
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { target.update(id, guests) }
|
22
|
+
|
23
|
+
let(:id) { 10 }
|
24
|
+
let(:guests) do
|
25
|
+
[
|
26
|
+
'guest1@example.com',
|
27
|
+
'guest2@example.com',
|
28
|
+
'guest3@example.com'
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
it { is_expected.to be_truthy }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/space_members'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::SpaceMembers do
|
6
|
+
let(:target) { Kintone::Command::SpaceMembers.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#get' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:get,
|
13
|
+
'https://example.cybozu.com/k/v1/space/members.json'
|
14
|
+
)
|
15
|
+
.with(query: { id: id })
|
16
|
+
.to_return(body: response_data.to_json, status: 200)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { target.get(id) }
|
20
|
+
|
21
|
+
let(:id) { 1 }
|
22
|
+
|
23
|
+
def response_data
|
24
|
+
{
|
25
|
+
'members' => members
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def members
|
30
|
+
[
|
31
|
+
{
|
32
|
+
'entity' => { 'type' => 'USER', 'code' => 'user1' },
|
33
|
+
'isAdmin' => false,
|
34
|
+
'isImplicit' => true
|
35
|
+
}
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
it { expect(subject).to match members }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#update' do
|
43
|
+
before(:each) do
|
44
|
+
stub_request(
|
45
|
+
:put,
|
46
|
+
'https://example.cybozu.com/k/v1/space/members.json'
|
47
|
+
)
|
48
|
+
.with(body: request_data.to_json)
|
49
|
+
.to_return(body: '{}', status: 200)
|
50
|
+
end
|
51
|
+
|
52
|
+
subject { target.update(id, members) }
|
53
|
+
|
54
|
+
let(:id) { 1 }
|
55
|
+
let(:members) do
|
56
|
+
[
|
57
|
+
{
|
58
|
+
'entity' => { 'type' => 'USER', 'code' => 'user1' },
|
59
|
+
'isAdmin' => false,
|
60
|
+
'isImplicit' => true
|
61
|
+
}
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
def request_data
|
66
|
+
{
|
67
|
+
'id' => 1,
|
68
|
+
'members' => [
|
69
|
+
{
|
70
|
+
'entity' => { 'type' => 'USER', 'code' => 'user1' },
|
71
|
+
'isAdmin' => false,
|
72
|
+
'isImplicit' => true
|
73
|
+
}
|
74
|
+
]
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it { expect(subject).to be_truthy }
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/command/space_thread'
|
3
|
+
require 'kintone/api'
|
4
|
+
|
5
|
+
describe Kintone::Command::SpaceThread do
|
6
|
+
let(:target) { Kintone::Command::SpaceThread.new(api) }
|
7
|
+
let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
|
8
|
+
|
9
|
+
describe '#update' do
|
10
|
+
before(:each) do
|
11
|
+
stub_request(
|
12
|
+
:put,
|
13
|
+
'https://example.cybozu.com/k/v1/space/thread.json'
|
14
|
+
)
|
15
|
+
.with(body: request_body)
|
16
|
+
.to_return(body: '{}', status: 200)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { target.update(id, name: name, body: body) }
|
20
|
+
|
21
|
+
let(:id) { 1 }
|
22
|
+
|
23
|
+
where(:name, :body, :request_body) do
|
24
|
+
[
|
25
|
+
[
|
26
|
+
'example thread',
|
27
|
+
'<b>awesome thread!</b>',
|
28
|
+
'{"id":1,"name":"example thread","body":"<b>awesome thread!</b>"}'
|
29
|
+
],
|
30
|
+
[
|
31
|
+
nil,
|
32
|
+
'<b>awesome thread!</b>',
|
33
|
+
'{"id":1,"body":"<b>awesome thread!</b>"}'
|
34
|
+
],
|
35
|
+
[
|
36
|
+
'example thread',
|
37
|
+
nil,
|
38
|
+
'{"id":1,"name":"example thread"}'
|
39
|
+
],
|
40
|
+
[
|
41
|
+
nil,
|
42
|
+
nil,
|
43
|
+
'{"id":1}'
|
44
|
+
]
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
with_them do
|
49
|
+
it { expect(subject).to be_truthy }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'kintone/query'
|
3
|
+
|
4
|
+
describe Kintone::Query do
|
5
|
+
describe '#to_s' do
|
6
|
+
subject { target.to_s }
|
7
|
+
|
8
|
+
context '==' do
|
9
|
+
where(:target, :result) do
|
10
|
+
[
|
11
|
+
[Kintone::Query.new { field(:text) == '"Hello, world."' }, 'text = "Hello, world."'],
|
12
|
+
[Kintone::Query.new { field(:text) == 'Hello, world.' }, 'text = "Hello, world."'],
|
13
|
+
[Kintone::Query.new { field('作成日時') == now }, '作成日時 = NOW()'],
|
14
|
+
[Kintone::Query.new { field('作成日時') == today }, '作成日時 = TODAY()'],
|
15
|
+
[Kintone::Query.new { field('作成日時') == this_month }, '作成日時 = THIS_MONTH()'],
|
16
|
+
[Kintone::Query.new { field('作成日時') == last_month }, '作成日時 = LAST_MONTH()'],
|
17
|
+
[Kintone::Query.new { field('作成日時') == this_year }, '作成日時 = THIS_YEAR()'],
|
18
|
+
[Kintone::Query.new { field(:number) == 100 }, 'number = 100']
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
with_them do
|
23
|
+
it { expect(subject).to eq result }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '!=' do
|
28
|
+
where(:target, :result) do
|
29
|
+
[
|
30
|
+
[Kintone::Query.new { field(:text) != '"Hello, world."' }, 'text != "Hello, world."'],
|
31
|
+
[Kintone::Query.new { field(:text) != 'Hello, world.' }, 'text != "Hello, world."'],
|
32
|
+
[Kintone::Query.new { field('作成日時') != now }, '作成日時 != NOW()'],
|
33
|
+
[Kintone::Query.new { field('作成日時') != today }, '作成日時 != TODAY()'],
|
34
|
+
[Kintone::Query.new { field('作成日時') != this_month }, '作成日時 != THIS_MONTH()'],
|
35
|
+
[Kintone::Query.new { field('作成日時') != last_month }, '作成日時 != LAST_MONTH()'],
|
36
|
+
[Kintone::Query.new { field('作成日時') != this_year }, '作成日時 != THIS_YEAR()'],
|
37
|
+
[Kintone::Query.new { field(:number) != 100 }, 'number != 100']
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
with_them do
|
42
|
+
it { expect(subject).to eq result }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context '>' do
|
47
|
+
where(:target, :result) do
|
48
|
+
[
|
49
|
+
[Kintone::Query.new { field(:text) > '"Hello, world."' }, 'text > "Hello, world."'],
|
50
|
+
[Kintone::Query.new { field(:text) > 'Hello, world.' }, 'text > "Hello, world."'],
|
51
|
+
[Kintone::Query.new { field('作成日時') > now }, '作成日時 > NOW()'],
|
52
|
+
[Kintone::Query.new { field('作成日時') > today }, '作成日時 > TODAY()'],
|
53
|
+
[Kintone::Query.new { field('作成日時') > this_month }, '作成日時 > THIS_MONTH()'],
|
54
|
+
[Kintone::Query.new { field('作成日時') > last_month }, '作成日時 > LAST_MONTH()'],
|
55
|
+
[Kintone::Query.new { field('作成日時') > this_year }, '作成日時 > THIS_YEAR()'],
|
56
|
+
[Kintone::Query.new { field(:number) > 100 }, 'number > 100']
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
with_them do
|
61
|
+
it { expect(subject).to eq result }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context '<' do
|
66
|
+
where(:target, :result) do
|
67
|
+
[
|
68
|
+
[Kintone::Query.new { field(:text) < '"Hello, world."' }, 'text < "Hello, world."'],
|
69
|
+
[Kintone::Query.new { field(:text) < 'Hello, world.' }, 'text < "Hello, world."'],
|
70
|
+
[Kintone::Query.new { field('作成日時') < now }, '作成日時 < NOW()'],
|
71
|
+
[Kintone::Query.new { field('作成日時') < today }, '作成日時 < TODAY()'],
|
72
|
+
[Kintone::Query.new { field('作成日時') < this_month }, '作成日時 < THIS_MONTH()'],
|
73
|
+
[Kintone::Query.new { field('作成日時') < last_month }, '作成日時 < LAST_MONTH()'],
|
74
|
+
[Kintone::Query.new { field('作成日時') < this_year }, '作成日時 < THIS_YEAR()'],
|
75
|
+
[Kintone::Query.new { field(:number) < 100 }, 'number < 100']
|
76
|
+
]
|
77
|
+
end
|
78
|
+
|
79
|
+
with_them do
|
80
|
+
it { expect(subject).to eq result }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context '>=' do
|
85
|
+
where(:target, :result) do
|
86
|
+
[
|
87
|
+
[Kintone::Query.new { field(:text) >= '"Hello, world."' }, 'text >= "Hello, world."'],
|
88
|
+
[Kintone::Query.new { field(:text) >= 'Hello, world.' }, 'text >= "Hello, world."'],
|
89
|
+
[Kintone::Query.new { field('作成日時') >= now }, '作成日時 >= NOW()'],
|
90
|
+
[Kintone::Query.new { field('作成日時') >= today }, '作成日時 >= TODAY()'],
|
91
|
+
[Kintone::Query.new { field('作成日時') >= this_month }, '作成日時 >= THIS_MONTH()'],
|
92
|
+
[Kintone::Query.new { field('作成日時') >= last_month }, '作成日時 >= LAST_MONTH()'],
|
93
|
+
[Kintone::Query.new { field('作成日時') >= this_year }, '作成日時 >= THIS_YEAR()'],
|
94
|
+
[Kintone::Query.new { field(:number) >= 100 }, 'number >= 100']
|
95
|
+
]
|
96
|
+
end
|
97
|
+
|
98
|
+
with_them do
|
99
|
+
it { expect(subject).to eq result }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context '<=' do
|
104
|
+
where(:target, :result) do
|
105
|
+
[
|
106
|
+
[Kintone::Query.new { field(:text) <= '"Hello, world."' }, 'text <= "Hello, world."'],
|
107
|
+
[Kintone::Query.new { field(:text) <= 'Hello, world.' }, 'text <= "Hello, world."'],
|
108
|
+
[Kintone::Query.new { field('作成日時') <= now }, '作成日時 <= NOW()'],
|
109
|
+
[Kintone::Query.new { field('作成日時') <= today }, '作成日時 <= TODAY()'],
|
110
|
+
[Kintone::Query.new { field('作成日時') <= this_month }, '作成日時 <= THIS_MONTH()'],
|
111
|
+
[Kintone::Query.new { field('作成日時') <= last_month }, '作成日時 <= LAST_MONTH()'],
|
112
|
+
[Kintone::Query.new { field('作成日時') <= this_year }, '作成日時 <= THIS_YEAR()'],
|
113
|
+
[Kintone::Query.new { field(:number) <= 100 }, 'number <= 100']
|
114
|
+
]
|
115
|
+
end
|
116
|
+
|
117
|
+
with_them do
|
118
|
+
it { expect(subject).to eq result }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'in' do
|
123
|
+
where(:target, :result) do
|
124
|
+
[
|
125
|
+
[Kintone::Query.new { field(:dropdown).in(['"A"', '"B"']) }, 'dropdown in ("A", "B")'],
|
126
|
+
[Kintone::Query.new { field(:dropdown).in(%w(A B)) }, 'dropdown in ("A", "B")'],
|
127
|
+
[Kintone::Query.new { field(:dropdown).in([:A, :B]) }, 'dropdown in ("A", "B")'],
|
128
|
+
[Kintone::Query.new { field(:dropdown).in([100, 200]) }, 'dropdown in (100, 200)'],
|
129
|
+
[Kintone::Query.new { field('作成者').in([login_user]) }, '作成者 in (LOGINUSER())']
|
130
|
+
]
|
131
|
+
end
|
132
|
+
|
133
|
+
with_them do
|
134
|
+
it { expect(subject).to eq result }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'not in' do
|
139
|
+
where(:target, :result) do
|
140
|
+
[
|
141
|
+
[
|
142
|
+
Kintone::Query.new { field(:dropdown).not_in(['"A"', '"B"']) },
|
143
|
+
'dropdown not in ("A", "B")'
|
144
|
+
],
|
145
|
+
[
|
146
|
+
Kintone::Query.new { field(:dropdown).not_in(%w(A B)) },
|
147
|
+
'dropdown not in ("A", "B")'
|
148
|
+
],
|
149
|
+
[
|
150
|
+
Kintone::Query.new { field(:dropdown).not_in([:A, :B]) },
|
151
|
+
'dropdown not in ("A", "B")'
|
152
|
+
],
|
153
|
+
[
|
154
|
+
Kintone::Query.new { field(:dropdown).not_in([100, 200]) },
|
155
|
+
'dropdown not in (100, 200)'
|
156
|
+
],
|
157
|
+
[
|
158
|
+
Kintone::Query.new { field('作成者').not_in([login_user]) },
|
159
|
+
'作成者 not in (LOGINUSER())'
|
160
|
+
]
|
161
|
+
]
|
162
|
+
end
|
163
|
+
|
164
|
+
with_them do
|
165
|
+
it { expect(subject).to eq result }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'like' do
|
170
|
+
where(:target, :result) do
|
171
|
+
[
|
172
|
+
[Kintone::Query.new { field(:text).like('Hello') }, 'text like "Hello"'],
|
173
|
+
[Kintone::Query.new { field(:text).like('"Hello"') }, 'text like "Hello"'],
|
174
|
+
[Kintone::Query.new { field(:text).like(:Hello) }, 'text like "Hello"']
|
175
|
+
]
|
176
|
+
end
|
177
|
+
|
178
|
+
with_them do
|
179
|
+
it { expect(subject).to eq result }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'not like' do
|
184
|
+
where(:target, :result) do
|
185
|
+
[
|
186
|
+
[Kintone::Query.new { field(:text).not_like('Hello') }, 'text not like "Hello"'],
|
187
|
+
[Kintone::Query.new { field(:text).not_like('"Hello"') }, 'text not like "Hello"'],
|
188
|
+
[Kintone::Query.new { field(:text).not_like(:Hello) }, 'text not like "Hello"']
|
189
|
+
]
|
190
|
+
end
|
191
|
+
|
192
|
+
with_them do
|
193
|
+
it { expect(subject).to eq result }
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'and!' do
|
198
|
+
let(:target) do
|
199
|
+
Kintone::Query.new do
|
200
|
+
field(:text).like 'Hello'
|
201
|
+
and!
|
202
|
+
field(:number) > 100
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def result
|
207
|
+
'text like "Hello" and number > 100'
|
208
|
+
end
|
209
|
+
|
210
|
+
it { expect(subject).to eq result }
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'or!' do
|
214
|
+
let(:target) do
|
215
|
+
Kintone::Query.new do
|
216
|
+
field(:text).like 'Hello'
|
217
|
+
or!
|
218
|
+
field(:number) > 100
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def result
|
223
|
+
'text like "Hello" or number > 100'
|
224
|
+
end
|
225
|
+
|
226
|
+
it { expect(subject).to eq result }
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'precede' do
|
230
|
+
let(:target) do
|
231
|
+
Kintone::Query.new do
|
232
|
+
precede do
|
233
|
+
field(:text).like 'Hello'
|
234
|
+
or!
|
235
|
+
field(:number) > 100
|
236
|
+
end
|
237
|
+
and!
|
238
|
+
precede do
|
239
|
+
field(:text2).not_like 'Hello'
|
240
|
+
and!
|
241
|
+
field(:number2) <= 100
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def result
|
247
|
+
'(text like "Hello" or number > 100) and (text2 not like "Hello" and number2 <= 100)'
|
248
|
+
end
|
249
|
+
|
250
|
+
it { expect(subject).to eq result }
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'order by' do
|
254
|
+
where(:target, :result) do
|
255
|
+
[
|
256
|
+
[Kintone::Query.new { order_by(:record_id, :asc) }, 'order by record_id asc'],
|
257
|
+
[Kintone::Query.new { order_by(:record_id, :desc) }, 'order by record_id desc'],
|
258
|
+
[Kintone::Query.new { order_by(:record_id) }, 'order by record_id asc'],
|
259
|
+
[Kintone::Query.new { order_by('作成日時', :desc) }, 'order by 作成日時 desc']
|
260
|
+
]
|
261
|
+
end
|
262
|
+
|
263
|
+
with_them do
|
264
|
+
it { expect(subject).to eq result }
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'limit' do
|
269
|
+
where(:target, :result) do
|
270
|
+
[
|
271
|
+
[Kintone::Query.new { limit(20) }, 'limit 20'],
|
272
|
+
[Kintone::Query.new { limit('20') }, 'limit 20']
|
273
|
+
]
|
274
|
+
end
|
275
|
+
|
276
|
+
with_them do
|
277
|
+
it { expect(subject).to eq result }
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'offset' do
|
282
|
+
where(:target, :result) do
|
283
|
+
[
|
284
|
+
[Kintone::Query.new { offset(30) }, 'offset 30'],
|
285
|
+
[Kintone::Query.new { offset('30') }, 'offset 30']
|
286
|
+
]
|
287
|
+
end
|
288
|
+
|
289
|
+
with_them do
|
290
|
+
it { expect(subject).to eq result }
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|