groupdocs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +3 -0
  3. data/README.md +141 -0
  4. data/Rakefile +9 -0
  5. data/groupdocs.gemspec +28 -0
  6. data/lib/groupdocs.rb +53 -0
  7. data/lib/groupdocs/api.rb +3 -0
  8. data/lib/groupdocs/api/entity.rb +113 -0
  9. data/lib/groupdocs/api/helpers.rb +5 -0
  10. data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
  11. data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
  12. data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
  13. data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
  14. data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
  15. data/lib/groupdocs/api/request.rb +73 -0
  16. data/lib/groupdocs/api/sugar/lookup.rb +48 -0
  17. data/lib/groupdocs/datasource.rb +162 -0
  18. data/lib/groupdocs/datasource/field.rb +44 -0
  19. data/lib/groupdocs/document.rb +513 -0
  20. data/lib/groupdocs/document/annotation.rb +215 -0
  21. data/lib/groupdocs/document/annotation/reply.rb +167 -0
  22. data/lib/groupdocs/document/change.rb +35 -0
  23. data/lib/groupdocs/document/field.rb +27 -0
  24. data/lib/groupdocs/document/metadata.rb +26 -0
  25. data/lib/groupdocs/document/rectangle.rb +24 -0
  26. data/lib/groupdocs/document/view.rb +36 -0
  27. data/lib/groupdocs/errors.rb +10 -0
  28. data/lib/groupdocs/job.rb +201 -0
  29. data/lib/groupdocs/questionnaire.rb +221 -0
  30. data/lib/groupdocs/questionnaire/execution.rb +120 -0
  31. data/lib/groupdocs/questionnaire/page.rb +43 -0
  32. data/lib/groupdocs/questionnaire/question.rb +75 -0
  33. data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
  34. data/lib/groupdocs/storage.rb +37 -0
  35. data/lib/groupdocs/storage/file.rb +248 -0
  36. data/lib/groupdocs/storage/folder.rb +314 -0
  37. data/lib/groupdocs/storage/package.rb +42 -0
  38. data/lib/groupdocs/user.rb +50 -0
  39. data/lib/groupdocs/version.rb +3 -0
  40. data/spec/groupdocs/api/entity_spec.rb +54 -0
  41. data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
  42. data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
  43. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
  44. data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
  45. data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
  46. data/spec/groupdocs/api/request_spec.rb +85 -0
  47. data/spec/groupdocs/datasource/field_spec.rb +50 -0
  48. data/spec/groupdocs/datasource_spec.rb +156 -0
  49. data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
  50. data/spec/groupdocs/document/annotation_spec.rb +226 -0
  51. data/spec/groupdocs/document/change_spec.rb +35 -0
  52. data/spec/groupdocs/document/field_spec.rb +31 -0
  53. data/spec/groupdocs/document/metadata_spec.rb +26 -0
  54. data/spec/groupdocs/document/rectangle_spec.rb +34 -0
  55. data/spec/groupdocs/document/view_spec.rb +36 -0
  56. data/spec/groupdocs/document_spec.rb +509 -0
  57. data/spec/groupdocs/errors_spec.rb +7 -0
  58. data/spec/groupdocs/job_spec.rb +196 -0
  59. data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
  60. data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
  61. data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
  62. data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
  63. data/spec/groupdocs/questionnaire_spec.rb +217 -0
  64. data/spec/groupdocs/storage/file_spec.rb +242 -0
  65. data/spec/groupdocs/storage/folder_spec.rb +310 -0
  66. data/spec/groupdocs/storage/package_spec.rb +41 -0
  67. data/spec/groupdocs/storage_spec.rb +27 -0
  68. data/spec/groupdocs/user_spec.rb +53 -0
  69. data/spec/groupdocs_spec.rb +56 -0
  70. data/spec/spec_helper.rb +46 -0
  71. data/spec/support/files/resume.pdf +0 -0
  72. data/spec/support/json/annotation_collaborators_set.json +16 -0
  73. data/spec/support/json/annotation_create.json +12 -0
  74. data/spec/support/json/annotation_list.json +32 -0
  75. data/spec/support/json/annotation_remove.json +9 -0
  76. data/spec/support/json/annotation_replies_create.json +9 -0
  77. data/spec/support/json/annotation_replies_get.json +25 -0
  78. data/spec/support/json/comparison_changes.json +46 -0
  79. data/spec/support/json/comparison_compare.json +8 -0
  80. data/spec/support/json/comparison_document.json +10 -0
  81. data/spec/support/json/datasource_add.json +8 -0
  82. data/spec/support/json/datasource_get.json +22 -0
  83. data/spec/support/json/datasource_remove.json +8 -0
  84. data/spec/support/json/datasource_update.json +8 -0
  85. data/spec/support/json/document_access_info_get.json +14 -0
  86. data/spec/support/json/document_convert.json +8 -0
  87. data/spec/support/json/document_datasource.json +10 -0
  88. data/spec/support/json/document_fields.json +34 -0
  89. data/spec/support/json/document_formats.json +8 -0
  90. data/spec/support/json/document_metadata.json +15 -0
  91. data/spec/support/json/document_questionnaire_create.json +9 -0
  92. data/spec/support/json/document_questionnaires.json +23 -0
  93. data/spec/support/json/document_sharers_remove.json +8 -0
  94. data/spec/support/json/document_sharers_set.json +16 -0
  95. data/spec/support/json/document_views.json +32 -0
  96. data/spec/support/json/file_compress.json +8 -0
  97. data/spec/support/json/file_copy.json +14 -0
  98. data/spec/support/json/file_delete.json +5 -0
  99. data/spec/support/json/file_move.json +14 -0
  100. data/spec/support/json/file_upload.json +8 -0
  101. data/spec/support/json/folder_create.json +8 -0
  102. data/spec/support/json/folder_delete.json +5 -0
  103. data/spec/support/json/folder_list.json +21 -0
  104. data/spec/support/json/folder_move.json +8 -0
  105. data/spec/support/json/folder_sharers_get.json +16 -0
  106. data/spec/support/json/folder_sharers_remove.json +8 -0
  107. data/spec/support/json/folder_sharers_set.json +16 -0
  108. data/spec/support/json/job_add_url.json +8 -0
  109. data/spec/support/json/job_create.json +8 -0
  110. data/spec/support/json/job_documents.json +39 -0
  111. data/spec/support/json/job_file_add.json +8 -0
  112. data/spec/support/json/job_update.json +7 -0
  113. data/spec/support/json/jobs_get.json +52 -0
  114. data/spec/support/json/package_create.json +7 -0
  115. data/spec/support/json/questionnaire_create.json +8 -0
  116. data/spec/support/json/questionnaire_datasources.json +26 -0
  117. data/spec/support/json/questionnaire_execution_create.json +9 -0
  118. data/spec/support/json/questionnaire_execution_status_set.json +8 -0
  119. data/spec/support/json/questionnaire_execution_update.json +8 -0
  120. data/spec/support/json/questionnaire_executions.json +24 -0
  121. data/spec/support/json/questionnaire_get.json +14 -0
  122. data/spec/support/json/questionnaire_remove.json +8 -0
  123. data/spec/support/json/questionnaire_update.json +8 -0
  124. data/spec/support/json/questionnaires_get.json +22 -0
  125. data/spec/support/json/storage_info.json +10 -0
  126. data/spec/support/shared_examples/api/entity.rb +37 -0
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
  128. data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
  129. metadata +356 -0
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Api::Helpers::Access do
4
+
5
+ subject do
6
+ GroupDocs::Api::Request.new(method: :GET)
7
+ end
8
+
9
+ describe 'MODES' do
10
+ it 'contains hash of access modes' do
11
+ described_class::MODES.should == {
12
+ private: 0,
13
+ restricted: 1,
14
+ public: 2,
15
+ }
16
+ end
17
+ end
18
+
19
+ describe '#client_id' do
20
+ it 'returns passed to method client ID' do
21
+ subject.options[:access] = { client_id: 'method_client_id' }
22
+ subject.options[:access].should_receive(:[]).with(:client_id).and_return('method_client_id')
23
+ subject.send(:client_id).should == 'method_client_id'
24
+ end
25
+
26
+ it 'returns GroupDocs.client_id if access has not been passed to method' do
27
+ subject.options[:access] = {}
28
+ GroupDocs.should_receive(:client_id).and_return('static_client_id')
29
+ subject.send(:client_id).should == 'static_client_id'
30
+ end
31
+
32
+ it 'raises error if client ID has not been set' do
33
+ subject.options[:access] = {}
34
+ GroupDocs.client_id = nil
35
+ -> { subject.send(:client_id) }.should raise_error(GroupDocs::Errors::NoClientIdError)
36
+ end
37
+ end
38
+
39
+ describe '#private_key' do
40
+ it 'returns passed to method private key' do
41
+ subject.options[:access] = { private_key: 'method_private_key' }
42
+ subject.options[:access].should_receive(:[]).with(:private_key).and_return('method_private_key')
43
+ subject.send(:private_key).should == 'method_private_key'
44
+ end
45
+
46
+ it 'returns GroupDocs.private_key if access has not been passed to method' do
47
+ subject.options[:access] = {}
48
+ GroupDocs.should_receive(:private_key).and_return('static_private_key')
49
+ subject.send(:private_key).should == 'static_private_key'
50
+ end
51
+
52
+ it 'raises error if private key has not been set' do
53
+ subject.options[:access] = {}
54
+ GroupDocs.private_key = nil
55
+ -> { subject.send(:private_key) }.should raise_error(GroupDocs::Errors::NoPrivateKeyError)
56
+ end
57
+ end
58
+
59
+ describe '#parse_access_mode' do
60
+ it 'raise error if mode is unknown' do
61
+ -> { subject.send(:parse_access_mode, 3) }.should raise_error(ArgumentError)
62
+ -> { subject.send(:parse_access_mode, :unknown) }.should raise_error(ArgumentError)
63
+ end
64
+
65
+ it 'returns :private if passed mode is 0' do
66
+ subject.send(:parse_access_mode, 0).should == :private
67
+ end
68
+
69
+ it 'returns :restricted if passed mode is 1' do
70
+ subject.send(:parse_access_mode, 1).should == :restricted
71
+ end
72
+
73
+ it 'returns :public if passed mode is 2' do
74
+ subject.send(:parse_access_mode, 2).should == :public
75
+ end
76
+
77
+ it 'returns 0 if passed mode is :private' do
78
+ subject.send(:parse_access_mode, :private).should == 0
79
+ end
80
+
81
+ it 'returns 1 if passed mode is :restricted' do
82
+ subject.send(:parse_access_mode, :restricted).should == 1
83
+ end
84
+
85
+ it 'returns 2 if passed mode is :public' do
86
+ subject.send(:parse_access_mode, :public).should == 2
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Api::Helpers::Actions do
4
+
5
+ subject do
6
+ Object.extend(described_class)
7
+ end
8
+
9
+ describe 'ACTIONS' do
10
+ it 'contains hash of actions' do
11
+ described_class::ACTIONS.should == {
12
+ none: 0,
13
+ convert: 1,
14
+ combine: 2,
15
+ compress_zip: 4,
16
+ compress_rar: 8,
17
+ trace: 16,
18
+ convert_body: 32,
19
+ bind_data: 64,
20
+ print: 128,
21
+ import_annotations: 256,
22
+ }
23
+ end
24
+ end
25
+
26
+ describe '.convert_actions' do
27
+ it 'raises error if actions is not an array' do
28
+ -> { subject.convert_actions(:convert) }.should raise_error(ArgumentError)
29
+ end
30
+
31
+ it 'raises error if action is unknown' do
32
+ -> { subject.convert_actions(%w(unknown)) }.should raise_error(ArgumentError)
33
+ end
34
+
35
+ it 'converts each action to Symbol' do
36
+ actions = %w(none convert)
37
+ actions.each do |action|
38
+ symbol = action.to_sym
39
+ action.should_receive(:to_sym).and_return(symbol)
40
+ end
41
+ subject.convert_actions(actions)
42
+ end
43
+
44
+ it 'returns correct byte flag' do
45
+ actions = %w(none convert combine compress_zip compress_rar trace convert_body bind_data print import_annotations)
46
+ flag = subject.convert_actions(actions)
47
+ flag.should be_an(Integer)
48
+ flag.should == 511
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Api::Helpers::REST do
4
+
5
+ subject do
6
+ GroupDocs::Api::Request.new(method: :GET)
7
+ end
8
+
9
+ describe 'DEFAULT_HEADERS' do
10
+ subject { described_class::DEFAULT_HEADERS }
11
+
12
+ it 'includes "Accept: application/json"' do
13
+ subject.should include(accept: 'application/json')
14
+ end
15
+
16
+ it 'includes "Content-length: 0"' do
17
+ subject.should include(content_length: 0)
18
+ end
19
+ end
20
+
21
+ describe '#prepare_request' do
22
+ it 'merges default headers with passed' do
23
+ subject.options[:headers] = { keep_alive: 300 }
24
+ merged_headers = described_class::DEFAULT_HEADERS.merge(keep_alive: 300)
25
+ lambda do
26
+ subject.send(:prepare_request)
27
+ end.should change { subject.options[:headers] }.to(merged_headers)
28
+ end
29
+
30
+ it 'uses default headers when not passed' do
31
+ lambda do
32
+ subject.send(:prepare_request)
33
+ end.should change { subject.options[:headers] }.to(described_class::DEFAULT_HEADERS)
34
+ end
35
+
36
+ it 'downcases HTTP method' do
37
+ lambda do
38
+ subject.send(:prepare_request)
39
+ end.should change { subject.options[:method] }.to(:get)
40
+ end
41
+
42
+ it 'coverts request body to JSON' do
43
+ subject.options[:method] = :POST
44
+ subject.options[:request_body] = { body: 'test' }
45
+ lambda do
46
+ subject.send(:prepare_request)
47
+ end.should change { subject.options[:request_body] }.to('{"body":"test"}')
48
+ end
49
+
50
+ it 'does not convert request body to JSON if payload is file' do
51
+ file = Object::File.new(__FILE__, 'rb')
52
+ subject.options[:method] = :POST
53
+ subject.options[:request_body] = file
54
+ subject.send(:prepare_request)
55
+ subject.options[:request_body].should == file
56
+ end
57
+
58
+ it 'calculates and sets Content-length' do
59
+ subject.options[:method] = :POST
60
+ subject.options[:headers] = {}
61
+ subject.options[:request_body] = { body: 'test' }
62
+ lambda do
63
+ subject.send(:prepare_request)
64
+ end.should change { subject.options[:headers][:content_length] }.to(15)
65
+ end
66
+
67
+ it 'sets Content-Type header if necessary' do
68
+ subject.options[:method] = :POST
69
+ subject.options[:headers] = {}
70
+ subject.options[:request_body] = { body: 'test' }
71
+ lambda do
72
+ subject.send(:prepare_request)
73
+ end.should change { subject.options[:headers][:content_type] }.to('application/json')
74
+ end
75
+ end
76
+
77
+ describe '#send_request' do
78
+ %w(GET DOWNLOAD POST PUT DELETE).each do |method|
79
+ it "sends HTTP #{method} request" do
80
+ mock_api_server('{"status": "Ok"}')
81
+ method = method.downcase.to_sym
82
+ subject.options[:method] = method
83
+ subject.options[:path] = '/folders'
84
+ subject.options[:headers] = {}
85
+ subject.send(:send_request)
86
+ end
87
+ end
88
+
89
+ it 'raises error if incorrect method has been passed' do
90
+ subject.options[:method] = :TEST
91
+ -> { subject.send(:send_request) }.should raise_error(GroupDocs::Errors::UnsupportedMethodError)
92
+ end
93
+
94
+ it 'saves response' do
95
+ mock_api_server('{"status": "Ok"}')
96
+ subject.options[:method] = :get
97
+ subject.options[:path] = '/folders'
98
+ subject.options[:headers] = {}
99
+ lambda do
100
+ subject.send(:send_request)
101
+ end.should change(subject, :response).to('{"status": "Ok"}')
102
+ end
103
+ end
104
+
105
+ describe '#parse_response' do
106
+ it 'does not parse body if request method was DOWNLOAD' do
107
+ subject.options[:method] = :download
108
+ JSON.should_not_receive(:parse)
109
+ lambda do
110
+ subject.send(:parse_response)
111
+ end.should_not change(subject, :response)
112
+ end
113
+
114
+ it 'returns JSON result key value' do
115
+ mock_response('{"status": "Ok", "result": { "entities": [] }}')
116
+ parsed_json = { status: 'Ok', result: { entities: [] } }
117
+ JSON.should_receive(:parse).with(subject.response, symbolize_names: true).and_return(parsed_json)
118
+ subject.send(:parse_response).should == { entities: [] }
119
+ end
120
+
121
+ it 'raises error if response status is not "Ok"' do
122
+ unparsed_json = '{"status": "Failed", "error_message": "The source path is not found."}'
123
+ parsed_json = { status: "Failed", error_message: "The source path is not found." }
124
+ mock_response(unparsed_json)
125
+ subject.should_receive(:raise_bad_request_error).with(parsed_json)
126
+ subject.send(:parse_response)
127
+ end
128
+ end
129
+
130
+ describe '#raise_bad_request_error' do
131
+ let(:json) do
132
+ { status: 'Failed', error_message: 'The source path is not found.' }
133
+ end
134
+
135
+ it 'raises error' do
136
+ lambda do
137
+ subject.send(:raise_bad_request_error, json)
138
+ end.should raise_error(GroupDocs::Errors::BadResponseError)
139
+ end
140
+
141
+ it 'shows "Bad response!" message' do
142
+ lambda do
143
+ subject.send(:raise_bad_request_error, json)
144
+ end.should raise_error(message = /Bad response!/)
145
+ end
146
+
147
+ it 'contains information about request method' do
148
+ subject.options[:method] = :get
149
+ lambda do
150
+ subject.send(:raise_bad_request_error, json)
151
+ end.should raise_error(message = /Request method: GET/)
152
+ end
153
+
154
+ it 'contains information about request URL' do
155
+ subject.options[:path] = '/folders'
156
+ lambda do
157
+ subject.send(:raise_bad_request_error, json)
158
+ end.should raise_error(message = %r(Request URL: https?://(.+)/folders))
159
+ end
160
+
161
+ it 'contains information about request body' do
162
+ subject.options[:request_body] = '{"test": 123}'
163
+ lambda do
164
+ subject.send(:raise_bad_request_error, json)
165
+ end.should raise_error(message = /Request body: {"test": 123}/)
166
+ end
167
+
168
+ it 'contains information about response status' do
169
+ lambda do
170
+ subject.send(:raise_bad_request_error, json)
171
+ end.should raise_error(message = /Status: Failed/)
172
+ end
173
+
174
+ it 'contains information about error message' do
175
+ lambda do
176
+ subject.send(:raise_bad_request_error, json)
177
+ end.should raise_error(message = /Error message: The source path is not found./)
178
+ end
179
+
180
+ it 'contains information about response body' do
181
+ mock_response('{"status": "Failed", "error_message": "The source path is not found."}')
182
+ lambda do
183
+ subject.send(:raise_bad_request_error, json)
184
+ end.should raise_error(message = /Response body: {"status": "Failed", "error_message": "The source path is not found."}/)
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Api::Helpers::Status do
4
+
5
+ subject do
6
+ Object.extend(described_class)
7
+ end
8
+
9
+ describe 'STATUSES' do
10
+ it 'contains hash of entity statuses' do
11
+ described_class::STATUSES.should == {
12
+ draft: -1,
13
+ pending: 0,
14
+ scheduled: 1,
15
+ in_progress: 2,
16
+ completed: 3,
17
+ postponed: 4,
18
+ archived: 5,
19
+ }
20
+ end
21
+ end
22
+
23
+ describe '#parse_status' do
24
+ it 'raise error if status is unknown' do
25
+ -> { subject.send(:parse_status, 8) }.should raise_error(ArgumentError)
26
+ -> { subject.send(:parse_status, :unknown) }.should raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'returns :draft if passed status is -1' do
30
+ subject.send(:parse_status, -1).should == :draft
31
+ end
32
+
33
+ it 'returns :pending if passed status is 0' do
34
+ subject.send(:parse_status, 0).should == :pending
35
+ end
36
+
37
+ it 'returns :scheduled if passed status is 1' do
38
+ subject.send(:parse_status, 1).should == :scheduled
39
+ end
40
+
41
+ it 'returns :in_progress if passed status is 2' do
42
+ subject.send(:parse_status, 2).should == :in_progress
43
+ end
44
+
45
+ it 'returns :completed if passed status is 3' do
46
+ subject.send(:parse_status, 3).should == :completed
47
+ end
48
+
49
+ it 'returns :postponed if passed status is 4' do
50
+ subject.send(:parse_status, 4).should == :postponed
51
+ end
52
+
53
+ it 'returns :archived if passed status is 5' do
54
+ subject.send(:parse_status, 5).should == :archived
55
+ end
56
+
57
+ it 'returns -1 if passed status is :draft' do
58
+ subject.send(:parse_status, :draft).should == -1
59
+ end
60
+
61
+ it 'returns 0 if passed status is :pending' do
62
+ subject.send(:parse_status, :pending).should == 0
63
+ end
64
+
65
+ it 'returns 1 if passed status is :scheduled' do
66
+ subject.send(:parse_status, :scheduled).should == 1
67
+ end
68
+
69
+ it 'returns 2 if passed status is :in_progress' do
70
+ subject.send(:parse_status, :in_progress).should == 2
71
+ end
72
+
73
+ it 'returns 3 if passed status is :completed' do
74
+ subject.send(:parse_status, :completed).should == 3
75
+ end
76
+
77
+ it 'returns 4 if passed status is :postponed' do
78
+ subject.send(:parse_status, :postponed).should == 4
79
+ end
80
+
81
+ it 'returns 5 if passed status is :archived' do
82
+ subject.send(:parse_status, :archived).should == 5
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Api::Helpers::URL do
4
+
5
+ subject do
6
+ GroupDocs::Api::Request.new(path: '/1/files/2?new_name=invoice.docx')
7
+ end
8
+
9
+ describe '#add_params' do
10
+ it 'adds parameters to query' do
11
+ subject.options[:path].should_receive(:<<).with('&param=value')
12
+ subject.add_params({ param: 'value' })
13
+ end
14
+
15
+ it 'joins values with comma if it is array' do
16
+ subject.options[:path] = '/1/files/2'
17
+ value = [1, 2]
18
+ value.should_receive(:join).with(?,).and_return('1,2')
19
+ subject.add_params({ param: value })
20
+ end
21
+
22
+ it 'determines correct URL separator' do
23
+ subject.options[:path] = '/1/files/2'
24
+ subject.should_receive(:separator)
25
+ subject.add_params({ param: 'value' })
26
+ end
27
+ end
28
+
29
+ describe '#parse_path' do
30
+ it 'replaces {{client_id}} with real client ID' do
31
+ subject.options[:path] = '/doc/{{client_id}}/files/123'
32
+ subject.should_receive(:client_id).and_return('real_client_id')
33
+ lambda do
34
+ subject.send(:parse_path)
35
+ end.should change { subject.options[:path] }.to('/doc/real_client_id/files/123')
36
+ end
37
+ end
38
+
39
+ describe '#url_encode_path' do
40
+ it 'URL encodes path' do
41
+ subject.options[:path] = '/folder/Test 123'
42
+ subject.options.should_receive(:[]=).with(:path, '/folder/Test%20123')
43
+ subject.send(:url_encode_path)
44
+ end
45
+ end
46
+
47
+ describe '#sign_url' do
48
+ it 'uses defined private key' do
49
+ subject.should_receive(:private_key).and_return('e98ea443354183fd1fb434047232c687')
50
+ subject.send(:sign_url)
51
+ end
52
+
53
+ it 'adds signature to path' do
54
+ subject.options[:access] = { private_key: 'e98ea443354183fd1fb434047232c687' }
55
+ GroupDocs.stub(api_version: nil)
56
+ subject.send(:sign_url)
57
+ subject.options[:path].should == '/1/files/2?new_name=invoice.docx&signature=gw%2BLupOB3krtliSSM0dvUBSznJY'
58
+ end
59
+
60
+ it 'determines correct URL separator' do
61
+ subject.options[:access] = { private_key: 'e98ea443354183fd1fb434047232c687' }
62
+ subject.should_receive(:separator)
63
+ subject.send(:sign_url)
64
+ end
65
+ end
66
+
67
+ describe '#separator' do
68
+ it 'returns ? if URL has no parameters' do
69
+ subject.options[:path] = '/1/files/2'
70
+ subject.send(:separator).should == '?'
71
+ end
72
+
73
+ it 'returns & if URL has parameters' do
74
+ subject.send(:separator).should == '&'
75
+ end
76
+ end
77
+
78
+ describe '#prepend_version' do
79
+ it 'does not modify URL if API version is not specified' do
80
+ GroupDocs.stub(api_version: nil)
81
+ subject.options.should_not_receive(:[]=).with(:path, '/v2.0/1/files/2?new_name=invoice.docx')
82
+ subject.send(:prepend_version)
83
+ end
84
+
85
+ it 'prepends API version number' do
86
+ GroupDocs.stub(api_version: '2.0')
87
+ path = '/1/files/2?new_name=invoice.docx'
88
+ subject = GroupDocs::Api::Request.new(path: path)
89
+ subject.options.should_receive(:[]=).with(:path, "/v2.0#{path}").and_return("/v2.0#{path}")
90
+ subject.send(:prepend_version)
91
+ end
92
+ end
93
+ end