kintone_rb 1.0.0
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.
- checksums.yaml +7 -0
 - data/.github/dependabot.yml +7 -0
 - data/.github/workflows/rspec.yml +28 -0
 - data/.gitignore +20 -0
 - data/.rspec +1 -0
 - data/.rubocop.yml +47 -0
 - data/.ruby-version +1 -0
 - data/CHANGELOG.md +4 -0
 - data/Gemfile +4 -0
 - data/LICENSE.txt +22 -0
 - data/README.md +361 -0
 - data/Rakefile +6 -0
 - data/kintone.gemspec +30 -0
 - data/lib/kintone/api/guest.rb +44 -0
 - data/lib/kintone/api.rb +121 -0
 - data/lib/kintone/command/accessor.rb +109 -0
 - data/lib/kintone/command/apis.rb +22 -0
 - data/lib/kintone/command/app.rb +11 -0
 - data/lib/kintone/command/app_acl.rb +11 -0
 - data/lib/kintone/command/apps.rb +12 -0
 - data/lib/kintone/command/bulk_request.rb +12 -0
 - data/lib/kintone/command/field_acl.rb +11 -0
 - data/lib/kintone/command/file.rb +15 -0
 - data/lib/kintone/command/form.rb +11 -0
 - data/lib/kintone/command/guests.rb +17 -0
 - data/lib/kintone/command/preview_form.rb +11 -0
 - data/lib/kintone/command/record.rb +23 -0
 - data/lib/kintone/command/record_acl.rb +11 -0
 - data/lib/kintone/command/records.rb +29 -0
 - data/lib/kintone/command/space.rb +15 -0
 - data/lib/kintone/command/space_body.rb +11 -0
 - 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/command/template_space.rb +12 -0
 - data/lib/kintone/command.rb +12 -0
 - data/lib/kintone/kintone_error.rb +12 -0
 - data/lib/kintone/query/extension.rb +23 -0
 - data/lib/kintone/query.rb +152 -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/type.rb +6 -0
 - data/lib/kintone/version.rb +3 -0
 - data/lib/kintone_rb.rb +7 -0
 - data/spec/kintone/api/guest_spec.rb +289 -0
 - data/spec/kintone/api_spec.rb +566 -0
 - data/spec/kintone/command/apis_spec.rb +179 -0
 - data/spec/kintone/command/app_acl_spec.rb +43 -0
 - data/spec/kintone/command/app_spec.rb +54 -0
 - data/spec/kintone/command/apps_spec.rb +90 -0
 - data/spec/kintone/command/bulk_request_spec.rb +92 -0
 - data/spec/kintone/command/field_acl_spec.rb +47 -0
 - data/spec/kintone/command/file_spec.rb +65 -0
 - data/spec/kintone/command/form_spec.rb +47 -0
 - data/spec/kintone/command/guests_spec.rb +107 -0
 - data/spec/kintone/command/preview_form_spec.rb +30 -0
 - data/spec/kintone/command/record_acl_spec.rb +48 -0
 - data/spec/kintone/command/record_spec.rb +210 -0
 - data/spec/kintone/command/records_spec.rb +463 -0
 - data/spec/kintone/command/space_body_spec.rb +47 -0
 - data/spec/kintone/command/space_guests_spec.rb +55 -0
 - data/spec/kintone/command/space_members_spec.rb +117 -0
 - data/spec/kintone/command/space_spec.rb +86 -0
 - data/spec/kintone/command/space_thread_spec.rb +77 -0
 - data/spec/kintone/command/template_space_spec.rb +59 -0
 - data/spec/kintone/kintone_error_spec.rb +93 -0
 - data/spec/kintone/query_spec.rb +506 -0
 - data/spec/kintone/type/record_spec.rb +38 -0
 - data/spec/spec_helper.rb +4 -0
 - metadata +250 -0
 
| 
         @@ -0,0 +1,463 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'kintone/command/records'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'kintone/api'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'kintone/type'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            describe Kintone::Command::Records do
         
     | 
| 
      
 7 
     | 
    
         
            +
              let(:target) { Kintone::Command::Records.new(api) }
         
     | 
| 
      
 8 
     | 
    
         
            +
              let(:api) { Kintone::Api.new('example.cybozu.com', 'Administrator', 'cybozu') }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              describe '#get' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                subject { target.get(app, query, fields) }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                let(:app) { 8 }
         
     | 
| 
      
 14 
     | 
    
         
            +
                let(:query) { '' }
         
     | 
| 
      
 15 
     | 
    
         
            +
                let(:fields) { [] }
         
     | 
| 
      
 16 
     | 
    
         
            +
                let(:request_body) { { app: app, query: query.to_s, totalCount: false, fields: fields } }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                context 'アプリIDだけ指定した時' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 20 
     | 
    
         
            +
                    {
         
     | 
| 
      
 21 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 22 
     | 
    
         
            +
                      'totalCount' => nil
         
     | 
| 
      
 23 
     | 
    
         
            +
                    }
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 28 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 29 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 30 
     | 
    
         
            +
                    )
         
     | 
| 
      
 31 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 32 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 33 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 34 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 35 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 36 
     | 
    
         
            +
                      )
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                context '条件に文字列を含むqueryを指定した時' do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 44 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 45 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 46 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 47 
     | 
    
         
            +
                    )
         
     | 
| 
      
 48 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 49 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 50 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 51 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 52 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 53 
     | 
    
         
            +
                      )
         
     | 
| 
      
 54 
     | 
    
         
            +
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  let(:query) { 'updated_time > "2012-02-03T09:00:00+0900" and updated_time < "2012-02-03T10:00:00+0900"' } # rubocop:disable Metrics/LineLength
         
     | 
| 
      
 57 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 58 
     | 
    
         
            +
                    {
         
     | 
| 
      
 59 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 60 
     | 
    
         
            +
                      'totalCount' => nil
         
     | 
| 
      
 61 
     | 
    
         
            +
                    }
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                context '項目に全角文字を含むfieldsを指定した時' do
         
     | 
| 
      
 68 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 69 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 70 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 71 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 72 
     | 
    
         
            +
                    )
         
     | 
| 
      
 73 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 74 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 75 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 76 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 77 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 78 
     | 
    
         
            +
                      )
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  let(:fields) { %w(レコード番号 created_time dropdown) }
         
     | 
| 
      
 82 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 83 
     | 
    
         
            +
                    {
         
     | 
| 
      
 84 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 85 
     | 
    
         
            +
                      'totalCount' => nil
         
     | 
| 
      
 86 
     | 
    
         
            +
                    }
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                context 'queryにnilを指定した時' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 94 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 95 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 96 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 97 
     | 
    
         
            +
                    )
         
     | 
| 
      
 98 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 99 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 100 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 101 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 102 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 103 
     | 
    
         
            +
                      )
         
     | 
| 
      
 104 
     | 
    
         
            +
                  end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                  let(:query) { nil }
         
     | 
| 
      
 107 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 108 
     | 
    
         
            +
                    {
         
     | 
| 
      
 109 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 110 
     | 
    
         
            +
                      'totalCount' => nil
         
     | 
| 
      
 111 
     | 
    
         
            +
                    }
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                context 'fieldsにnilを指定した時' do
         
     | 
| 
      
 118 
     | 
    
         
            +
                  let(:fields) { nil }
         
     | 
| 
      
 119 
     | 
    
         
            +
                  let(:request_body) { { app: app, query: query, totalCount: false } }
         
     | 
| 
      
 120 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 121 
     | 
    
         
            +
                    {
         
     | 
| 
      
 122 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 123 
     | 
    
         
            +
                      'totalCount' => nil
         
     | 
| 
      
 124 
     | 
    
         
            +
                    }
         
     | 
| 
      
 125 
     | 
    
         
            +
                  end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 128 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 129 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 130 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 131 
     | 
    
         
            +
                    )
         
     | 
| 
      
 132 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 133 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 134 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 135 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 136 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 137 
     | 
    
         
            +
                      )
         
     | 
| 
      
 138 
     | 
    
         
            +
                  end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                context 'totalCountにtrueを指定した時' do
         
     | 
| 
      
 144 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 145 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 146 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 147 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 148 
     | 
    
         
            +
                    )
         
     | 
| 
      
 149 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 150 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 151 
     | 
    
         
            +
                        body: response_data.to_json,
         
     | 
| 
      
 152 
     | 
    
         
            +
                        status: 200,
         
     | 
| 
      
 153 
     | 
    
         
            +
                        headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 154 
     | 
    
         
            +
                      )
         
     | 
| 
      
 155 
     | 
    
         
            +
                  end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                  subject { target.get(app, query, fields, total_count: total_count) }
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                  let(:request_body) { { app: app, query: query, totalCount: total_count, fields: fields } }
         
     | 
| 
      
 160 
     | 
    
         
            +
                  let(:response_data) do
         
     | 
| 
      
 161 
     | 
    
         
            +
                    {
         
     | 
| 
      
 162 
     | 
    
         
            +
                      'records' => [{ 'record_id' => { 'type' => 'RECORD_NUMBER', 'value' => '1' } }],
         
     | 
| 
      
 163 
     | 
    
         
            +
                      'totalCount' => '1'
         
     | 
| 
      
 164 
     | 
    
         
            +
                    }
         
     | 
| 
      
 165 
     | 
    
         
            +
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                  let(:total_count) { true }
         
     | 
| 
      
 168 
     | 
    
         
            +
                  it { expect(subject).to eq response_data }
         
     | 
| 
      
 169 
     | 
    
         
            +
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 172 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 173 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 174 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 175 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 176 
     | 
    
         
            +
                    )
         
     | 
| 
      
 177 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 178 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 179 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 180 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 181 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 182 
     | 
    
         
            +
                      )
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                  let(:fields) { nil }
         
     | 
| 
      
 185 
     | 
    
         
            +
                  let(:request_body) { { app: app, query: '', totalCount: false } }
         
     | 
| 
      
 186 
     | 
    
         
            +
             
     | 
| 
      
 187 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
              end
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
              describe '#register' do
         
     | 
| 
      
 192 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 193 
     | 
    
         
            +
                  stub_request(
         
     | 
| 
      
 194 
     | 
    
         
            +
                    :post,
         
     | 
| 
      
 195 
     | 
    
         
            +
                    'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 196 
     | 
    
         
            +
                  )
         
     | 
| 
      
 197 
     | 
    
         
            +
                    .with(body: request_body.to_json)
         
     | 
| 
      
 198 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 199 
     | 
    
         
            +
                      body: response_body.to_json,
         
     | 
| 
      
 200 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 201 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 202 
     | 
    
         
            +
                    )
         
     | 
| 
      
 203 
     | 
    
         
            +
                end
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
                subject { target.register(app, records) }
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                let(:app) { 7 }
         
     | 
| 
      
 208 
     | 
    
         
            +
                let(:request_body) do
         
     | 
| 
      
 209 
     | 
    
         
            +
                  {
         
     | 
| 
      
 210 
     | 
    
         
            +
                    'app' => 7,
         
     | 
| 
      
 211 
     | 
    
         
            +
                    'records' => [
         
     | 
| 
      
 212 
     | 
    
         
            +
                      { 'rich_editor' => { 'value' => 'testtest' } },
         
     | 
| 
      
 213 
     | 
    
         
            +
                      { 'user_select' => { 'value' => [{ 'code' => 'suzuki' }] } }
         
     | 
| 
      
 214 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 215 
     | 
    
         
            +
                  }
         
     | 
| 
      
 216 
     | 
    
         
            +
                end
         
     | 
| 
      
 217 
     | 
    
         
            +
                let(:response_body) { { 'ids' => ['100', '101'], 'revisions' => ['1', '1'] } }
         
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
      
 219 
     | 
    
         
            +
                context 'use hash' do
         
     | 
| 
      
 220 
     | 
    
         
            +
                  let(:records) do
         
     | 
| 
      
 221 
     | 
    
         
            +
                    [
         
     | 
| 
      
 222 
     | 
    
         
            +
                      { 'rich_editor' => { 'value' => 'testtest' } },
         
     | 
| 
      
 223 
     | 
    
         
            +
                      { 'user_select' => { 'value' => [{ 'code' => 'suzuki' }] } }
         
     | 
| 
      
 224 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 225 
     | 
    
         
            +
                  end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                  it { expect(subject).to eq response_body }
         
     | 
| 
      
 228 
     | 
    
         
            +
                end
         
     | 
| 
      
 229 
     | 
    
         
            +
             
     | 
| 
      
 230 
     | 
    
         
            +
                context 'use record' do
         
     | 
| 
      
 231 
     | 
    
         
            +
                  let(:records) do
         
     | 
| 
      
 232 
     | 
    
         
            +
                    [
         
     | 
| 
      
 233 
     | 
    
         
            +
                      Kintone::Type::Record.new(rich_editor: 'testtest'),
         
     | 
| 
      
 234 
     | 
    
         
            +
                      Kintone::Type::Record.new(user_select: [{ code: 'suzuki' }])
         
     | 
| 
      
 235 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 236 
     | 
    
         
            +
                  end
         
     | 
| 
      
 237 
     | 
    
         
            +
             
     | 
| 
      
 238 
     | 
    
         
            +
                  it { expect(subject).to eq response_body }
         
     | 
| 
      
 239 
     | 
    
         
            +
                end
         
     | 
| 
      
 240 
     | 
    
         
            +
             
     | 
| 
      
 241 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 242 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 243 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 244 
     | 
    
         
            +
                      :post,
         
     | 
| 
      
 245 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 246 
     | 
    
         
            +
                    )
         
     | 
| 
      
 247 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 248 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 249 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 250 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 251 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 252 
     | 
    
         
            +
                      )
         
     | 
| 
      
 253 
     | 
    
         
            +
                  end
         
     | 
| 
      
 254 
     | 
    
         
            +
             
     | 
| 
      
 255 
     | 
    
         
            +
                  let(:records) do
         
     | 
| 
      
 256 
     | 
    
         
            +
                    [
         
     | 
| 
      
 257 
     | 
    
         
            +
                      { 'rich_editor' => { 'value' => 'testtest' } },
         
     | 
| 
      
 258 
     | 
    
         
            +
                      { 'user_select' => { 'value' => [{ 'code' => 'suzuki' }] } }
         
     | 
| 
      
 259 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 260 
     | 
    
         
            +
                  end
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 263 
     | 
    
         
            +
                end
         
     | 
| 
      
 264 
     | 
    
         
            +
              end
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
              describe '#update' do
         
     | 
| 
      
 267 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 268 
     | 
    
         
            +
                  stub_request(
         
     | 
| 
      
 269 
     | 
    
         
            +
                    :put,
         
     | 
| 
      
 270 
     | 
    
         
            +
                    'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 271 
     | 
    
         
            +
                  )
         
     | 
| 
      
 272 
     | 
    
         
            +
                    .with(body: request_body.to_json)
         
     | 
| 
      
 273 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 274 
     | 
    
         
            +
                      body: response_body.to_json,
         
     | 
| 
      
 275 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 276 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 277 
     | 
    
         
            +
                    )
         
     | 
| 
      
 278 
     | 
    
         
            +
                end
         
     | 
| 
      
 279 
     | 
    
         
            +
             
     | 
| 
      
 280 
     | 
    
         
            +
                subject { target.update(app, records) }
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
                let(:app) { 4 }
         
     | 
| 
      
 283 
     | 
    
         
            +
                let(:response_body) do
         
     | 
| 
      
 284 
     | 
    
         
            +
                  { 'records' => [{ 'id' => '1', 'revision' => '2' }, { 'id' => '2', 'revision' => '2' }] }
         
     | 
| 
      
 285 
     | 
    
         
            +
                end
         
     | 
| 
      
 286 
     | 
    
         
            +
             
     | 
| 
      
 287 
     | 
    
         
            +
                context 'without revision' do
         
     | 
| 
      
 288 
     | 
    
         
            +
                  let(:request_body) do
         
     | 
| 
      
 289 
     | 
    
         
            +
                    {
         
     | 
| 
      
 290 
     | 
    
         
            +
                      'app' => 4,
         
     | 
| 
      
 291 
     | 
    
         
            +
                      'records' => [
         
     | 
| 
      
 292 
     | 
    
         
            +
                        { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
         
     | 
| 
      
 293 
     | 
    
         
            +
                        { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
         
     | 
| 
      
 294 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 295 
     | 
    
         
            +
                    }
         
     | 
| 
      
 296 
     | 
    
         
            +
                  end
         
     | 
| 
      
 297 
     | 
    
         
            +
             
     | 
| 
      
 298 
     | 
    
         
            +
                  context 'use hash' do
         
     | 
| 
      
 299 
     | 
    
         
            +
                    let(:records) do
         
     | 
| 
      
 300 
     | 
    
         
            +
                      [
         
     | 
| 
      
 301 
     | 
    
         
            +
                        { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
         
     | 
| 
      
 302 
     | 
    
         
            +
                        { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
         
     | 
| 
      
 303 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 304 
     | 
    
         
            +
                    end
         
     | 
| 
      
 305 
     | 
    
         
            +
             
     | 
| 
      
 306 
     | 
    
         
            +
                    it { expect(subject).to eq response_body }
         
     | 
| 
      
 307 
     | 
    
         
            +
                  end
         
     | 
| 
      
 308 
     | 
    
         
            +
             
     | 
| 
      
 309 
     | 
    
         
            +
                  context 'use record' do
         
     | 
| 
      
 310 
     | 
    
         
            +
                    let(:records) do
         
     | 
| 
      
 311 
     | 
    
         
            +
                      [
         
     | 
| 
      
 312 
     | 
    
         
            +
                        { id: 1, record: Kintone::Type::Record.new(string_1: 'abcdef') },
         
     | 
| 
      
 313 
     | 
    
         
            +
                        { id: 2, record: Kintone::Type::Record.new(string_multi: 'opqrstu') }
         
     | 
| 
      
 314 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 315 
     | 
    
         
            +
                    end
         
     | 
| 
      
 316 
     | 
    
         
            +
             
     | 
| 
      
 317 
     | 
    
         
            +
                    it { expect(subject).to eq response_body }
         
     | 
| 
      
 318 
     | 
    
         
            +
                  end
         
     | 
| 
      
 319 
     | 
    
         
            +
                end
         
     | 
| 
      
 320 
     | 
    
         
            +
             
     | 
| 
      
 321 
     | 
    
         
            +
                context 'with revision' do
         
     | 
| 
      
 322 
     | 
    
         
            +
                  let(:request_body) do
         
     | 
| 
      
 323 
     | 
    
         
            +
                    {
         
     | 
| 
      
 324 
     | 
    
         
            +
                      'app' => 4,
         
     | 
| 
      
 325 
     | 
    
         
            +
                      'records' => [
         
     | 
| 
      
 326 
     | 
    
         
            +
                        {
         
     | 
| 
      
 327 
     | 
    
         
            +
                          'id' => 1,
         
     | 
| 
      
 328 
     | 
    
         
            +
                          'revision' => 1,
         
     | 
| 
      
 329 
     | 
    
         
            +
                          'record' => { 'string_1' => { 'value' => 'abcdef' } }
         
     | 
| 
      
 330 
     | 
    
         
            +
                        },
         
     | 
| 
      
 331 
     | 
    
         
            +
                        {
         
     | 
| 
      
 332 
     | 
    
         
            +
                          'id' => 2,
         
     | 
| 
      
 333 
     | 
    
         
            +
                          'revision' => 1,
         
     | 
| 
      
 334 
     | 
    
         
            +
                          'record' => { 'string_multi' => { 'value' => 'opqrstu' } }
         
     | 
| 
      
 335 
     | 
    
         
            +
                        }
         
     | 
| 
      
 336 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 337 
     | 
    
         
            +
                    }
         
     | 
| 
      
 338 
     | 
    
         
            +
                  end
         
     | 
| 
      
 339 
     | 
    
         
            +
             
     | 
| 
      
 340 
     | 
    
         
            +
                  context 'use hash' do
         
     | 
| 
      
 341 
     | 
    
         
            +
                    let(:records) do
         
     | 
| 
      
 342 
     | 
    
         
            +
                      [
         
     | 
| 
      
 343 
     | 
    
         
            +
                        {
         
     | 
| 
      
 344 
     | 
    
         
            +
                          'id' => 1,
         
     | 
| 
      
 345 
     | 
    
         
            +
                          'revision' => 1,
         
     | 
| 
      
 346 
     | 
    
         
            +
                          'record' => { 'string_1' => { 'value' => 'abcdef' } }
         
     | 
| 
      
 347 
     | 
    
         
            +
                        },
         
     | 
| 
      
 348 
     | 
    
         
            +
                        {
         
     | 
| 
      
 349 
     | 
    
         
            +
                          'id' => 2,
         
     | 
| 
      
 350 
     | 
    
         
            +
                          'revision' => 1,
         
     | 
| 
      
 351 
     | 
    
         
            +
                          'record' => { 'string_multi' => { 'value' => 'opqrstu' } }
         
     | 
| 
      
 352 
     | 
    
         
            +
                        }
         
     | 
| 
      
 353 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 354 
     | 
    
         
            +
                    end
         
     | 
| 
      
 355 
     | 
    
         
            +
             
     | 
| 
      
 356 
     | 
    
         
            +
                    it { expect(subject).to eq response_body }
         
     | 
| 
      
 357 
     | 
    
         
            +
                  end
         
     | 
| 
      
 358 
     | 
    
         
            +
             
     | 
| 
      
 359 
     | 
    
         
            +
                  context 'use record' do
         
     | 
| 
      
 360 
     | 
    
         
            +
                    let(:records) do
         
     | 
| 
      
 361 
     | 
    
         
            +
                      [
         
     | 
| 
      
 362 
     | 
    
         
            +
                        { id: 1, revision: 1, record: Kintone::Type::Record.new(string_1: 'abcdef') },
         
     | 
| 
      
 363 
     | 
    
         
            +
                        { id: 2, revision: 1, record: Kintone::Type::Record.new(string_multi: 'opqrstu') }
         
     | 
| 
      
 364 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 365 
     | 
    
         
            +
                    end
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
                    it { expect(subject).to eq response_body }
         
     | 
| 
      
 368 
     | 
    
         
            +
                  end
         
     | 
| 
      
 369 
     | 
    
         
            +
                end
         
     | 
| 
      
 370 
     | 
    
         
            +
             
     | 
| 
      
 371 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 372 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 373 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 374 
     | 
    
         
            +
                      :put,
         
     | 
| 
      
 375 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 376 
     | 
    
         
            +
                    )
         
     | 
| 
      
 377 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 378 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 379 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 380 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 381 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 382 
     | 
    
         
            +
                      )
         
     | 
| 
      
 383 
     | 
    
         
            +
                  end
         
     | 
| 
      
 384 
     | 
    
         
            +
             
     | 
| 
      
 385 
     | 
    
         
            +
                  let(:records) do
         
     | 
| 
      
 386 
     | 
    
         
            +
                    [
         
     | 
| 
      
 387 
     | 
    
         
            +
                      { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
         
     | 
| 
      
 388 
     | 
    
         
            +
                      { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
         
     | 
| 
      
 389 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 390 
     | 
    
         
            +
                  end
         
     | 
| 
      
 391 
     | 
    
         
            +
                  let(:request_body) do
         
     | 
| 
      
 392 
     | 
    
         
            +
                    {
         
     | 
| 
      
 393 
     | 
    
         
            +
                      'app' => 4,
         
     | 
| 
      
 394 
     | 
    
         
            +
                      'records' => [
         
     | 
| 
      
 395 
     | 
    
         
            +
                        { 'id' => 1, 'record' => { 'string_1' => { 'value' => 'abcdef' } } },
         
     | 
| 
      
 396 
     | 
    
         
            +
                        { 'id' => 2, 'record' => { 'string_multi' => { 'value' => 'opqrstu' } } }
         
     | 
| 
      
 397 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 398 
     | 
    
         
            +
                    }
         
     | 
| 
      
 399 
     | 
    
         
            +
                  end
         
     | 
| 
      
 400 
     | 
    
         
            +
             
     | 
| 
      
 401 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 402 
     | 
    
         
            +
                end
         
     | 
| 
      
 403 
     | 
    
         
            +
              end
         
     | 
| 
      
 404 
     | 
    
         
            +
             
     | 
| 
      
 405 
     | 
    
         
            +
              describe '#delete' do
         
     | 
| 
      
 406 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 407 
     | 
    
         
            +
                  stub_request(
         
     | 
| 
      
 408 
     | 
    
         
            +
                    :delete,
         
     | 
| 
      
 409 
     | 
    
         
            +
                    'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 410 
     | 
    
         
            +
                  )
         
     | 
| 
      
 411 
     | 
    
         
            +
                    .with(body: request_body.to_json)
         
     | 
| 
      
 412 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 413 
     | 
    
         
            +
                      body: '{}',
         
     | 
| 
      
 414 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 415 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 416 
     | 
    
         
            +
                    )
         
     | 
| 
      
 417 
     | 
    
         
            +
                end
         
     | 
| 
      
 418 
     | 
    
         
            +
             
     | 
| 
      
 419 
     | 
    
         
            +
                context 'without revisions' do
         
     | 
| 
      
 420 
     | 
    
         
            +
                  subject { target.delete(app, ids) }
         
     | 
| 
      
 421 
     | 
    
         
            +
             
     | 
| 
      
 422 
     | 
    
         
            +
                  let(:app) { 1 }
         
     | 
| 
      
 423 
     | 
    
         
            +
                  let(:ids) { [100, 80] }
         
     | 
| 
      
 424 
     | 
    
         
            +
                  let(:request_body) { { app: app, ids: ids } }
         
     | 
| 
      
 425 
     | 
    
         
            +
             
     | 
| 
      
 426 
     | 
    
         
            +
                  it { expect(subject).to eq({}) }
         
     | 
| 
      
 427 
     | 
    
         
            +
                end
         
     | 
| 
      
 428 
     | 
    
         
            +
             
     | 
| 
      
 429 
     | 
    
         
            +
                context 'with revisions' do
         
     | 
| 
      
 430 
     | 
    
         
            +
                  subject { target.delete(app, ids, revisions: revisions) }
         
     | 
| 
      
 431 
     | 
    
         
            +
             
     | 
| 
      
 432 
     | 
    
         
            +
                  let(:app) { 1 }
         
     | 
| 
      
 433 
     | 
    
         
            +
                  let(:ids) { [100, 80] }
         
     | 
| 
      
 434 
     | 
    
         
            +
                  let(:revisions) { [1, 4] }
         
     | 
| 
      
 435 
     | 
    
         
            +
                  let(:request_body) { { app: app, ids: ids, revisions: revisions } }
         
     | 
| 
      
 436 
     | 
    
         
            +
             
     | 
| 
      
 437 
     | 
    
         
            +
                  it { expect(subject).to eq({}) }
         
     | 
| 
      
 438 
     | 
    
         
            +
                end
         
     | 
| 
      
 439 
     | 
    
         
            +
             
     | 
| 
      
 440 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 441 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 442 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 443 
     | 
    
         
            +
                      :delete,
         
     | 
| 
      
 444 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/records.json'
         
     | 
| 
      
 445 
     | 
    
         
            +
                    )
         
     | 
| 
      
 446 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 447 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 448 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 449 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 450 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 451 
     | 
    
         
            +
                      )
         
     | 
| 
      
 452 
     | 
    
         
            +
                  end
         
     | 
| 
      
 453 
     | 
    
         
            +
             
     | 
| 
      
 454 
     | 
    
         
            +
                  subject { target.delete(app, ids) }
         
     | 
| 
      
 455 
     | 
    
         
            +
             
     | 
| 
      
 456 
     | 
    
         
            +
                  let(:app) { 1 }
         
     | 
| 
      
 457 
     | 
    
         
            +
                  let(:ids) { [100, 80] }
         
     | 
| 
      
 458 
     | 
    
         
            +
                  let(:request_body) { { app: app, ids: ids } }
         
     | 
| 
      
 459 
     | 
    
         
            +
             
     | 
| 
      
 460 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 461 
     | 
    
         
            +
                end
         
     | 
| 
      
 462 
     | 
    
         
            +
              end
         
     | 
| 
      
 463 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'kintone/command/space_body'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'kintone/api'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Kintone::Command::SpaceBody do
         
     | 
| 
      
 6 
     | 
    
         
            +
              let(:target) { Kintone::Command::SpaceBody.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/body.json'
         
     | 
| 
      
 14 
     | 
    
         
            +
                  )
         
     | 
| 
      
 15 
     | 
    
         
            +
                    .with(body: { id: 1, body: '<b>総務課</b>専用のスペースです。' }.to_json)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 17 
     | 
    
         
            +
                      body: '{}',
         
     | 
| 
      
 18 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 19 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 20 
     | 
    
         
            +
                    )
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                subject { target.update(id, body) }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                let(:id) { 1 }
         
     | 
| 
      
 26 
     | 
    
         
            +
                let(:body) { '<b>総務課</b>専用のスペースです。' }
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                it { expect(subject).to eq({}) }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 32 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 33 
     | 
    
         
            +
                      :put,
         
     | 
| 
      
 34 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/space/body.json'
         
     | 
| 
      
 35 
     | 
    
         
            +
                    )
         
     | 
| 
      
 36 
     | 
    
         
            +
                      .with(body: { id: 1, body: '<b>総務課</b>専用のスペースです。' }.to_json)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 38 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 39 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 40 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 41 
     | 
    
         
            +
                      )
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 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(
         
     | 
| 
      
 19 
     | 
    
         
            +
                      body: '{}',
         
     | 
| 
      
 20 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 21 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 22 
     | 
    
         
            +
                    )
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                subject { target.update(id, guests) }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                let(:id) { 10 }
         
     | 
| 
      
 28 
     | 
    
         
            +
                let(:guests) do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  [
         
     | 
| 
      
 30 
     | 
    
         
            +
                    'guest1@example.com',
         
     | 
| 
      
 31 
     | 
    
         
            +
                    'guest2@example.com',
         
     | 
| 
      
 32 
     | 
    
         
            +
                    'guest3@example.com'
         
     | 
| 
      
 33 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                it { is_expected.to be_truthy }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 40 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 41 
     | 
    
         
            +
                      :put,
         
     | 
| 
      
 42 
     | 
    
         
            +
                      'https://example.cybozu.com/k/guest/1/v1/space/guests.json'
         
     | 
| 
      
 43 
     | 
    
         
            +
                    )
         
     | 
| 
      
 44 
     | 
    
         
            +
                      .with(body: { id: id, guests: guests }.to_json)
         
     | 
| 
      
 45 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 46 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 47 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 48 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 49 
     | 
    
         
            +
                      )
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,117 @@ 
     | 
|
| 
      
 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(body: request_body.to_json)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 17 
     | 
    
         
            +
                      body: response_data.to_json,
         
     | 
| 
      
 18 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 19 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 20 
     | 
    
         
            +
                    )
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                subject { target.get(id) }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                let(:id) { 1 }
         
     | 
| 
      
 26 
     | 
    
         
            +
                let(:request_body) { { id: id } }
         
     | 
| 
      
 27 
     | 
    
         
            +
                let(:response_data) { { 'members' => members } }
         
     | 
| 
      
 28 
     | 
    
         
            +
                let(:members) do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  [
         
     | 
| 
      
 30 
     | 
    
         
            +
                    {
         
     | 
| 
      
 31 
     | 
    
         
            +
                      'entity' => { 'type' => 'USER', 'code' => 'user1' },
         
     | 
| 
      
 32 
     | 
    
         
            +
                      'isAdmin' => false,
         
     | 
| 
      
 33 
     | 
    
         
            +
                      'isImplicit' => true
         
     | 
| 
      
 34 
     | 
    
         
            +
                    }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                it { expect(subject).to match members }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 42 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 43 
     | 
    
         
            +
                      :get,
         
     | 
| 
      
 44 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/space/members.json'
         
     | 
| 
      
 45 
     | 
    
         
            +
                    )
         
     | 
| 
      
 46 
     | 
    
         
            +
                      .with(body: request_body.to_json)
         
     | 
| 
      
 47 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 48 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 49 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 51 
     | 
    
         
            +
                      )
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
              describe '#update' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 60 
     | 
    
         
            +
                  stub_request(
         
     | 
| 
      
 61 
     | 
    
         
            +
                    :put,
         
     | 
| 
      
 62 
     | 
    
         
            +
                    'https://example.cybozu.com/k/v1/space/members.json'
         
     | 
| 
      
 63 
     | 
    
         
            +
                  )
         
     | 
| 
      
 64 
     | 
    
         
            +
                    .with(body: request_data.to_json)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    .to_return(
         
     | 
| 
      
 66 
     | 
    
         
            +
                      body: '{}',
         
     | 
| 
      
 67 
     | 
    
         
            +
                      status: 200,
         
     | 
| 
      
 68 
     | 
    
         
            +
                      headers: { 'Content-type' => 'application/json' }
         
     | 
| 
      
 69 
     | 
    
         
            +
                    )
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                subject { target.update(id, members) }
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                let(:id) { 1 }
         
     | 
| 
      
 75 
     | 
    
         
            +
                let(:members) do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  [
         
     | 
| 
      
 77 
     | 
    
         
            +
                    {
         
     | 
| 
      
 78 
     | 
    
         
            +
                      'entity' => { 'type' => 'USER', 'code' => 'user1' },
         
     | 
| 
      
 79 
     | 
    
         
            +
                      'isAdmin' => false,
         
     | 
| 
      
 80 
     | 
    
         
            +
                      'isImplicit' => true
         
     | 
| 
      
 81 
     | 
    
         
            +
                    }
         
     | 
| 
      
 82 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                let(:request_data) do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  {
         
     | 
| 
      
 87 
     | 
    
         
            +
                    'id' => 1,
         
     | 
| 
      
 88 
     | 
    
         
            +
                    'members' => [
         
     | 
| 
      
 89 
     | 
    
         
            +
                      {
         
     | 
| 
      
 90 
     | 
    
         
            +
                        'entity' => { 'type' => 'USER', 'code' => 'user1' },
         
     | 
| 
      
 91 
     | 
    
         
            +
                        'isAdmin' => false,
         
     | 
| 
      
 92 
     | 
    
         
            +
                        'isImplicit' => true
         
     | 
| 
      
 93 
     | 
    
         
            +
                      }
         
     | 
| 
      
 94 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 95 
     | 
    
         
            +
                  }
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                it { expect(subject).to be_truthy }
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                context 'fail to request' do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  before(:each) do
         
     | 
| 
      
 102 
     | 
    
         
            +
                    stub_request(
         
     | 
| 
      
 103 
     | 
    
         
            +
                      :put,
         
     | 
| 
      
 104 
     | 
    
         
            +
                      'https://example.cybozu.com/k/v1/space/members.json'
         
     | 
| 
      
 105 
     | 
    
         
            +
                    )
         
     | 
| 
      
 106 
     | 
    
         
            +
                      .with(body: request_data.to_json)
         
     | 
| 
      
 107 
     | 
    
         
            +
                      .to_return(
         
     | 
| 
      
 108 
     | 
    
         
            +
                        body: '{"message":"不正なJSON文字列です。","id":"1505999166-897850006","code":"CB_IJ01"}',
         
     | 
| 
      
 109 
     | 
    
         
            +
                        status: 500,
         
     | 
| 
      
 110 
     | 
    
         
            +
                        headers: { 'Content-Type' => 'application/json' }
         
     | 
| 
      
 111 
     | 
    
         
            +
                      )
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  it { expect { subject }.to raise_error Kintone::KintoneError }
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
              end
         
     | 
| 
      
 117 
     | 
    
         
            +
            end
         
     |