groupdocs 0.3.11 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGELOG.md +150 -0
  2. data/README.md +6 -58
  3. data/Rakefile +1 -1
  4. data/examples/README.md +13 -0
  5. data/examples/annotations/Gemfile +5 -0
  6. data/examples/annotations/app.rb +67 -0
  7. data/groupdocs.gemspec +3 -3
  8. data/lib/groupdocs.rb +11 -2
  9. data/lib/groupdocs/api/entity.rb +17 -1
  10. data/lib/groupdocs/api/helpers/path_helper.rb +10 -10
  11. data/lib/groupdocs/api/helpers/rest_helper.rb +7 -2
  12. data/lib/groupdocs/api/helpers/url_helper.rb +2 -4
  13. data/lib/groupdocs/api/request.rb +2 -4
  14. data/lib/groupdocs/datasource.rb +2 -2
  15. data/lib/groupdocs/datasource/field.rb +1 -1
  16. data/lib/groupdocs/document.rb +6 -18
  17. data/lib/groupdocs/document/annotation.rb +25 -2
  18. data/lib/groupdocs/document/annotation/reply.rb +6 -10
  19. data/lib/groupdocs/document/change.rb +1 -1
  20. data/lib/groupdocs/document/field.rb +1 -1
  21. data/lib/groupdocs/document/metadata.rb +1 -1
  22. data/lib/groupdocs/document/rectangle.rb +1 -1
  23. data/lib/groupdocs/document/view.rb +1 -1
  24. data/lib/groupdocs/job.rb +51 -8
  25. data/lib/groupdocs/questionnaire.rb +2 -2
  26. data/lib/groupdocs/questionnaire/execution.rb +1 -1
  27. data/lib/groupdocs/questionnaire/page.rb +1 -1
  28. data/lib/groupdocs/questionnaire/question.rb +1 -1
  29. data/lib/groupdocs/questionnaire/question/answer.rb +1 -1
  30. data/lib/groupdocs/signature.rb +134 -0
  31. data/lib/groupdocs/signature/contact.rb +141 -0
  32. data/lib/groupdocs/signature/envelope.rb +376 -0
  33. data/lib/groupdocs/signature/envelope/log.rb +22 -0
  34. data/lib/groupdocs/signature/field.rb +253 -0
  35. data/lib/groupdocs/signature/field/location.rb +72 -0
  36. data/lib/groupdocs/signature/form.rb +202 -0
  37. data/lib/groupdocs/signature/list.rb +93 -0
  38. data/lib/groupdocs/signature/recipient.rb +47 -0
  39. data/lib/groupdocs/signature/role.rb +84 -0
  40. data/lib/groupdocs/signature/shared.rb +6 -0
  41. data/lib/groupdocs/signature/shared/document_methods.rb +98 -0
  42. data/lib/groupdocs/signature/shared/entity_fields.rb +94 -0
  43. data/lib/groupdocs/signature/shared/entity_methods.rb +145 -0
  44. data/lib/groupdocs/signature/shared/field_methods.rb +282 -0
  45. data/lib/groupdocs/signature/shared/recipient_methods.rb +63 -0
  46. data/lib/groupdocs/signature/shared/resource_methods.rb +65 -0
  47. data/lib/groupdocs/signature/template.rb +104 -0
  48. data/lib/groupdocs/storage/file.rb +69 -62
  49. data/lib/groupdocs/storage/folder.rb +54 -88
  50. data/lib/groupdocs/storage/package.rb +1 -1
  51. data/lib/groupdocs/subscription.rb +113 -0
  52. data/lib/groupdocs/subscription/limit.rb +24 -0
  53. data/lib/groupdocs/user.rb +22 -2
  54. data/lib/groupdocs/version.rb +1 -1
  55. data/spec/groupdocs/api/entity_spec.rb +14 -0
  56. data/spec/groupdocs/api/helpers/path_helper_spec.rb +6 -19
  57. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +9 -0
  58. data/spec/groupdocs/api/request_spec.rb +2 -7
  59. data/spec/groupdocs/datasource_spec.rb +3 -7
  60. data/spec/groupdocs/document/annotation/reply_spec.rb +11 -20
  61. data/spec/groupdocs/document/annotation_spec.rb +35 -31
  62. data/spec/groupdocs/document/field_spec.rb +1 -4
  63. data/spec/groupdocs/document/rectangle_spec.rb +10 -22
  64. data/spec/groupdocs/document_spec.rb +7 -27
  65. data/spec/groupdocs/job_spec.rb +43 -0
  66. data/spec/groupdocs/questionnaire/question_spec.rb +2 -6
  67. data/spec/groupdocs/questionnaire_spec.rb +3 -7
  68. data/spec/groupdocs/signature/contact_spec.rb +129 -0
  69. data/spec/groupdocs/signature/envelope/log_spec.rb +23 -0
  70. data/spec/groupdocs/signature/envelope_spec.rb +296 -0
  71. data/spec/groupdocs/signature/field/location_spec.rb +73 -0
  72. data/spec/groupdocs/signature/field_spec.rb +264 -0
  73. data/spec/groupdocs/signature/form_spec.rb +174 -0
  74. data/spec/groupdocs/signature/list_spec.rb +92 -0
  75. data/spec/groupdocs/signature/recipient_spec.rb +37 -0
  76. data/spec/groupdocs/signature/role_spec.rb +100 -0
  77. data/spec/groupdocs/signature/template_spec.rb +82 -0
  78. data/spec/groupdocs/signature_spec.rb +117 -0
  79. data/spec/groupdocs/storage/file_spec.rb +76 -61
  80. data/spec/groupdocs/storage/folder_spec.rb +43 -90
  81. data/spec/groupdocs/storage/package_spec.rb +1 -2
  82. data/spec/groupdocs/subscription/limit_spec.rb +24 -0
  83. data/spec/groupdocs/subscription_spec.rb +85 -0
  84. data/spec/groupdocs/user_spec.rb +27 -18
  85. data/spec/groupdocs_spec.rb +11 -0
  86. data/spec/spec_helper.rb +10 -1
  87. data/spec/support/files/envelope.zip +0 -0
  88. data/spec/support/json/annotation_access_set.json +11 -0
  89. data/spec/support/json/contact_add.json +12 -0
  90. data/spec/support/json/contacts_get.json +19 -0
  91. data/spec/support/json/contacts_import.json +8 -0
  92. data/spec/support/json/envelope_get.json +46 -0
  93. data/spec/support/json/envelope_logs.json +16 -0
  94. data/spec/support/json/envelopes_all.json +48 -0
  95. data/spec/support/json/envelopes_resources.json +31 -0
  96. data/spec/support/json/form_get.json +21 -0
  97. data/spec/support/json/forms_all.json +23 -0
  98. data/spec/support/json/job_get.json +30 -0
  99. data/spec/support/json/list_add.json +12 -0
  100. data/spec/support/json/lists_get.json +19 -0
  101. data/spec/support/json/signature_create.json +12 -0
  102. data/spec/support/json/signature_field_add.json +25 -0
  103. data/spec/support/json/signature_fields_get.json +27 -0
  104. data/spec/support/json/signature_roles_get.json +17 -0
  105. data/spec/support/json/signatures_get.json +19 -0
  106. data/spec/support/json/subscription_plan_get.json +9 -0
  107. data/spec/support/json/subscription_plans_get.json +17 -0
  108. data/spec/support/json/template_get.json +35 -0
  109. data/spec/support/json/template_get_documents.json +15 -0
  110. data/spec/support/json/template_get_recipients.json +20 -0
  111. data/spec/support/json/templates_all.json +37 -0
  112. data/spec/support/json/user_users_get.json +27 -0
  113. data/spec/support/shared_examples/signature/shared/document_methods.rb +68 -0
  114. data/spec/support/shared_examples/signature/shared/entity_fields.rb +89 -0
  115. data/spec/support/shared_examples/signature/shared/entity_methods.rb +116 -0
  116. data/spec/support/shared_examples/signature/shared/field_methods.rb +188 -0
  117. data/spec/support/shared_examples/signature/shared/recipient_methods.rb +42 -0
  118. data/spec/support/shared_examples/signature/shared/resource_methods.rb +46 -0
  119. metadata +139 -29
  120. data/lib/groupdocs/extensions.rb +0 -1
  121. data/lib/groupdocs/extensions/lookup.rb +0 -52
  122. data/spec/support/shared_examples/extensions/lookup.rb +0 -57
@@ -13,26 +13,14 @@ describe GroupDocs::Document::Rectangle do
13
13
  it { should respond_to(:Height) }
14
14
  it { should respond_to(:Height=) }
15
15
 
16
- it 'has human-readable accessors' do
17
- subject.should respond_to(:x)
18
- subject.should respond_to(:x=)
19
- subject.should respond_to(:y)
20
- subject.should respond_to(:y=)
21
- subject.should respond_to(:w)
22
- subject.should respond_to(:w=)
23
- subject.should respond_to(:width)
24
- subject.should respond_to(:h)
25
- subject.should respond_to(:h=)
26
- subject.should respond_to(:height)
27
- subject.method(:x).should == subject.method(:X)
28
- subject.method(:x=).should == subject.method(:X=)
29
- subject.method(:y).should == subject.method(:Y)
30
- subject.method(:y=).should == subject.method(:Y=)
31
- subject.method(:w).should == subject.method(:Width)
32
- subject.method(:w=).should == subject.method(:Width=)
33
- subject.method(:width).should == subject.method(:w)
34
- subject.method(:h).should == subject.method(:Height)
35
- subject.method(:h=).should == subject.method(:Height=)
36
- subject.method(:height).should == subject.method(:h)
37
- end
16
+ it { should have_alias(:x, :X) }
17
+ it { should have_alias(:x=, :X=) }
18
+ it { should have_alias(:y, :Y) }
19
+ it { should have_alias(:y=, :Y=) }
20
+ it { should have_alias(:w, :Width) }
21
+ it { should have_alias(:w=, :Width=) }
22
+ it { should have_alias(:width, :w) }
23
+ it { should have_alias(:h, :Height) }
24
+ it { should have_alias(:h=, :Height=) }
25
+ it { should have_alias(:height, :h) }
38
26
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe GroupDocs::Document do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
- include_examples GroupDocs::Extensions::Lookup
7
6
  include_examples GroupDocs::Api::Helpers::Status
8
7
 
9
8
  subject do
@@ -31,23 +30,6 @@ describe GroupDocs::Document do
31
30
  end
32
31
  end
33
32
 
34
- describe '.all!' do
35
- it 'accepts access credentials hash' do
36
- lambda do
37
- described_class.all!('/', client_id: 'client_id', private_key: 'private_key')
38
- end.should_not raise_error(ArgumentError)
39
- end
40
-
41
- it 'calls GroupDocs::Storage::File.all! and converts each file to document' do
42
- file1 = GroupDocs::Storage::File.new
43
- file2 = GroupDocs::Storage::File.new
44
- GroupDocs::Storage::File.should_receive(:all!).with('/', {}).and_return([file1, file2])
45
- file1.should_receive(:to_document).and_return(described_class.new(file: file1))
46
- file2.should_receive(:to_document).and_return(described_class.new(file: file2))
47
- described_class.all!
48
- end
49
- end
50
-
51
33
  it { should respond_to(:file) }
52
34
  it { should respond_to(:file=) }
53
35
  it { should respond_to(:process_date) }
@@ -56,11 +38,10 @@ describe GroupDocs::Document do
56
38
  it { should respond_to(:outputs=) }
57
39
  it { should respond_to(:output_formats) }
58
40
  it { should respond_to(:output_formats=) }
41
+ it { should respond_to(:order) }
42
+ it { should respond_to(:order=) }
59
43
 
60
- it 'is compatible with response JSON' do
61
- subject.should respond_to(:proc_date=)
62
- subject.method(:proc_date=).should == subject.method(:process_date=)
63
- end
44
+ it { should have_alias(:access_mode=, :access_mode_set!) }
64
45
 
65
46
  describe '#outputs=' do
66
47
  let(:response) do
@@ -149,8 +130,7 @@ describe GroupDocs::Document do
149
130
  end
150
131
 
151
132
  it 'is aliased to #access_mode=' do
152
- subject.should respond_to(:access_mode=)
153
- subject.method(:access_mode=).should == subject.method(:access_mode_set!)
133
+ subject.should have_alias(:access_mode=, :access_mode_set!)
154
134
  end
155
135
  end
156
136
 
@@ -198,7 +178,7 @@ describe GroupDocs::Document do
198
178
  end
199
179
 
200
180
  it 'does not set last view if document has never been viewed' do
201
- mock_api_server('{"status": "Ok", "result": {"last_view": null }}')
181
+ mock_api_server('{ "status": "Ok", "result": { "last_view": null }}')
202
182
  subject.metadata!.last_view.should be_nil
203
183
  end
204
184
  end
@@ -375,7 +355,7 @@ describe GroupDocs::Document do
375
355
  subject.create_questionnaire!(questionnaire)
376
356
  end
377
357
 
378
- it 'adds ID from response to questionnaire' do
358
+ it 'updates ID from response to questionnaire' do
379
359
  lambda do
380
360
  subject.create_questionnaire!(questionnaire)
381
361
  end.should change(questionnaire, :id)
@@ -449,7 +429,7 @@ describe GroupDocs::Document do
449
429
  end
450
430
 
451
431
  it 'returns empty array if annotations are null in response' do
452
- mock_api_server('{"status": "Ok", "result": {"annotations": null }}')
432
+ mock_api_server('{ "status": "Ok", "result": { "annotations": null }}')
453
433
  subject.annotations!.should be_empty
454
434
  end
455
435
  end
@@ -31,6 +31,22 @@ describe GroupDocs::Job do
31
31
  end
32
32
  end
33
33
 
34
+ describe '.get!' do
35
+ before(:each) do
36
+ mock_api_server(load_json('job_get'))
37
+ end
38
+
39
+ it 'accepts access credentials hash' do
40
+ lambda do
41
+ described_class.get!(1, client_id: 'client_id', private_key: 'private_key')
42
+ end.should_not raise_error(ArgumentError)
43
+ end
44
+
45
+ it 'returns GroupDocs::Job object' do
46
+ described_class.get!(1).should be_a(GroupDocs::Job)
47
+ end
48
+ end
49
+
34
50
  describe '.create!' do
35
51
  before(:each) do
36
52
  mock_api_server(load_json('job_create'))
@@ -66,6 +82,12 @@ describe GroupDocs::Job do
66
82
 
67
83
  it { should respond_to(:id) }
68
84
  it { should respond_to(:id=) }
85
+ it { should respond_to(:guid) }
86
+ it { should respond_to(:guid=) }
87
+ it { should respond_to(:name) }
88
+ it { should respond_to(:name=) }
89
+ it { should respond_to(:priority) }
90
+ it { should respond_to(:priority=) }
69
91
  it { should respond_to(:actions) }
70
92
  it { should respond_to(:actions=) }
71
93
  it { should respond_to(:email_results) }
@@ -140,6 +162,11 @@ describe GroupDocs::Job do
140
162
  document.should be_a(GroupDocs::Document)
141
163
  end
142
164
  end
165
+
166
+ it 'returns empty array if null is returned instead of inputs array' do
167
+ mock_api_server('{ "status": "Ok", "result": {}}')
168
+ subject.documents!.should be_empty
169
+ end
143
170
  end
144
171
 
145
172
  describe '#add_document!' do
@@ -172,6 +199,22 @@ describe GroupDocs::Job do
172
199
  end
173
200
  end
174
201
 
202
+ describe '#delete_document!' do
203
+ before(:each) do
204
+ mock_api_server('{ "result": {}, "status": "Ok" }')
205
+ end
206
+
207
+ it 'accepts access credentials hash' do
208
+ lambda do
209
+ subject.delete_document!('a9ufg8s7dfgsdf', client_id: 'client_id', private_key: 'private_key')
210
+ end.should_not raise_error(ArgumentError)
211
+ end
212
+
213
+ it 'returns empty hash' do
214
+ subject.delete_document!('a9ufg8s7dfgsdf').should be_empty
215
+ end
216
+ end
217
+
175
218
  describe '#add_datasource!' do
176
219
  let(:document) do
177
220
  GroupDocs::Document.new(file: GroupDocs::Storage::File.new)
@@ -17,12 +17,8 @@ describe GroupDocs::Questionnaire::Question do
17
17
  it { should respond_to(:answers) }
18
18
  it { should respond_to(:answers=) }
19
19
 
20
- it 'has human-readable accessors' do
21
- subject.should respond_to(:default_answer)
22
- subject.should respond_to(:default_answer=)
23
- subject.method(:default_answer).should == subject.method(:def_answer)
24
- subject.method(:default_answer=).should == subject.method(:def_answer=)
25
- end
20
+ it { should have_alias(:default_answer, :def_answer) }
21
+ it { should have_alias(:default_answer=, :def_answer=) }
26
22
 
27
23
  describe '#answers=' do
28
24
  it 'converts each answer to GroupDocs::Questionnaire::Question::Answer object' do
@@ -68,12 +68,8 @@ describe GroupDocs::Questionnaire do
68
68
  it { should respond_to(:pages) }
69
69
  it { should respond_to(:pages=) }
70
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
71
+ it { should have_alias(:description, :descr) }
72
+ it { should have_alias(:description=, :descr=) }
77
73
 
78
74
  describe '#pages=' do
79
75
  it 'converts each page to GroupDocs::Questionnaire::Page object if hash is passed' do
@@ -129,7 +125,7 @@ describe GroupDocs::Questionnaire do
129
125
  subject.create!
130
126
  end
131
127
 
132
- it 'adds ID of questionnaire from response to self' do
128
+ it 'updates identifier of questionnaire' do
133
129
  lambda do
134
130
  subject.create!
135
131
  end.should change(subject, :id)
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Contact do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe '.get!' do
8
+ before(:each) do
9
+ mock_api_server(load_json('contacts_get'))
10
+ end
11
+
12
+ it 'accepts access credentials hash' do
13
+ lambda do
14
+ described_class.get!({}, client_id: 'client_id', private_key: 'private_key')
15
+ end.should_not raise_error(ArgumentError)
16
+ end
17
+
18
+ it 'allows passing options' do
19
+ -> { described_class.get!(page: 1, email: 'com') }.should_not raise_error(ArgumentError)
20
+ end
21
+
22
+ it 'returns array of GroupDocs::Signature::Contact objects' do
23
+ contacts = described_class.get!
24
+ contacts.should be_an(Array)
25
+ contacts.each do |contact|
26
+ contact.should be_a(GroupDocs::Signature::Contact)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '.import!' do
32
+ let(:contact) do
33
+ described_class.new(first_name: 'John', last_name: 'Smith', email: 'john@smith.com')
34
+ end
35
+
36
+ before(:each) do
37
+ mock_api_server(load_json('contacts_import'))
38
+ end
39
+
40
+ it 'accepts access credentials hash' do
41
+ lambda do
42
+ described_class.import!([contact], client_id: 'client_id', private_key: 'private_key')
43
+ end.should_not raise_error(ArgumentError)
44
+ end
45
+
46
+ it 'raises error if contacts is not array' do
47
+ -> { described_class.import!(contact) }.should raise_error(ArgumentError)
48
+ end
49
+
50
+ it 'raises error if array element is not GroupDocs::Signature::Contact' do
51
+ -> { described_class.import!(%w(test)) }.should raise_error(ArgumentError)
52
+ end
53
+
54
+ it 'uses hashed version of array elements as request body' do
55
+ contact.should_receive(:to_hash)
56
+ described_class.import!([contact])
57
+ end
58
+ end
59
+
60
+ it { should respond_to(:id) }
61
+ it { should respond_to(:id=) }
62
+ it { should respond_to(:firstName) }
63
+ it { should respond_to(:firstName=) }
64
+ it { should respond_to(:lastName) }
65
+ it { should respond_to(:lastName=) }
66
+ it { should respond_to(:nickname) }
67
+ it { should respond_to(:nickname=) }
68
+ it { should respond_to(:email) }
69
+ it { should respond_to(:email=) }
70
+ it { should respond_to(:provider) }
71
+ it { should respond_to(:provider=) }
72
+
73
+ it { should have_alias(:first_name, :firstName) }
74
+ it { should have_alias(:first_name=, :firstName=) }
75
+ it { should have_alias(:last_name, :lastName) }
76
+ it { should have_alias(:last_name=, :lastName=) }
77
+
78
+ describe '#add!' do
79
+ before(:each) do
80
+ mock_api_server(load_json('contact_add'))
81
+ end
82
+
83
+ it 'accepts access credentials hash' do
84
+ lambda do
85
+ subject.add!(client_id: 'client_id', private_key: 'private_key')
86
+ end.should_not raise_error(ArgumentError)
87
+ end
88
+
89
+ it 'uses hashed version of self as request body' do
90
+ subject.should_receive(:to_hash)
91
+ subject.add!
92
+ end
93
+
94
+ it 'updates identifier of contact' do
95
+ lambda do
96
+ subject.add!
97
+ end.should change(subject, :id)
98
+ end
99
+ end
100
+
101
+ describe '#update!' do
102
+ before(:each) do
103
+ mock_api_server(load_json('contact_add'))
104
+ end
105
+
106
+ it 'accepts access credentials hash' do
107
+ lambda do
108
+ subject.update!(client_id: 'client_id', private_key: 'private_key')
109
+ end.should_not raise_error(ArgumentError)
110
+ end
111
+
112
+ it 'uses hashed version of self as request body' do
113
+ subject.should_receive(:to_hash)
114
+ subject.add!
115
+ end
116
+ end
117
+
118
+ describe '#delete!' do
119
+ before(:each) do
120
+ mock_api_server('{ "status": "Ok", "result": { "contact": null }}')
121
+ end
122
+
123
+ it 'accepts access credentials hash' do
124
+ lambda do
125
+ subject.delete!(client_id: 'client_id', private_key: 'private_key')
126
+ end.should_not raise_error(ArgumentError)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Envelope::Log do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ it { should respond_to(:id) }
8
+ it { should respond_to(:id=) }
9
+ it { should respond_to(:date) }
10
+ it { should respond_to(:date=) }
11
+ it { should respond_to(:userName) }
12
+ it { should respond_to(:userName=) }
13
+ it { should respond_to(:action) }
14
+ it { should respond_to(:action=) }
15
+ it { should respond_to(:remoteAddress) }
16
+ it { should respond_to(:remoteAddress=) }
17
+
18
+ it { should have_alias(:user_name, :userName) }
19
+ it { should have_alias(:user_name=, :userName=) }
20
+ it { should have_alias(:remote_address, :remoteAddress) }
21
+ it { should have_alias(:remote_address=, :remoteAddress=) }
22
+
23
+ end
@@ -0,0 +1,296 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Envelope do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+ include_examples GroupDocs::Signature::DocumentMethods
7
+ include_examples GroupDocs::Signature::EntityFields
8
+ include_examples GroupDocs::Signature::EntityMethods
9
+ include_examples GroupDocs::Signature::FieldMethods
10
+ include_examples GroupDocs::Signature::RecipientMethods
11
+ include_examples GroupDocs::Signature::ResourceMethods
12
+
13
+ describe '.all!' do
14
+ before(:each) do
15
+ mock_api_server(load_json('envelopes_all'))
16
+ end
17
+
18
+ it 'accepts access credentials hash' do
19
+ lambda do
20
+ described_class.all!({}, client_id: 'client_id', private_key: 'private_key')
21
+ end.should_not raise_error(ArgumentError)
22
+ end
23
+
24
+ it 'allows passing options' do
25
+ -> { described_class.all!(page: 1, count: 3) }.should_not raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'returns array of GroupDocs::Signature::Envelope objects' do
29
+ envelopes = described_class.all!
30
+ envelopes.should be_an(Array)
31
+ envelopes.each do |envelope|
32
+ envelope.should be_a(GroupDocs::Signature::Envelope)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '.for_me!' do
38
+ before(:each) do
39
+ mock_api_server(load_json('envelopes_all'))
40
+ end
41
+
42
+ it 'accepts access credentials hash' do
43
+ lambda do
44
+ described_class.for_me!({}, client_id: 'client_id', private_key: 'private_key')
45
+ end.should_not raise_error(ArgumentError)
46
+ end
47
+
48
+ it 'allows passing options' do
49
+ -> { described_class.for_me!(page: 1, count: 3) }.should_not raise_error(ArgumentError)
50
+ end
51
+
52
+ it 'returns array of GroupDocs::Signature::Envelope objects' do
53
+ envelopes = described_class.for_me!
54
+ envelopes.should be_an(Array)
55
+ envelopes.each do |envelope|
56
+ envelope.should be_a(GroupDocs::Signature::Envelope)
57
+ end
58
+ end
59
+ end
60
+
61
+ it { should respond_to(:creationDateTime) }
62
+ it { should respond_to(:creationDateTime=) }
63
+ it { should respond_to(:status) }
64
+ it { should respond_to(:status=) }
65
+ it { should respond_to(:statusDateTime) }
66
+ it { should respond_to(:statusDateTime=) }
67
+ it { should respond_to(:envelopeExpireTime) }
68
+ it { should respond_to(:envelopeExpireTime=) }
69
+ it { should respond_to(:status) }
70
+ it { should respond_to(:status=) }
71
+
72
+ it { should have_alias(:creation_date_time, :creationDateTime) }
73
+ it { should have_alias(:creation_date_time=, :creationDateTime=) }
74
+ it { should have_alias(:status_date_time, :statusDateTime) }
75
+ it { should have_alias(:status_date_time=, :statusDateTime=) }
76
+ it { should have_alias(:envelope_expire_time, :envelopeExpireTime) }
77
+ it { should have_alias(:envelope_expire_time=, :envelopeExpireTime=) }
78
+
79
+ describe '#status' do
80
+ it 'converts status to human-readable format' do
81
+ subject.status = 1
82
+ subject.status.should == :in_progress
83
+ end
84
+ end
85
+
86
+ describe '#add_recipient!' do
87
+ let(:recipient) do
88
+ GroupDocs::Signature::Recipient.new
89
+ end
90
+
91
+ before(:each) do
92
+ mock_api_server('{ "status": "Ok", "result": {}}')
93
+ end
94
+
95
+ it 'accepts access credentials hash' do
96
+ lambda do
97
+ subject.add_recipient!(recipient, client_id: 'client_id', private_key: 'private_key')
98
+ end.should_not raise_error(ArgumentError)
99
+ end
100
+
101
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
102
+ -> { subject.add_recipient!('Recipient') }.should raise_error(ArgumentError)
103
+ end
104
+ end
105
+
106
+ describe '#modify_recipient!' do
107
+ let(:recipient) do
108
+ GroupDocs::Signature::Recipient.new
109
+ end
110
+
111
+ before(:each) do
112
+ mock_api_server('{ "status": "Ok", "result": {}}')
113
+ end
114
+
115
+ it 'accepts access credentials hash' do
116
+ lambda do
117
+ subject.modify_recipient!(recipient, client_id: 'client_id', private_key: 'private_key')
118
+ end.should_not raise_error(ArgumentError)
119
+ end
120
+
121
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
122
+ -> { subject.modify_recipient!('Recipient') }.should raise_error(ArgumentError)
123
+ end
124
+ end
125
+
126
+ describe '#fill_field!' do
127
+ let(:field) { GroupDocs::Signature::Field.new(location: { location_x: 0.1, page: 1 }) }
128
+ let(:document) { GroupDocs::Document.new(file: GroupDocs::Storage::File.new) }
129
+ let(:recipient) { GroupDocs::Signature::Recipient.new }
130
+
131
+ before(:each) do
132
+ mock_api_server(load_json('signature_field_add'))
133
+ end
134
+
135
+ it 'accepts access credentials hash' do
136
+ lambda do
137
+ subject.fill_field!('test', field, document, recipient, client_id: 'client_id', private_key: 'private_key')
138
+ end.should_not raise_error(ArgumentError)
139
+ end
140
+
141
+ it 'raises error if field is not GroupDocs::Signature::Field object' do
142
+ -> { subject.fill_field!('test', 'Field', document, recipient) }.should raise_error(ArgumentError)
143
+ end
144
+
145
+ it 'raises error if document is not GroupDocs::Document object' do
146
+ -> { subject.fill_field!('test', field, 'Document', recipient) }.should raise_error(ArgumentError)
147
+ end
148
+
149
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
150
+ -> { subject.fill_field!('test', field, document, 'Recipient') }.should raise_error(ArgumentError)
151
+ end
152
+
153
+ it 'returns filled field' do
154
+ subject.fill_field!('test', field, document, recipient).should be_a(GroupDocs::Signature::Field)
155
+ end
156
+
157
+ it 'uses signature identifier if field is :signature and GroupDocs::Signature is passed' do
158
+ api = stub(GroupDocs::Api::Request)
159
+ api.stub!(execute!: { field: {} })
160
+ GroupDocs::Api::Request.stub(new: api)
161
+ signature = GroupDocs::Signature.new(id: '123')
162
+ api.should_receive(:add_params).with(signatureId: '123')
163
+ field.field_type = :signature
164
+ subject.fill_field!(signature, field, document, recipient)
165
+ end
166
+
167
+ it 'converts boolean value to required string if field is :checkbox' do
168
+ api = stub(GroupDocs::Api::Request)
169
+ options = {}
170
+ api.stub!(execute!: { field: {} })
171
+ api.stub!(options: { request_body: nil })
172
+ GroupDocs::Api::Request.stub(new: api)
173
+ field.field_type = :checkbox
174
+ subject.fill_field!(true, field, document, recipient)
175
+ api.options[:request_body].should == 'on'
176
+ end
177
+ end
178
+
179
+ describe '#sign!' do
180
+ let(:recipient) { GroupDocs::Signature::Recipient.new }
181
+
182
+ before(:each) do
183
+ mock_api_server('{ "status": "Ok", "result": {}}')
184
+ end
185
+
186
+ it 'accepts access credentials hash' do
187
+ lambda do
188
+ subject.sign!(recipient, client_id: 'client_id', private_key: 'private_key')
189
+ end.should_not raise_error(ArgumentError)
190
+ end
191
+
192
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
193
+ -> { subject.sign!('Recipient') }.should raise_error(ArgumentError)
194
+ end
195
+ end
196
+
197
+ describe '#decline!' do
198
+ let(:recipient) { GroupDocs::Signature::Recipient.new }
199
+
200
+ before(:each) do
201
+ mock_api_server('{ "status": "Ok", "result": {}}')
202
+ end
203
+
204
+ it 'accepts access credentials hash' do
205
+ lambda do
206
+ subject.decline!(recipient, client_id: 'client_id', private_key: 'private_key')
207
+ end.should_not raise_error(ArgumentError)
208
+ end
209
+
210
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
211
+ -> { subject.decline!('Recipient') }.should raise_error(ArgumentError)
212
+ end
213
+ end
214
+
215
+ describe '#signed_documents!' do
216
+ before(:each) do
217
+ mock_api_server(File.read('spec/support/files/envelope.zip'))
218
+ subject.stub(name: 'envelope')
219
+ end
220
+
221
+ let(:path) { Dir.tmpdir }
222
+
223
+ it 'accepts access credentials hash' do
224
+ lambda do
225
+ subject.signed_documents!(path, client_id: 'client_id', private_key: 'private_key')
226
+ end.should_not raise_error(ArgumentError)
227
+ end
228
+
229
+ it 'downloads file to given path' do
230
+ file = stub('file')
231
+ Object::File.should_receive(:open).with("#{path}/#{subject.name}.zip", 'w').and_yield(file)
232
+ file.should_receive(:write).with(File.read('spec/support/files/envelope.zip'))
233
+ subject.signed_documents!(path)
234
+ end
235
+
236
+ it 'returns saved file path' do
237
+ subject.signed_documents!(path).should == "#{path}/#{subject.name}.zip"
238
+ end
239
+ end
240
+
241
+ describe '#logs!' do
242
+ before(:each) do
243
+ mock_api_server(load_json('envelope_logs'))
244
+ end
245
+
246
+ it 'accepts access credentials hash' do
247
+ lambda do
248
+ subject.logs!(client_id: 'client_id', private_key: 'private_key')
249
+ end.should_not raise_error(ArgumentError)
250
+ end
251
+
252
+ it 'returns array of GroupDocs::Signature::Envelope::Log objects' do
253
+ logs = subject.logs!
254
+ logs.should be_an(Array)
255
+ logs.each do |log|
256
+ log.should be_a(GroupDocs::Signature::Envelope::Log)
257
+ end
258
+ end
259
+ end
260
+
261
+ describe '#send!' do
262
+ before(:each) do
263
+ mock_api_server('{ "status": "Ok", "result": {}}')
264
+ end
265
+
266
+ it 'accepts access credentials hash' do
267
+ lambda do
268
+ subject.send!(client_id: 'client_id', private_key: 'private_key')
269
+ end.should_not raise_error(ArgumentError)
270
+ end
271
+ end
272
+
273
+ describe '#archive!' do
274
+ before(:each) do
275
+ mock_api_server('{ "status": "Ok", "result": {}}')
276
+ end
277
+
278
+ it 'accepts access credentials hash' do
279
+ lambda do
280
+ subject.archive!(client_id: 'client_id', private_key: 'private_key')
281
+ end.should_not raise_error(ArgumentError)
282
+ end
283
+ end
284
+
285
+ describe '#restart!' do
286
+ before(:each) do
287
+ mock_api_server('{ "status": "Ok", "result": {}}')
288
+ end
289
+
290
+ it 'accepts access credentials hash' do
291
+ lambda do
292
+ subject.restart!(client_id: 'client_id', private_key: 'private_key')
293
+ end.should_not raise_error(ArgumentError)
294
+ end
295
+ end
296
+ end