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
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::List do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe '.get!' do
8
+ before(:each) do
9
+ mock_api_server(load_json('lists_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 'returns array of GroupDocs::Signature::List objects' do
19
+ lists = described_class.get!
20
+ lists.should be_an(Array)
21
+ lists.each do |list|
22
+ list.should be_a(GroupDocs::Signature::List)
23
+ end
24
+ end
25
+ end
26
+
27
+ it { should respond_to(:id) }
28
+ it { should respond_to(:id=) }
29
+ it { should respond_to(:name) }
30
+ it { should respond_to(:name=) }
31
+ it { should respond_to(:values) }
32
+ it { should respond_to(:values=) }
33
+ it { should respond_to(:defaultValue) }
34
+ it { should respond_to(:defaultValue=) }
35
+
36
+ it { should have_alias(:default_value, :defaultValue) }
37
+ it { should have_alias(:default_value=, :defaultValue=) }
38
+
39
+ describe '#values=' do
40
+ it 'converts array of values to a string' do
41
+ subject.values = %w(Test1 Test2)
42
+ subject.instance_variable_get(:@values).should == 'Test1;Test2'
43
+ end
44
+
45
+ it 'does nothing if values is a string' do
46
+ subject.values = 'Test1;Test2'
47
+ subject.instance_variable_get(:@values).should == 'Test1;Test2'
48
+ end
49
+ end
50
+
51
+ describe '#values' do
52
+ it 'returns values as an array' do
53
+ subject.values = 'Test1;Test2'
54
+ subject.values.should == %w(Test1 Test2)
55
+ end
56
+ end
57
+
58
+ describe '#add!' do
59
+ before(:each) do
60
+ mock_api_server(load_json('list_add'))
61
+ end
62
+
63
+ it 'accepts access credentials hash' do
64
+ lambda do
65
+ subject.add!(client_id: 'client_id', private_key: 'private_key')
66
+ end.should_not raise_error(ArgumentError)
67
+ end
68
+
69
+ it 'uses hashed version of self as request body' do
70
+ subject.should_receive(:to_hash)
71
+ subject.add!
72
+ end
73
+
74
+ it 'updates identifier of list' do
75
+ lambda do
76
+ subject.add!
77
+ end.should change(subject, :id)
78
+ end
79
+ end
80
+
81
+ describe '#delete!' do
82
+ before(:each) do
83
+ mock_api_server('{ "status": "Ok", "result": { "list": null }}')
84
+ end
85
+
86
+ it 'accepts access credentials hash' do
87
+ lambda do
88
+ subject.delete!(client_id: 'client_id', private_key: 'private_key')
89
+ end.should_not raise_error(ArgumentError)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Recipient 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(:email) }
10
+ it { should respond_to(:email=) }
11
+ it { should respond_to(:firstName) }
12
+ it { should respond_to(:firstName=) }
13
+ it { should respond_to(:lastName) }
14
+ it { should respond_to(:lastName=) }
15
+ it { should respond_to(:nickname) }
16
+ it { should respond_to(:nickname=) }
17
+ it { should respond_to(:roleId) }
18
+ it { should respond_to(:roleId=) }
19
+ it { should respond_to(:order) }
20
+ it { should respond_to(:order=) }
21
+ it { should respond_to(:status) }
22
+ it { should respond_to(:status=) }
23
+
24
+ it { should have_alias(:first_name, :firstName) }
25
+ it { should have_alias(:first_name=, :firstName=) }
26
+ it { should have_alias(:last_name, :lastName) }
27
+ it { should have_alias(:last_name=, :lastName=) }
28
+ it { should have_alias(:role_id, :roleId) }
29
+ it { should have_alias(:role_id=, :roleId=) }
30
+
31
+ describe '#status' do
32
+ it 'converts status to human-readable format' do
33
+ subject.status = 1
34
+ subject.status.should == :notified
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Role do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe '.get!' do
8
+ before(:each) do
9
+ mock_api_server(load_json('signature_roles_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!(id: "dsaoij3928ukr03") }.should_not raise_error(ArgumentError)
20
+ end
21
+
22
+ it 'returns array of GroupDocs::Signature::Role objects' do
23
+ roles = described_class.get!
24
+ roles.should be_an(Array)
25
+ roles.each do |role|
26
+ role.should be_a(GroupDocs::Signature::Role)
27
+ end
28
+ end
29
+ end
30
+
31
+ it { should respond_to(:id) }
32
+ it { should respond_to(:id=) }
33
+ it { should respond_to(:name) }
34
+ it { should respond_to(:name=) }
35
+ it { should respond_to(:canEdit) }
36
+ it { should respond_to(:canEdit=) }
37
+ it { should respond_to(:canSign) }
38
+ it { should respond_to(:canSign=) }
39
+ it { should respond_to(:canAnnotate) }
40
+ it { should respond_to(:canAnnotate=) }
41
+ it { should respond_to(:canDelegate) }
42
+ it { should respond_to(:canDelegate=) }
43
+
44
+ it { should have_alias(:can_edit, :canEdit) }
45
+ it { should have_alias(:can_edit=, :canEdit=) }
46
+ it { should have_alias(:can_sign, :canSign) }
47
+ it { should have_alias(:can_sign=, :canSign=) }
48
+ it { should have_alias(:can_annotate, :canAnnotate) }
49
+ it { should have_alias(:can_annotate=, :canAnnotate=) }
50
+ it { should have_alias(:can_delegate, :canDelegate) }
51
+ it { should have_alias(:can_delegate=, :canDelegate=) }
52
+
53
+ describe '#can_edit?' do
54
+ it 'returns true if role can edit' do
55
+ subject.can_edit = 1
56
+ subject.can_edit?.should be_true
57
+ end
58
+
59
+ it 'returns false if role cannot edit' do
60
+ subject.can_edit = 0
61
+ subject.can_edit?.should be_false
62
+ end
63
+ end
64
+
65
+ describe '#can_sign?' do
66
+ it 'returns true if role can sign' do
67
+ subject.can_sign = 1
68
+ subject.can_sign?.should be_true
69
+ end
70
+
71
+ it 'returns false if role cannot sign' do
72
+ subject.can_sign = 0
73
+ subject.can_sign?.should be_false
74
+ end
75
+ end
76
+
77
+ describe '#can_annotate?' do
78
+ it 'returns true if role can annotate' do
79
+ subject.can_annotate = 1
80
+ subject.can_annotate?.should be_true
81
+ end
82
+
83
+ it 'returns false if role cannot annotate' do
84
+ subject.can_annotate = 0
85
+ subject.can_annotate?.should be_false
86
+ end
87
+ end
88
+
89
+ describe '#can_delegate?' do
90
+ it 'returns true if role can delegate' do
91
+ subject.can_delegate = 1
92
+ subject.can_delegate?.should be_true
93
+ end
94
+
95
+ it 'returns false if role cannot delegate' do
96
+ subject.can_delegate = 0
97
+ subject.can_delegate?.should be_false
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature::Template 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('templates_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::Template objects' do
29
+ templates = described_class.all!
30
+ templates.should be_an(Array)
31
+ templates.each do |template|
32
+ template.should be_a(GroupDocs::Signature::Template)
33
+ end
34
+ end
35
+ end
36
+
37
+ it { should respond_to(:templateExpireTime) }
38
+ it { should respond_to(:templateExpireTime=) }
39
+
40
+ it { should have_alias(:template_expire_time, :templateExpireTime) }
41
+ it { should have_alias(:template_expire_time=, :templateExpireTime=) }
42
+
43
+ describe '#add_recipient!' do
44
+ let(:recipient) do
45
+ GroupDocs::Signature::Recipient.new
46
+ end
47
+
48
+ before(:each) do
49
+ mock_api_server('{ "status": "Ok", "result": {}}')
50
+ end
51
+
52
+ it 'accepts access credentials hash' do
53
+ lambda do
54
+ subject.add_recipient!(recipient, client_id: 'client_id', private_key: 'private_key')
55
+ end.should_not raise_error(ArgumentError)
56
+ end
57
+
58
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
59
+ -> { subject.add_recipient!('Recipient') }.should raise_error(ArgumentError)
60
+ end
61
+ end
62
+
63
+ describe '#modify_recipient!' do
64
+ let(:recipient) do
65
+ GroupDocs::Signature::Recipient.new
66
+ end
67
+
68
+ before(:each) do
69
+ mock_api_server('{ "status": "Ok", "result": {}}')
70
+ end
71
+
72
+ it 'accepts access credentials hash' do
73
+ lambda do
74
+ subject.modify_recipient!(recipient, client_id: 'client_id', private_key: 'private_key')
75
+ end.should_not raise_error(ArgumentError)
76
+ end
77
+
78
+ it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
79
+ -> { subject.modify_recipient!('Recipient') }.should raise_error(ArgumentError)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Signature do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe '.get!' do
8
+ before(:each) do
9
+ mock_api_server(load_json('signatures_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 'returns array of GroupDocs::Signature objects' do
19
+ signatures = described_class.get!
20
+ signatures.should be_an(Array)
21
+ signatures.each do |signature|
22
+ signature.should be_a(GroupDocs::Signature)
23
+ end
24
+ end
25
+ end
26
+
27
+ it { should respond_to(:id) }
28
+ it { should respond_to(:id=) }
29
+ it { should respond_to(:userGuid) }
30
+ it { should respond_to(:userGuid=) }
31
+ it { should respond_to(:recipientId) }
32
+ it { should respond_to(:recipientId=) }
33
+ it { should respond_to(:name) }
34
+ it { should respond_to(:name=) }
35
+ it { should respond_to(:companyName) }
36
+ it { should respond_to(:companyName=) }
37
+ it { should respond_to(:position) }
38
+ it { should respond_to(:position=) }
39
+ it { should respond_to(:firstName) }
40
+ it { should respond_to(:firstName=) }
41
+ it { should respond_to(:lastName) }
42
+ it { should respond_to(:lastName=) }
43
+ it { should respond_to(:fullName) }
44
+ it { should respond_to(:fullName=) }
45
+ it { should respond_to(:textInitials) }
46
+ it { should respond_to(:textInitials=) }
47
+ it { should respond_to(:signatureImageFileId) }
48
+ it { should respond_to(:signatureImageFileId=) }
49
+ it { should respond_to(:initialsImageFileId) }
50
+ it { should respond_to(:initialsImageFileId=) }
51
+ it { should respond_to(:signatureImageUrl) }
52
+ it { should respond_to(:signatureImageUrl=) }
53
+ it { should respond_to(:initialsImageUrl) }
54
+ it { should respond_to(:initialsImageUrl=) }
55
+ it { should respond_to(:createdTimeStamp) }
56
+ it { should respond_to(:createdTimeStamp=) }
57
+
58
+ it { should have_alias(:user_guid, :userGuid) }
59
+ it { should have_alias(:user_guid=, :userGuid=) }
60
+ it { should have_alias(:recipient_id, :recipientId) }
61
+ it { should have_alias(:recipient_id=, :recipientId=) }
62
+ it { should have_alias(:company_name, :companyName) }
63
+ it { should have_alias(:company_name=, :companyName=) }
64
+ it { should have_alias(:first_name, :firstName) }
65
+ it { should have_alias(:first_name=, :firstName=) }
66
+ it { should have_alias(:last_name, :lastName) }
67
+ it { should have_alias(:last_name=, :lastName=) }
68
+ it { should have_alias(:full_name, :fullName) }
69
+ it { should have_alias(:full_name=, :fullName=) }
70
+ it { should have_alias(:text_initials, :textInitials) }
71
+ it { should have_alias(:text_initials=, :textInitials=) }
72
+ it { should have_alias(:signature_image_file_id, :signatureImageFileId) }
73
+ it { should have_alias(:signature_image_file_id=, :signatureImageFileId=) }
74
+ it { should have_alias(:initials_image_file_id, :initialsImageFileId) }
75
+ it { should have_alias(:initials_image_file_id=, :initialsImageFileId=) }
76
+ it { should have_alias(:signature_image_url, :signatureImageUrl) }
77
+ it { should have_alias(:signature_image_url=, :signatureImageUrl=) }
78
+ it { should have_alias(:initials_image_url, :initialsImageUrl) }
79
+ it { should have_alias(:initials_image_url=, :initialsImageUrl=) }
80
+ it { should have_alias(:created_time_stamp, :createdTimeStamp) }
81
+ it { should have_alias(:created_time_stamp=, :createdTimeStamp=) }
82
+
83
+ describe '#create!' do
84
+ before(:each) do
85
+ mock_api_server(load_json('signature_create'))
86
+ end
87
+
88
+ it 'accepts access credentials hash' do
89
+ lambda do
90
+ subject.create!('Signature', client_id: 'client_id', private_key: 'private_key')
91
+ end.should_not raise_error(ArgumentError)
92
+ end
93
+
94
+ it 'uses hashed version of self as request body' do
95
+ subject.should_receive(:to_hash)
96
+ subject.create!('Signature')
97
+ end
98
+
99
+ it 'updates identifier of signature' do
100
+ lambda do
101
+ subject.create!('Signature')
102
+ end.should change(subject, :id)
103
+ end
104
+ end
105
+
106
+ describe '#delete!' do
107
+ before(:each) do
108
+ mock_api_server('{ "status": "Ok", "result": {}}')
109
+ end
110
+
111
+ it 'accepts access credentials hash' do
112
+ lambda do
113
+ subject.delete!(client_id: 'client_id', private_key: 'private_key')
114
+ end.should_not raise_error(ArgumentError)
115
+ end
116
+ end
117
+ end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe GroupDocs::Storage::File do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
- include_examples GroupDocs::Extensions::Lookup
7
6
  include_examples GroupDocs::Api::Helpers::AccessMode
8
7
 
9
8
  describe '.upload!' do
@@ -13,18 +12,32 @@ describe GroupDocs::Storage::File do
13
12
 
14
13
  it 'accepts access credentials hash' do
15
14
  lambda do
16
- described_class.upload!(__FILE__, '/upload_path', client_id: 'client_id', private_key: 'private_key')
15
+ described_class.upload!(__FILE__, {}, client_id: 'client_id', private_key: 'private_key')
17
16
  end.should_not raise_error(ArgumentError)
18
17
  end
19
18
 
20
- it 'checks that upload path starts with /' do
21
- GroupDocs::Api::Helpers::Path.should_receive(:verify_starts_with_root).with('/upload_path')
22
- described_class.upload!(__FILE__, '/upload_path')
19
+ it 'accepts options hash' do
20
+ lambda do
21
+ described_class.upload!(__FILE__, path: 'folder1')
22
+ end.should_not raise_error(ArgumentError)
23
+ end
24
+
25
+ it 'uses root folder by default' do
26
+ opts = {}
27
+ described_class.upload!(__FILE__, opts)
28
+ opts[:path].should == ''
29
+ end
30
+
31
+ it 'uses file name by default' do
32
+ opts = {}
33
+ described_class.upload!(__FILE__, opts)
34
+ opts[:name].should == Object::File.basename(__FILE__)
23
35
  end
24
36
 
25
- it 'appends filename to upload path if it is not passed' do
26
- GroupDocs::Api::Helpers::Path.should_receive(:append_file_name).with('/upload_path', __FILE__)
27
- described_class.upload!(__FILE__, '/upload_path')
37
+ it 'uses name if passed' do
38
+ opts = { name: 'file.pdf' }
39
+ described_class.upload!(__FILE__, opts)
40
+ opts[:name].should == opts[:name]
28
41
  end
29
42
 
30
43
  it 'returns GroupDocs::Storage::File object' do
@@ -32,6 +45,22 @@ describe GroupDocs::Storage::File do
32
45
  end
33
46
  end
34
47
 
48
+ describe '.upload_web!' do
49
+ before(:each) do
50
+ mock_api_server(load_json('file_upload'))
51
+ end
52
+
53
+ it 'accepts access credentials hash' do
54
+ lambda do
55
+ described_class.upload_web!('http://www.google.com', client_id: 'client_id', private_key: 'private_key')
56
+ end.should_not raise_error(ArgumentError)
57
+ end
58
+
59
+ it 'returns GroupDocs::Storage::File object' do
60
+ described_class.upload_web!('http://www.google.com').should be_a(GroupDocs::Storage::File)
61
+ end
62
+ end
63
+
35
64
  it { should respond_to(:id) }
36
65
  it { should respond_to(:id=) }
37
66
  it { should respond_to(:guid) }
@@ -59,10 +88,7 @@ describe GroupDocs::Storage::File do
59
88
  it { should respond_to(:path) }
60
89
  it { should respond_to(:path=) }
61
90
 
62
- it 'is compatible with response JSON' do
63
- subject.should respond_to(:adj_name=)
64
- subject.method(:adj_name=).should == subject.method(:name=)
65
- end
91
+ it { should have_alias(:adj_name=, :name=) }
66
92
 
67
93
  describe '#type=' do
68
94
  it 'saves type in machine readable format if symbol is passed' do
@@ -108,31 +134,6 @@ describe GroupDocs::Storage::File do
108
134
  end
109
135
  end
110
136
 
111
- describe '#upload!' do
112
- before(:each) do
113
- mock_api_server(load_json('file_upload'))
114
- end
115
-
116
- it 'accepts access credentials hash' do
117
- lambda do
118
- subject.upload!('/', client_id: 'client_id', private_key: 'private_key')
119
- end.should_not raise_error(ArgumentError)
120
- end
121
-
122
- it 'calls upload! class method and pass parameters to it' do
123
- subject = described_class.new(name: File.basename(__FILE__), path: File.dirname(__FILE__))
124
- described_class.should_receive(:upload!).with(__FILE__, '/Folder', {})
125
- subject.upload!('/Folder')
126
- end
127
-
128
- it 'returns new GroupDocs::Storage::File object' do
129
- subject = described_class.new(name: File.basename(__FILE__), path: File.dirname(__FILE__))
130
- new_file = subject.upload!
131
- new_file.should be_a(GroupDocs::Storage::File)
132
- new_file.should_not == subject
133
- end
134
- end
135
-
136
137
  describe '#download!' do
137
138
  before(:each) do
138
139
  mock_api_server(File.read('spec/support/files/resume.pdf'))
@@ -166,28 +167,31 @@ describe GroupDocs::Storage::File do
166
167
 
167
168
  it 'accepts access credentials hash' do
168
169
  lambda do
169
- subject.move!('/resume.pdf', client_id: 'client_id', private_key: 'private_key')
170
+ subject.move!('folder1', {}, client_id: 'client_id', private_key: 'private_key')
170
171
  end.should_not raise_error(ArgumentError)
171
172
  end
172
173
 
173
- it 'checks that path starts with /' do
174
- GroupDocs::Api::Helpers::Path.should_receive(:verify_starts_with_root).with('/resume.pdf')
175
- subject.move!('/resume.pdf')
174
+ it 'accepts options credentials hash' do
175
+ lambda do
176
+ subject.move!('folder1', name: 'file.pdf')
177
+ end.should_not raise_error(ArgumentError)
176
178
  end
177
179
 
178
- it 'appends filename to move to path if it is not passed' do
179
- GroupDocs::Api::Helpers::Path.should_receive(:append_file_name).with('/Folder', subject.name)
180
- subject.move!('/Folder')
180
+ it 'uses current file name by default' do
181
+ subject.name = 'resume.pdf'
182
+ opts = {}
183
+ subject.move!('folder1', opts)
184
+ opts[:name].should == subject.name
181
185
  end
182
186
 
183
- it 'sends "Groupdocs-Move" header' do
184
- mock_api_server(load_json('file_move'), :'Groupdocs-Move' => '123')
185
- subject.stub(id: 123)
186
- subject.move!('/resume2.pdf')
187
+ it 'uses name if passed' do
188
+ opts = { name: 'file.pdf' }
189
+ subject.move!('folder1', opts)
190
+ opts[:name].should == opts[:name]
187
191
  end
188
192
 
189
193
  it 'returns moved to file' do
190
- subject.move!('/resume2.pdf').should be_a(GroupDocs::Storage::File)
194
+ subject.move!('folder1').should be_a(GroupDocs::Storage::File)
191
195
  end
192
196
  end
193
197
 
@@ -203,7 +207,7 @@ describe GroupDocs::Storage::File do
203
207
  end
204
208
 
205
209
  it 'uses #move! to rename file' do
206
- subject.should_receive(:move!).with('/resume2.pdf', {})
210
+ subject.should_receive(:move!).with(subject.path, { name: 'resume2.pdf' }, {})
207
211
  subject.rename!('resume2.pdf')
208
212
  end
209
213
  end
@@ -215,24 +219,27 @@ describe GroupDocs::Storage::File do
215
219
 
216
220
  it 'accepts access credentials hash' do
217
221
  lambda do
218
- subject.copy!('/resume.pdf', client_id: 'client_id', private_key: 'private_key')
222
+ subject.copy!('resume.pdf', {}, client_id: 'client_id', private_key: 'private_key')
219
223
  end.should_not raise_error(ArgumentError)
220
224
  end
221
225
 
222
- it 'checks that path starts with /' do
223
- GroupDocs::Api::Helpers::Path.should_receive(:verify_starts_with_root).with('resume.pdf')
224
- subject.copy!('resume.pdf')
226
+ it 'accepts options credentials hash' do
227
+ lambda do
228
+ subject.copy!('folder1', name: 'file.pdf')
229
+ end.should_not raise_error(ArgumentError)
225
230
  end
226
231
 
227
- it 'appends filename to move to path if it is not passed' do
228
- GroupDocs::Api::Helpers::Path.should_receive(:append_file_name).with('/Folder', subject.name)
229
- subject.copy!('/Folder')
232
+ it 'uses current file name by default' do
233
+ subject.name = 'resume.pdf'
234
+ opts = {}
235
+ subject.copy!('folder1', opts)
236
+ opts[:name].should == subject.name
230
237
  end
231
238
 
232
- it 'sends "Groupdocs-Copy" header' do
233
- mock_api_server(load_json('file_copy'), :'Groupdocs-Copy' => '123')
234
- subject.stub(id: 123)
235
- subject.copy!('/resume2.pdf')
239
+ it 'uses name if passed' do
240
+ opts = { name: 'file.pdf' }
241
+ subject.copy!('folder1', opts)
242
+ opts[:name].should == opts[:name]
236
243
  end
237
244
 
238
245
  it 'returns copied to file' do
@@ -276,6 +283,14 @@ describe GroupDocs::Storage::File do
276
283
  end
277
284
  end
278
285
 
286
+ describe '#move_to_trash!' do
287
+ it 'accepts access credentials hash' do
288
+ lambda do
289
+ subject.move_to_trash!(client_id: 'client_id', private_key: 'private_key')
290
+ end.should_not raise_error(ArgumentError)
291
+ end
292
+ end
293
+
279
294
  describe '#to_document' do
280
295
  it 'creates new GroupDocs::Document' do
281
296
  subject.to_document.should be_a(GroupDocs::Document)