kintone 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.rubocop.yml +11 -1
  4. data/.travis.yml +15 -1
  5. data/Guardfile +2 -2
  6. data/README.md +4 -0
  7. data/kintone.gemspec +3 -5
  8. data/lib/kintone/api.rb +18 -24
  9. data/lib/kintone/api/guest.rb +6 -2
  10. data/lib/kintone/command/accessor.rb +1 -1
  11. data/lib/kintone/command/guests.rb +1 -1
  12. data/lib/kintone/command/record.rb +1 -1
  13. data/lib/kintone/command/records.rb +3 -2
  14. data/lib/kintone/kintone_error.rb +11 -0
  15. data/lib/kintone/query.rb +1 -1
  16. data/lib/kintone/version.rb +1 -1
  17. data/spec/kintone/api/guest_spec.rb +98 -10
  18. data/spec/kintone/api_spec.rb +186 -75
  19. data/spec/kintone/command/apis_spec.rb +70 -8
  20. data/spec/kintone/command/app_acl_spec.rb +21 -6
  21. data/spec/kintone/command/app_spec.rb +22 -2
  22. data/spec/kintone/command/apps_spec.rb +25 -2
  23. data/spec/kintone/command/bulk_request_spec.rb +22 -2
  24. data/spec/kintone/command/field_acl_spec.rb +25 -7
  25. data/spec/kintone/command/file_spec.rb +28 -12
  26. data/spec/kintone/command/form_spec.rb +23 -6
  27. data/spec/kintone/command/guests_spec.rb +44 -4
  28. data/spec/kintone/command/record_acl_spec.rb +27 -8
  29. data/spec/kintone/command/record_spec.rb +77 -10
  30. data/spec/kintone/command/records_spec.rb +157 -15
  31. data/spec/kintone/command/space_body_spec.rb +25 -7
  32. data/spec/kintone/command/space_guests_spec.rb +22 -2
  33. data/spec/kintone/command/space_members_spec.rb +47 -13
  34. data/spec/kintone/command/space_spec.rb +49 -19
  35. data/spec/kintone/command/space_thread_spec.rb +26 -2
  36. data/spec/kintone/command/template_space_spec.rb +37 -20
  37. data/spec/kintone/kintone_error_spec.rb +22 -0
  38. data/spec/spec_helper.rb +3 -0
  39. metadata +17 -27
@@ -7,22 +7,37 @@ describe Kintone::Command::AppAcl do
7
7
  let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
8
 
9
9
  describe '#update' do
10
+ before(:each) do
11
+ stub_request(
12
+ :put,
13
+ 'https://example.cybozu.com/k/v1/app/acl.json'
14
+ )
15
+ .with(body: { 'app' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
16
+ .to_return(body: '{}', status: 200, headers: { 'Content-type' => 'application/json' })
17
+ end
18
+
10
19
  subject { target.update(app, rights) }
11
20
 
12
- context '' do
21
+ let(:app) { 1 }
22
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
23
+
24
+ it { expect(subject).to eq({}) }
25
+
26
+ context 'fail to request' do
13
27
  before(:each) do
14
28
  stub_request(
15
29
  :put,
16
30
  'https://example.cybozu.com/k/v1/app/acl.json'
17
31
  )
18
32
  .with(body: { 'app' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
- .to_return(body: '{}', status: 200, headers: { 'Content-type' => 'application/json' })
33
+ .to_return(
34
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
35
+ status: 500,
36
+ headers: { 'Content-Type' => 'application/json' }
37
+ )
20
38
  end
21
39
 
22
- let(:app) { 1 }
23
- let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
24
-
25
- it { expect(subject).to eq({}) }
40
+ it { expect { subject }.to raise_error Kintone::KintoneError }
26
41
  end
27
42
  end
28
43
  end
@@ -12,8 +12,11 @@ describe Kintone::Command::App do
12
12
  'https://example.cybozu.com/k/v1/app.json'
13
13
  )
14
14
  .with(query: { id: id })
15
- .to_return(body: response_data.to_json, status: 200,
16
- headers: { 'Content-type' => 'application/json' })
15
+ .to_return(
16
+ body: response_data.to_json,
17
+ status: 200,
18
+ headers: { 'Content-type' => 'application/json' }
19
+ )
17
20
  end
18
21
 
19
22
  subject { target.get(id) }
@@ -30,5 +33,22 @@ describe Kintone::Command::App do
30
33
  end
31
34
 
32
35
  it { is_expected.to be_kind_of(Hash) }
36
+
37
+ context 'fail to request' do
38
+ before(:each) do
39
+ stub_request(
40
+ :get,
41
+ 'https://example.cybozu.com/k/v1/app.json'
42
+ )
43
+ .with(query: { id: id })
44
+ .to_return(
45
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
46
+ status: 500,
47
+ headers: { 'Content-Type' => 'application/json' }
48
+ )
49
+ end
50
+
51
+ it { expect { subject }.to raise_error Kintone::KintoneError }
52
+ end
33
53
  end
34
54
  end
@@ -15,8 +15,11 @@ describe Kintone::Command::Apps do
15
15
  'https://example.cybozu.com/k/v1/apps.json'
16
16
  )
17
17
  .with(query: query)
18
- .to_return(body: { apps: [] }.to_json, status: 200,
19
- headers: { 'Content-type' => 'application/json' })
18
+ .to_return(
19
+ body: { apps: [] }.to_json,
20
+ status: 200,
21
+ headers: { 'Content-type' => 'application/json' }
22
+ )
20
23
  end
21
24
 
22
25
  where(:params, :query) do
@@ -51,5 +54,25 @@ describe Kintone::Command::Apps do
51
54
 
52
55
  it { expect { subject }.to raise_error NoMethodError }
53
56
  end
57
+
58
+ context 'fail to request' do
59
+ before(:each) do
60
+ stub_request(
61
+ :get,
62
+ 'https://example.cybozu.com/k/v1/apps.json'
63
+ )
64
+ .with(query: query)
65
+ .to_return(
66
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
67
+ status: 500,
68
+ headers: { 'Content-Type' => 'application/json' }
69
+ )
70
+ end
71
+
72
+ let(:params) { { ids: [100, 200] } }
73
+ let(:query) { 'ids[0]=100&ids[1]=200' }
74
+
75
+ it { expect { subject }.to raise_error Kintone::KintoneError }
76
+ end
54
77
  end
55
78
  end
@@ -13,8 +13,11 @@ describe Kintone::Command::BulkRequest do
13
13
  'https://example.cybozu.com/k/v1/bulkRequest.json'
14
14
  )
15
15
  .with(body: { requests: requests }.to_json)
16
- .to_return(body: { 'results' => results }.to_json, status: 200,
17
- headers: { 'Content-type' => 'application/json' })
16
+ .to_return(
17
+ body: { 'results' => results }.to_json,
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
18
21
  end
19
22
 
20
23
  subject { target.request(requests) }
@@ -68,5 +71,22 @@ describe Kintone::Command::BulkRequest do
68
71
  end
69
72
 
70
73
  it { is_expected.to eq results }
74
+
75
+ context 'fail to request' do
76
+ before(:each) do
77
+ stub_request(
78
+ :post,
79
+ 'https://example.cybozu.com/k/v1/bulkRequest.json'
80
+ )
81
+ .with(body: { requests: requests }.to_json)
82
+ .to_return(
83
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
84
+ status: 500,
85
+ headers: { 'Content-Type' => 'application/json' }
86
+ )
87
+ end
88
+
89
+ it { expect { subject }.to raise_error Kintone::KintoneError }
90
+ end
71
91
  end
72
92
  end
@@ -7,23 +7,41 @@ describe Kintone::Command::FieldAcl do
7
7
  let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
8
 
9
9
  describe '#update' do
10
+ before(:each) do
11
+ stub_request(
12
+ :put,
13
+ 'https://example.cybozu.com/k/v1/field/acl.json'
14
+ )
15
+ .with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
23
+ let(:id) { 1 }
24
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
25
+
10
26
  subject { target.update(id, rights) }
11
27
 
12
- context '' do
28
+ it { expect(subject).to eq({}) }
29
+
30
+ context 'fail to request' do
13
31
  before(:each) do
14
32
  stub_request(
15
33
  :put,
16
34
  'https://example.cybozu.com/k/v1/field/acl.json'
17
35
  )
18
36
  .with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
- .to_return(body: '{}', status: 200,
20
- headers: { 'Content-type' => 'application/json' })
37
+ .to_return(
38
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
39
+ status: 500,
40
+ headers: { 'Content-Type' => 'application/json' }
41
+ )
21
42
  end
22
43
 
23
- let(:id) { 1 }
24
- let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
25
-
26
- it { expect(subject).to eq({}) }
44
+ it { expect { subject }.to raise_error Kintone::KintoneError }
27
45
  end
28
46
  end
29
47
  end
@@ -9,30 +9,42 @@ describe Kintone::Command::File do
9
9
  describe '#get' do
10
10
  before(:each) do
11
11
  stub_request(
12
- :get,
13
- 'https://example.cybozu.com/k/v1/file.json?fileKey=file-key-string'
12
+ :get,
13
+ 'https://example.cybozu.com/k/v1/file.json?fileKey=file-key-string'
14
14
  )
15
- .to_return(body: attachment, status: 200,
16
- headers: { 'Content-type' => 'image/gif' })
15
+ .to_return(body: attachment, status: 200, headers: { 'Content-type' => 'image/gif' })
17
16
  end
18
17
 
19
18
  subject { target.get(fileKey) }
20
19
 
21
- let(:attachment) do
22
- Base64.decode64('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==')
23
- end
20
+ let(:attachment) { Base64.decode64('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==') } # rubocop:disable Metrics/LineLength
24
21
  let(:fileKey) { 'file-key-string' }
25
22
 
26
23
  it { expect(subject).to eq attachment }
24
+
25
+ context 'fail to request' do
26
+ before(:each) do
27
+ stub_request(
28
+ :get,
29
+ 'https://example.cybozu.com/k/v1/file.json?fileKey=file-key-string'
30
+ )
31
+ .to_return(
32
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
33
+ status: 500,
34
+ headers: { 'Content-Type' => 'application/json' }
35
+ )
36
+ end
37
+
38
+ it { expect { subject }.to raise_error Kintone::KintoneError }
39
+ end
27
40
  end
28
41
 
29
42
  describe '#register' do
30
43
  before(:each) do
31
- expect(api).to receive(:post_file)
32
- .with(
33
- target.instance_variable_get('@url'),
34
- path, content_type, original_filename)
35
- .and_return('c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6')
44
+ expect(api)
45
+ .to receive(:post_file)
46
+ .with(target.instance_variable_get('@url'), path, content_type, original_filename)
47
+ .and_return('c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6')
36
48
  end
37
49
 
38
50
  subject { target.register(path, content_type, original_filename) }
@@ -42,5 +54,9 @@ describe Kintone::Command::File do
42
54
  let(:original_filename) { 'fileName.txt' }
43
55
 
44
56
  it { is_expected.to eq 'c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6' }
57
+
58
+ xcontext 'fail to request' do
59
+ # Should consider how to test
60
+ end
45
61
  end
46
62
  end
@@ -7,21 +7,38 @@ describe Kintone::Command::Form do
7
7
  let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
8
 
9
9
  describe '#get' do
10
+ before(:each) do
11
+ stub_request(
12
+ :get,
13
+ 'https://example.cybozu.com/k/v1/form.json?app=4'
14
+ )
15
+ .to_return(
16
+ body: '{"result":"ok"}',
17
+ status: 200,
18
+ headers: { 'Content-type' => 'application/json' }
19
+ )
20
+ end
21
+
10
22
  subject { target.get(app) }
11
23
 
12
- context '' do
24
+ let(:app) { 4 }
25
+
26
+ it { expect(subject).to eq 'result' => 'ok' }
27
+
28
+ context 'fail to request' do
13
29
  before(:each) do
14
30
  stub_request(
15
31
  :get,
16
32
  'https://example.cybozu.com/k/v1/form.json?app=4'
17
33
  )
18
- .to_return(body: "{\"result\":\"ok\"}", status: 200,
19
- headers: { 'Content-type' => 'application/json' })
34
+ .to_return(
35
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
36
+ status: 500,
37
+ headers: { 'Content-type' => 'application/json' }
38
+ )
20
39
  end
21
40
 
22
- let(:app) { 4 }
23
-
24
- it { expect(subject).to eq 'result' => 'ok' }
41
+ it { expect { subject }.to raise_error Kintone::KintoneError }
25
42
  end
26
43
  end
27
44
  end
@@ -13,8 +13,11 @@ describe Kintone::Command::Guests do
13
13
  'https://example.cybozu.com/k/v1/guests.json'
14
14
  )
15
15
  .with(body: { guests: guests }.to_json)
16
- .to_return(body: '{}', status: 200,
17
- headers: { 'Content-type' => 'application/json' })
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
18
21
  end
19
22
 
20
23
  subject { target.register(guests) }
@@ -39,6 +42,23 @@ describe Kintone::Command::Guests do
39
42
  end
40
43
 
41
44
  it { is_expected.to be_truthy }
45
+
46
+ context 'fail to request' do
47
+ before(:each) do
48
+ stub_request(
49
+ :post,
50
+ 'https://example.cybozu.com/k/v1/guests.json'
51
+ )
52
+ .with(body: { guests: guests }.to_json)
53
+ .to_return(
54
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
55
+ status: 500,
56
+ headers: { 'Content-type' => 'application/json' }
57
+ )
58
+ end
59
+
60
+ it { expect { subject }.to raise_error Kintone::KintoneError }
61
+ end
42
62
  end
43
63
 
44
64
  describe '#delete' do
@@ -48,8 +68,11 @@ describe Kintone::Command::Guests do
48
68
  'https://example.cybozu.com/k/v1/guests.json'
49
69
  )
50
70
  .with(body: { guests: guests }.to_json)
51
- .to_return(body: '{}', status: 200,
52
- headers: { 'Content-type' => 'application/json' })
71
+ .to_return(
72
+ body: '{}',
73
+ status: 200,
74
+ headers: { 'Content-type' => 'application/json' }
75
+ )
53
76
  end
54
77
 
55
78
  subject { target.delete(guests) }
@@ -63,5 +86,22 @@ describe Kintone::Command::Guests do
63
86
  end
64
87
 
65
88
  it { is_expected.to be_truthy }
89
+
90
+ context 'fail to request' do
91
+ before(:each) do
92
+ stub_request(
93
+ :delete,
94
+ 'https://example.cybozu.com/k/v1/guests.json'
95
+ )
96
+ .with(body: { guests: guests }.to_json)
97
+ .to_return(
98
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
99
+ status: 500,
100
+ headers: { 'Content-Type' => 'application/json' }
101
+ )
102
+ end
103
+
104
+ it { expect { subject }.to raise_error Kintone::KintoneError }
105
+ end
66
106
  end
67
107
  end
@@ -7,23 +7,42 @@ describe Kintone::Command::RecordAcl do
7
7
  let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
8
8
 
9
9
  describe '#update' do
10
+ before(:each) do
11
+ stub_request(
12
+ :put,
13
+ 'https://example.cybozu.com/k/v1/record/acl.json'
14
+ )
15
+ .with(body: request_body.to_json)
16
+ .to_return(
17
+ body: '{}',
18
+ status: 200,
19
+ headers: { 'Content-type' => 'application/json' }
20
+ )
21
+ end
22
+
10
23
  subject { target.update(id, rights) }
11
24
 
12
- context '' do
25
+ let(:id) { 1 }
26
+ let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
27
+ let(:request_body) { { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } } }
28
+
29
+ it { expect(subject).to eq({}) }
30
+
31
+ context 'fail to request' do
13
32
  before(:each) do
14
33
  stub_request(
15
34
  :put,
16
35
  'https://example.cybozu.com/k/v1/record/acl.json'
17
36
  )
18
- .with(body: { 'id' => 1, 'rights' => { 'p1' => 'abc', 'p2' => 'def' } }.to_json)
19
- .to_return(body: '{}', status: 200,
20
- headers: { 'Content-type' => 'application/json' })
37
+ .with(body: request_body.to_json)
38
+ .to_return(
39
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
40
+ status: 500,
41
+ headers: { 'Content-Type' => 'application/json' }
42
+ )
21
43
  end
22
44
 
23
- let(:id) { 1 }
24
- let(:rights) { { 'p1' => 'abc', 'p2' => 'def' } }
25
-
26
- it { expect(subject).to eq({}) }
45
+ it { expect { subject }.to raise_error Kintone::KintoneError }
27
46
  end
28
47
  end
29
48
  end
@@ -9,12 +9,12 @@ describe Kintone::Command::Record do
9
9
 
10
10
  describe '#get' do
11
11
  before(:each) do
12
- stub_request(
13
- :get,
14
- 'https://www.example.com/k/v1/record.json?app=8&id=100'
15
- )
16
- .to_return(body: "{\"result\":\"ok\"}", status: 200,
17
- headers: { 'Content-type' => 'application/json' })
12
+ stub_request(:get, 'https://www.example.com/k/v1/record.json?app=8&id=100')
13
+ .to_return(
14
+ body: '{"result":"ok"}',
15
+ status: 200,
16
+ headers: { 'Content-Type' => 'application/json' }
17
+ )
18
18
  end
19
19
 
20
20
  subject { target.get(app, id) }
@@ -29,6 +29,22 @@ describe Kintone::Command::Record do
29
29
  with_them do
30
30
  it { expect(subject).to eq 'result' => 'ok' }
31
31
  end
32
+
33
+ context 'fail to request' do
34
+ before(:each) do
35
+ stub_request(:get, 'https://www.example.com/k/v1/record.json?app=8&id=100')
36
+ .to_return(
37
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
38
+ status: 500,
39
+ headers: { 'Content-Type' => 'application/json' }
40
+ )
41
+ end
42
+
43
+ let(:app) { 8 }
44
+ let(:id) { 100 }
45
+
46
+ it { expect { subject }.to raise_error Kintone::KintoneError }
47
+ end
32
48
  end
33
49
 
34
50
  describe '#register' do
@@ -38,8 +54,11 @@ describe Kintone::Command::Record do
38
54
  'https://www.example.com/k/v1/record.json'
39
55
  )
40
56
  .with(body: request_body.to_json)
41
- .to_return(body: response_body.to_json, status: 200,
42
- headers: { 'Content-type' => 'application/json' })
57
+ .to_return(
58
+ body: response_body.to_json,
59
+ status: 200,
60
+ headers: { 'Content-type' => 'application/json' }
61
+ )
43
62
  end
44
63
 
45
64
  subject { target.register(app, record) }
@@ -80,6 +99,31 @@ describe Kintone::Command::Record do
80
99
 
81
100
  it { expect(subject).to eq response_body }
82
101
  end
102
+
103
+ context 'fail to request' do
104
+ before(:each) do
105
+ stub_request(
106
+ :post,
107
+ 'https://www.example.com/k/v1/record.json'
108
+ )
109
+ .with(body: request_body.to_json)
110
+ .to_return(
111
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
112
+ status: 500,
113
+ headers: { 'Content-Type' => 'application/json' }
114
+ )
115
+ end
116
+
117
+ let(:record) do
118
+ {
119
+ 'number' => { 'value' => '123456' },
120
+ 'rich_editor' => { 'value' => 'testtest' },
121
+ 'user_select' => { 'value' => [{ 'code' => 'sato' }] }
122
+ }
123
+ end
124
+
125
+ it { expect { subject }.to raise_error Kintone::KintoneError }
126
+ end
83
127
  end
84
128
 
85
129
  describe '#update' do
@@ -89,8 +133,11 @@ describe Kintone::Command::Record do
89
133
  'https://www.example.com/k/v1/record.json'
90
134
  )
91
135
  .with(body: request_body.to_json)
92
- .to_return(body: response_body.to_json, status: 200,
93
- headers: { 'Content-type' => 'application/json' })
136
+ .to_return(
137
+ body: response_body.to_json,
138
+ status: 200,
139
+ headers: { 'Content-type' => 'application/json' }
140
+ )
94
141
  end
95
142
 
96
143
  subject { target.update(app, id, record) }
@@ -135,5 +182,25 @@ describe Kintone::Command::Record do
135
182
  it { expect(subject).to match 'revision' => '2' }
136
183
  end
137
184
  end
185
+
186
+ context 'fail to request' do
187
+ before(:each) do
188
+ stub_request(
189
+ :put,
190
+ 'https://www.example.com/k/v1/record.json'
191
+ )
192
+ .with(body: request_body.to_json)
193
+ .to_return(
194
+ body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
195
+ status: 500,
196
+ headers: { 'Content-Type' => 'application/json' }
197
+ )
198
+ end
199
+
200
+ let(:request_body) { { 'app' => 4, 'id' => 1, 'record' => hash_record } }
201
+ let(:record) { hash_record }
202
+
203
+ it { expect { subject }.to raise_error Kintone::KintoneError }
204
+ end
138
205
  end
139
206
  end