groupdocs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/README.md +141 -0
- data/Rakefile +9 -0
- data/groupdocs.gemspec +28 -0
- data/lib/groupdocs.rb +53 -0
- data/lib/groupdocs/api.rb +3 -0
- data/lib/groupdocs/api/entity.rb +113 -0
- data/lib/groupdocs/api/helpers.rb +5 -0
- data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
- data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
- data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
- data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
- data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
- data/lib/groupdocs/api/request.rb +73 -0
- data/lib/groupdocs/api/sugar/lookup.rb +48 -0
- data/lib/groupdocs/datasource.rb +162 -0
- data/lib/groupdocs/datasource/field.rb +44 -0
- data/lib/groupdocs/document.rb +513 -0
- data/lib/groupdocs/document/annotation.rb +215 -0
- data/lib/groupdocs/document/annotation/reply.rb +167 -0
- data/lib/groupdocs/document/change.rb +35 -0
- data/lib/groupdocs/document/field.rb +27 -0
- data/lib/groupdocs/document/metadata.rb +26 -0
- data/lib/groupdocs/document/rectangle.rb +24 -0
- data/lib/groupdocs/document/view.rb +36 -0
- data/lib/groupdocs/errors.rb +10 -0
- data/lib/groupdocs/job.rb +201 -0
- data/lib/groupdocs/questionnaire.rb +221 -0
- data/lib/groupdocs/questionnaire/execution.rb +120 -0
- data/lib/groupdocs/questionnaire/page.rb +43 -0
- data/lib/groupdocs/questionnaire/question.rb +75 -0
- data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
- data/lib/groupdocs/storage.rb +37 -0
- data/lib/groupdocs/storage/file.rb +248 -0
- data/lib/groupdocs/storage/folder.rb +314 -0
- data/lib/groupdocs/storage/package.rb +42 -0
- data/lib/groupdocs/user.rb +50 -0
- data/lib/groupdocs/version.rb +3 -0
- data/spec/groupdocs/api/entity_spec.rb +54 -0
- data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
- data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
- data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
- data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
- data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
- data/spec/groupdocs/api/request_spec.rb +85 -0
- data/spec/groupdocs/datasource/field_spec.rb +50 -0
- data/spec/groupdocs/datasource_spec.rb +156 -0
- data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
- data/spec/groupdocs/document/annotation_spec.rb +226 -0
- data/spec/groupdocs/document/change_spec.rb +35 -0
- data/spec/groupdocs/document/field_spec.rb +31 -0
- data/spec/groupdocs/document/metadata_spec.rb +26 -0
- data/spec/groupdocs/document/rectangle_spec.rb +34 -0
- data/spec/groupdocs/document/view_spec.rb +36 -0
- data/spec/groupdocs/document_spec.rb +509 -0
- data/spec/groupdocs/errors_spec.rb +7 -0
- data/spec/groupdocs/job_spec.rb +196 -0
- data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
- data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
- data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
- data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
- data/spec/groupdocs/questionnaire_spec.rb +217 -0
- data/spec/groupdocs/storage/file_spec.rb +242 -0
- data/spec/groupdocs/storage/folder_spec.rb +310 -0
- data/spec/groupdocs/storage/package_spec.rb +41 -0
- data/spec/groupdocs/storage_spec.rb +27 -0
- data/spec/groupdocs/user_spec.rb +53 -0
- data/spec/groupdocs_spec.rb +56 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/files/resume.pdf +0 -0
- data/spec/support/json/annotation_collaborators_set.json +16 -0
- data/spec/support/json/annotation_create.json +12 -0
- data/spec/support/json/annotation_list.json +32 -0
- data/spec/support/json/annotation_remove.json +9 -0
- data/spec/support/json/annotation_replies_create.json +9 -0
- data/spec/support/json/annotation_replies_get.json +25 -0
- data/spec/support/json/comparison_changes.json +46 -0
- data/spec/support/json/comparison_compare.json +8 -0
- data/spec/support/json/comparison_document.json +10 -0
- data/spec/support/json/datasource_add.json +8 -0
- data/spec/support/json/datasource_get.json +22 -0
- data/spec/support/json/datasource_remove.json +8 -0
- data/spec/support/json/datasource_update.json +8 -0
- data/spec/support/json/document_access_info_get.json +14 -0
- data/spec/support/json/document_convert.json +8 -0
- data/spec/support/json/document_datasource.json +10 -0
- data/spec/support/json/document_fields.json +34 -0
- data/spec/support/json/document_formats.json +8 -0
- data/spec/support/json/document_metadata.json +15 -0
- data/spec/support/json/document_questionnaire_create.json +9 -0
- data/spec/support/json/document_questionnaires.json +23 -0
- data/spec/support/json/document_sharers_remove.json +8 -0
- data/spec/support/json/document_sharers_set.json +16 -0
- data/spec/support/json/document_views.json +32 -0
- data/spec/support/json/file_compress.json +8 -0
- data/spec/support/json/file_copy.json +14 -0
- data/spec/support/json/file_delete.json +5 -0
- data/spec/support/json/file_move.json +14 -0
- data/spec/support/json/file_upload.json +8 -0
- data/spec/support/json/folder_create.json +8 -0
- data/spec/support/json/folder_delete.json +5 -0
- data/spec/support/json/folder_list.json +21 -0
- data/spec/support/json/folder_move.json +8 -0
- data/spec/support/json/folder_sharers_get.json +16 -0
- data/spec/support/json/folder_sharers_remove.json +8 -0
- data/spec/support/json/folder_sharers_set.json +16 -0
- data/spec/support/json/job_add_url.json +8 -0
- data/spec/support/json/job_create.json +8 -0
- data/spec/support/json/job_documents.json +39 -0
- data/spec/support/json/job_file_add.json +8 -0
- data/spec/support/json/job_update.json +7 -0
- data/spec/support/json/jobs_get.json +52 -0
- data/spec/support/json/package_create.json +7 -0
- data/spec/support/json/questionnaire_create.json +8 -0
- data/spec/support/json/questionnaire_datasources.json +26 -0
- data/spec/support/json/questionnaire_execution_create.json +9 -0
- data/spec/support/json/questionnaire_execution_status_set.json +8 -0
- data/spec/support/json/questionnaire_execution_update.json +8 -0
- data/spec/support/json/questionnaire_executions.json +24 -0
- data/spec/support/json/questionnaire_get.json +14 -0
- data/spec/support/json/questionnaire_remove.json +8 -0
- data/spec/support/json/questionnaire_update.json +8 -0
- data/spec/support/json/questionnaires_get.json +22 -0
- data/spec/support/json/storage_info.json +10 -0
- data/spec/support/shared_examples/api/entity.rb +37 -0
- data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
- data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
- metadata +356 -0
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GroupDocs::Questionnaire do
|
4
|
+
|
5
|
+
it_behaves_like GroupDocs::Api::Entity
|
6
|
+
|
7
|
+
describe '.all!' do
|
8
|
+
before(:each) do
|
9
|
+
mock_api_server(load_json('questionnaires_get'))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts access credentials hash' do
|
13
|
+
lambda do
|
14
|
+
described_class.all!(client_id: 'client_id', private_key: 'private_key')
|
15
|
+
end.should_not raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns an array of GroupDocs::Questionnaire objects' do
|
19
|
+
questionnaires = described_class.all!
|
20
|
+
questionnaires.should be_an(Array)
|
21
|
+
questionnaires.each do |questionnaire|
|
22
|
+
questionnaire.should be_a(GroupDocs::Questionnaire)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.get!' do
|
28
|
+
before(:each) do
|
29
|
+
mock_api_server(load_json('questionnaire_get'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts access credentials hash' do
|
33
|
+
lambda do
|
34
|
+
described_class.get!(1, client_id: 'client_id', private_key: 'private_key')
|
35
|
+
end.should_not raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns GroupDocs::Questionnaire object' do
|
39
|
+
described_class.get!(1).should be_a(GroupDocs::Questionnaire)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns nil if BadRequestError was raised' do
|
43
|
+
GroupDocs::Api::Request.any_instance.should_receive(:execute!).and_raise(RestClient::BadRequest)
|
44
|
+
described_class.get!(1).should be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '.executions!' do
|
49
|
+
before(:each) do
|
50
|
+
mock_api_server(load_json('questionnaire_executions'))
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'accepts access credentials hash' do
|
54
|
+
lambda do
|
55
|
+
described_class.executions!(client_id: 'client_id', private_key: 'private_key')
|
56
|
+
end.should_not raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns an array of GroupDocs::Questionnaire::Execution objects' do
|
60
|
+
executions = described_class.executions!
|
61
|
+
executions.should be_an(Array)
|
62
|
+
executions.each do |execution|
|
63
|
+
execution.should be_a(GroupDocs::Questionnaire::Execution)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it { should respond_to(:pages) }
|
69
|
+
it { should respond_to(:pages=) }
|
70
|
+
|
71
|
+
it 'has human-readable accessors' do
|
72
|
+
subject.should respond_to(:description)
|
73
|
+
subject.should respond_to(:description=)
|
74
|
+
subject.method(:description).should == subject.method(:descr)
|
75
|
+
subject.method(:description=).should == subject.method(:descr=)
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#pages=' do
|
79
|
+
it 'converts each page to GroupDocs::Questionnaire::Page object if hash is passed' do
|
80
|
+
subject.pages = [{ number: 1, title: 'Page1' }, { number: 2, title: 'Page2' }]
|
81
|
+
pages = subject.pages
|
82
|
+
pages.should be_an(Array)
|
83
|
+
pages.each do |page|
|
84
|
+
page.should be_a(GroupDocs::Questionnaire::Page)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'saves each page if it is GroupDocs::Questionnaire::Page object' do
|
89
|
+
page1 = GroupDocs::Questionnaire::Page.new(number: 1)
|
90
|
+
page2 = GroupDocs::Questionnaire::Page.new(number: 2)
|
91
|
+
subject.pages = [page1, page2]
|
92
|
+
subject.pages.should include(page1)
|
93
|
+
subject.pages.should include(page2)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'does nothing if nil is passed' do
|
97
|
+
lambda do
|
98
|
+
subject.pages = nil
|
99
|
+
end.should_not change(subject, :pages)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#add_page' do
|
104
|
+
it 'raises error if page is not GroupDocs::Questionnaire::Page object' do
|
105
|
+
-> { subject.add_page('Page') }.should raise_error(ArgumentError)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'adds page to pages instance variable' do
|
109
|
+
page = GroupDocs::Questionnaire::Page.new
|
110
|
+
lambda do
|
111
|
+
subject.add_page(page)
|
112
|
+
end.should change(subject, :pages).to([page])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#create!' do
|
117
|
+
before(:each) do
|
118
|
+
mock_api_server(load_json('questionnaire_create'))
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'accepts access credentials hash' do
|
122
|
+
lambda do
|
123
|
+
subject.create!(client_id: 'client_id', private_key: 'private_key')
|
124
|
+
end.should_not raise_error(ArgumentError)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'uses hashed version of self as request body' do
|
128
|
+
subject.should_receive(:to_hash)
|
129
|
+
subject.create!
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'adds ID of questionnaire from response to self' do
|
133
|
+
lambda do
|
134
|
+
subject.create!
|
135
|
+
end.should change(subject, :id)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#update!' do
|
140
|
+
before(:each) do
|
141
|
+
mock_api_server(load_json('questionnaire_update'))
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'accepts access credentials hash' do
|
145
|
+
lambda do
|
146
|
+
subject.update!(client_id: 'client_id', private_key: 'private_key')
|
147
|
+
end.should_not raise_error(ArgumentError)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'uses hashed version of self as request body' do
|
151
|
+
subject.should_receive(:to_hash)
|
152
|
+
subject.update!
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#remove!' do
|
157
|
+
before(:each) do
|
158
|
+
mock_api_server(load_json('questionnaire_remove'))
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'accepts access credentials hash' do
|
162
|
+
lambda do
|
163
|
+
subject.remove!(client_id: 'client_id', private_key: 'private_key')
|
164
|
+
end.should_not raise_error(ArgumentError)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#datasources!' do
|
169
|
+
before(:each) do
|
170
|
+
mock_api_server(load_json('questionnaire_datasources'))
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'accepts access credentials hash' do
|
174
|
+
lambda do
|
175
|
+
subject.datasources!(client_id: 'client_id', private_key: 'private_key')
|
176
|
+
end.should_not raise_error(ArgumentError)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'returns array of GroupDocs::DataSource objects' do
|
180
|
+
datasources = subject.datasources!
|
181
|
+
datasources.should be_an(Array)
|
182
|
+
datasources.each do |datasource|
|
183
|
+
datasource.should be_a(GroupDocs::DataSource)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#create_execution!' do
|
189
|
+
before(:each) do
|
190
|
+
mock_api_server(load_json('questionnaire_execution_create'))
|
191
|
+
end
|
192
|
+
|
193
|
+
let(:execution) { GroupDocs::Questionnaire::Execution.new }
|
194
|
+
let(:email) { 'email@email.com' }
|
195
|
+
|
196
|
+
it 'accepts access credentials hash' do
|
197
|
+
lambda do
|
198
|
+
subject.create_execution!(execution, email, client_id: 'client_id', private_key: 'private_key')
|
199
|
+
end.should_not raise_error(ArgumentError)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'raises error if execution is not GroupDocs::Questionnaire::Execution object' do
|
203
|
+
-> { subject.create_execution!('Execution', email) }.should raise_error(ArgumentError)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'uses hashed version of execution along with executive payload' do
|
207
|
+
hash = {}
|
208
|
+
execution.should_receive(:to_hash).and_return(hash)
|
209
|
+
hash.should_receive(:merge).with({ executive: { primary_email: email } })
|
210
|
+
subject.create_execution!(execution, email)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'returns GroupDocs::Questionnaire::Execution object' do
|
214
|
+
subject.create_execution!(execution, email).should be_a(GroupDocs::Questionnaire::Execution)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GroupDocs::Storage::File do
|
4
|
+
|
5
|
+
it_behaves_like GroupDocs::Api::Entity
|
6
|
+
include_examples GroupDocs::Api::Sugar::Lookup
|
7
|
+
|
8
|
+
describe '.upload!' do
|
9
|
+
before(:each) do
|
10
|
+
mock_api_server(load_json('file_upload'))
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts options hash' do
|
14
|
+
lambda do
|
15
|
+
described_class.upload!(__FILE__, '/upload_path', { description: 'Description' })
|
16
|
+
end.should_not raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'accepts access credentials hash' do
|
20
|
+
lambda do
|
21
|
+
described_class.upload!(__FILE__, '/upload_path', {}, client_id: 'client_id', private_key: 'private_key')
|
22
|
+
end.should_not raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'raises error if upload path does not start with /' do
|
26
|
+
-> { described_class.upload!('test', 'upload_path') }.should raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'appends filename to upload path if it is not passed' do
|
30
|
+
upload_path = '/upload_path'
|
31
|
+
upload_path.should_receive(:<<).with("/#{File.basename(__FILE__)}")
|
32
|
+
described_class.upload!(__FILE__, upload_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns GroupDocs::Storage::File object' do
|
36
|
+
described_class.upload!(__FILE__).should be_a(GroupDocs::Storage::File)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it { should respond_to(:id) }
|
41
|
+
it { should respond_to(:id=) }
|
42
|
+
it { should respond_to(:guid) }
|
43
|
+
it { should respond_to(:guid=) }
|
44
|
+
it { should respond_to(:known) }
|
45
|
+
it { should respond_to(:known=) }
|
46
|
+
it { should respond_to(:size) }
|
47
|
+
it { should respond_to(:size=) }
|
48
|
+
it { should respond_to(:thumbnail) }
|
49
|
+
it { should respond_to(:thumbnail=) }
|
50
|
+
it { should respond_to(:created_on) }
|
51
|
+
it { should respond_to(:created_on=) }
|
52
|
+
it { should respond_to(:modified_on) }
|
53
|
+
it { should respond_to(:modified_on=) }
|
54
|
+
it { should respond_to(:url) }
|
55
|
+
it { should respond_to(:url=) }
|
56
|
+
it { should respond_to(:name) }
|
57
|
+
it { should respond_to(:name=) }
|
58
|
+
it { should respond_to(:version) }
|
59
|
+
it { should respond_to(:version=) }
|
60
|
+
it { should respond_to(:type) }
|
61
|
+
it { should respond_to(:type=) }
|
62
|
+
it { should respond_to(:access) }
|
63
|
+
it { should respond_to(:access=) }
|
64
|
+
it { should respond_to(:path) }
|
65
|
+
it { should respond_to(:path=) }
|
66
|
+
|
67
|
+
it 'is compatible with response JSON' do
|
68
|
+
subject.should respond_to(:adj_name=)
|
69
|
+
subject.method(:adj_name=).should == subject.method(:name=)
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#created_on' do
|
73
|
+
it 'converts timestamp to Time object' do
|
74
|
+
subject.created_on = 1330450135
|
75
|
+
subject.created_on.should be_a(Time)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#modified_on' do
|
80
|
+
it 'returns converted to Time object Unix timestamp' do
|
81
|
+
subject.modified_on = 1330450135
|
82
|
+
subject.modified_on.should be_a(Time)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#download!' do
|
87
|
+
before(:each) do
|
88
|
+
mock_api_server(File.read('spec/support/files/resume.pdf'))
|
89
|
+
subject.stub(name: 'resume.pdf')
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:path) { Dir.tmpdir }
|
93
|
+
|
94
|
+
it 'accepts access credentials hash' do
|
95
|
+
lambda do
|
96
|
+
subject.download!(path, client_id: 'client_id', private_key: 'private_key')
|
97
|
+
end.should_not raise_error(ArgumentError)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'downloads file to given path' do
|
101
|
+
file = stub('file')
|
102
|
+
Object::File.should_receive(:open).with("#{path}/resume.pdf", 'w').and_yield(file)
|
103
|
+
file.should_receive(:write).with(File.read('spec/support/files/resume.pdf'))
|
104
|
+
subject.download!(path)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns saved file path' do
|
108
|
+
subject.download!(path).should == "#{path}/resume.pdf"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#move!' do
|
113
|
+
before(:each) do
|
114
|
+
mock_api_server(load_json('file_move'))
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'accepts access credentials hash' do
|
118
|
+
lambda do
|
119
|
+
subject.move!('/resume.pdf', client_id: 'client_id', private_key: 'private_key')
|
120
|
+
end.should_not raise_error(ArgumentError)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'raises error if path does not start with /' do
|
124
|
+
-> { subject.move!('resume2.pdf') }.should raise_error(ArgumentError)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'sends "Groupdocs-Move" header' do
|
128
|
+
mock_api_server(load_json('file_move'), :'Groupdocs-Move' => '123')
|
129
|
+
subject.stub(id: 123)
|
130
|
+
subject.move!('/resume2.pdf')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'returns moved to file' do
|
134
|
+
subject.move!('/resume2.pdf').should be_a(GroupDocs::Storage::File)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'appends filename to move to path if it is not passed' do
|
138
|
+
path = '/Folder'
|
139
|
+
name = File.basename(__FILE__)
|
140
|
+
subject.stub(name: name)
|
141
|
+
path.should_receive(:<<).with("/#{name}")
|
142
|
+
subject.move!(path)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#rename!' do
|
147
|
+
before(:each) do
|
148
|
+
subject.path = '/'
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'accepts access credentials hash' do
|
152
|
+
lambda do
|
153
|
+
subject.rename!('resume.pdf', client_id: 'client_id', private_key: 'private_key')
|
154
|
+
end.should_not raise_error(ArgumentError)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'uses #move! to rename file' do
|
158
|
+
subject.should_receive(:move!).with('/resume2.pdf', {})
|
159
|
+
subject.rename!('resume2.pdf')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#copy!' do
|
164
|
+
before(:each) do
|
165
|
+
mock_api_server(load_json('file_copy'))
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'accepts access credentials hash' do
|
169
|
+
lambda do
|
170
|
+
subject.copy!('/resume.pdf', client_id: 'client_id', private_key: 'private_key')
|
171
|
+
end.should_not raise_error(ArgumentError)
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'raises error if path does not start with /' do
|
175
|
+
-> { subject.copy!('resume2.pdf') }.should raise_error(ArgumentError)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'sends "Groupdocs-Copy" header' do
|
179
|
+
mock_api_server(load_json('file_copy'), :'Groupdocs-Copy' => '123')
|
180
|
+
subject.stub(id: 123)
|
181
|
+
subject.copy!('/resume2.pdf')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'returns copied to file' do
|
185
|
+
subject.copy!('/resume2.pdf').should be_a(GroupDocs::Storage::File)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'appends filename to copy to path if it is not passed' do
|
189
|
+
path = '/Folder'
|
190
|
+
name = File.basename(__FILE__)
|
191
|
+
subject.stub(name: name)
|
192
|
+
path.should_receive(:<<).with("/#{name}")
|
193
|
+
subject.copy!(path)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#compress!' do
|
198
|
+
before(:each) do
|
199
|
+
mock_api_server(load_json('file_compress'))
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'accepts access credentials hash' do
|
203
|
+
lambda do
|
204
|
+
subject.compress!(:zip, client_id: 'client_id', private_key: 'private_key')
|
205
|
+
end.should_not raise_error(ArgumentError)
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'returns archived file' do
|
209
|
+
subject.stub(name: 'resume.pdf')
|
210
|
+
subject.compress!(:zip).should be_a(GroupDocs::Storage::File)
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'creates archive filename as filename + archive type' do
|
214
|
+
subject.stub(name: 'resume.pdf')
|
215
|
+
subject.compress!(:zip).name.should == 'resume.pdf.zip'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe '#delete!' do
|
220
|
+
it 'accepts access credentials hash' do
|
221
|
+
lambda do
|
222
|
+
subject.delete!(client_id: 'client_id', private_key: 'private_key')
|
223
|
+
end.should_not raise_error(ArgumentError)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'uses file guid' do
|
227
|
+
mock_api_server(load_json('file_delete'))
|
228
|
+
subject.should_receive(:guid).and_return('guid')
|
229
|
+
subject.delete!
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe '#to_document' do
|
234
|
+
it 'creates new GroupDocs::Document' do
|
235
|
+
subject.to_document.should be_a(GroupDocs::Document)
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'passes self as file for GroupDocs::Document' do
|
239
|
+
subject.to_document.file.should == subject
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|