groupdocs 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. data/CHANGELOG.md +41 -0
  2. data/examples/README.md +2 -3
  3. data/examples/api-samples/Gemfile +5 -0
  4. data/examples/api-samples/Gemfile.lock +27 -0
  5. data/examples/api-samples/README.md +12 -0
  6. data/examples/api-samples/app.rb +17 -0
  7. data/examples/api-samples/public/css/style.css +166 -0
  8. data/examples/api-samples/samples/sample1.rb +17 -0
  9. data/examples/api-samples/samples/sample10.rb +36 -0
  10. data/examples/api-samples/samples/sample2.rb +19 -0
  11. data/examples/api-samples/samples/sample3.rb +23 -0
  12. data/examples/api-samples/samples/sample4.rb +31 -0
  13. data/examples/api-samples/samples/sample5.rb +44 -0
  14. data/examples/api-samples/samples/sample6.rb +3 -0
  15. data/examples/api-samples/samples/sample7.rb +33 -0
  16. data/examples/api-samples/samples/sample8.rb +40 -0
  17. data/examples/api-samples/samples/sample9.rb +22 -0
  18. data/examples/api-samples/views/index.haml +23 -0
  19. data/examples/api-samples/views/layout.haml +7 -0
  20. data/examples/api-samples/views/sample1.haml +71 -0
  21. data/examples/api-samples/views/sample10.haml +69 -0
  22. data/examples/api-samples/views/sample2.haml +59 -0
  23. data/examples/api-samples/views/sample3.haml +62 -0
  24. data/examples/api-samples/views/sample4.haml +58 -0
  25. data/examples/api-samples/views/sample5.haml +62 -0
  26. data/examples/api-samples/views/sample6.haml +145 -0
  27. data/examples/api-samples/views/sample7.haml +59 -0
  28. data/examples/api-samples/views/sample8.haml +75 -0
  29. data/examples/api-samples/views/sample9.haml +61 -0
  30. data/examples/{annotations → viewer}/Gemfile +0 -0
  31. data/examples/viewer/app.rb +52 -0
  32. data/groupdocs.gemspec +5 -4
  33. data/lib/groupdocs/api.rb +1 -0
  34. data/lib/groupdocs/api/entity.rb +2 -0
  35. data/lib/groupdocs/api/helpers.rb +2 -0
  36. data/lib/groupdocs/api/helpers/accessor_helper.rb +30 -0
  37. data/lib/groupdocs/api/helpers/mime_helper.rb +21 -0
  38. data/lib/groupdocs/api/helpers/rest_helper.rb +3 -2
  39. data/lib/groupdocs/api/request.rb +1 -3
  40. data/lib/groupdocs/datasource.rb +1 -2
  41. data/lib/groupdocs/document.rb +133 -3
  42. data/lib/groupdocs/document/annotation.rb +14 -13
  43. data/lib/groupdocs/document/annotation/reply.rb +4 -8
  44. data/lib/groupdocs/document/annotation/reviewer.rb +2 -4
  45. data/lib/groupdocs/document/field.rb +10 -8
  46. data/lib/groupdocs/document/rectangle.rb +10 -18
  47. data/lib/groupdocs/job.rb +1 -1
  48. data/lib/groupdocs/questionnaire.rb +138 -44
  49. data/lib/groupdocs/questionnaire/collector.rb +262 -0
  50. data/lib/groupdocs/questionnaire/execution.rb +93 -10
  51. data/lib/groupdocs/questionnaire/question.rb +1 -2
  52. data/lib/groupdocs/signature.rb +16 -24
  53. data/lib/groupdocs/signature/contact.rb +2 -4
  54. data/lib/groupdocs/signature/envelope.rb +3 -6
  55. data/lib/groupdocs/signature/envelope/log.rb +2 -4
  56. data/lib/groupdocs/signature/field.rb +21 -42
  57. data/lib/groupdocs/signature/field/location.rb +18 -36
  58. data/lib/groupdocs/signature/form.rb +9 -18
  59. data/lib/groupdocs/signature/list.rb +1 -2
  60. data/lib/groupdocs/signature/recipient.rb +3 -6
  61. data/lib/groupdocs/signature/role.rb +4 -8
  62. data/lib/groupdocs/signature/shared/entity_fields.rb +12 -20
  63. data/lib/groupdocs/signature/template.rb +1 -2
  64. data/lib/groupdocs/storage/file.rb +3 -1
  65. data/lib/groupdocs/storage/folder.rb +7 -1
  66. data/lib/groupdocs/subscription.rb +6 -12
  67. data/lib/groupdocs/subscription/limit.rb +4 -8
  68. data/lib/groupdocs/user.rb +3 -6
  69. data/lib/groupdocs/version.rb +1 -1
  70. data/spec/groupdocs/api/helpers/accessor_helper_spec.rb +16 -0
  71. data/spec/groupdocs/api/helpers/mime_helper_spec.rb +16 -0
  72. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +4 -0
  73. data/spec/groupdocs/api/request_spec.rb +3 -5
  74. data/spec/groupdocs/datasource/field_spec.rb +3 -6
  75. data/spec/groupdocs/datasource_spec.rb +8 -15
  76. data/spec/groupdocs/document/annotation/reply_spec.rb +13 -24
  77. data/spec/groupdocs/document/annotation/reviewer_spec.rb +5 -9
  78. data/spec/groupdocs/document/annotation_spec.rb +35 -40
  79. data/spec/groupdocs/document/change_spec.rb +6 -11
  80. data/spec/groupdocs/document/field_spec.rb +13 -13
  81. data/spec/groupdocs/document/metadata_spec.rb +5 -10
  82. data/spec/groupdocs/document/rectangle_spec.rb +6 -18
  83. data/spec/groupdocs/document/view_spec.rb +3 -6
  84. data/spec/groupdocs/document_spec.rb +123 -10
  85. data/spec/groupdocs/job_spec.rb +9 -18
  86. data/spec/groupdocs/questionnaire/collector_spec.rb +201 -0
  87. data/spec/groupdocs/questionnaire/execution_spec.rb +91 -23
  88. data/spec/groupdocs/questionnaire/page_spec.rb +3 -6
  89. data/spec/groupdocs/questionnaire/question/answer_spec.rb +2 -4
  90. data/spec/groupdocs/questionnaire/question_spec.rb +7 -14
  91. data/spec/groupdocs/questionnaire_spec.rb +117 -41
  92. data/spec/groupdocs/signature/contact_spec.rb +9 -17
  93. data/spec/groupdocs/signature/envelope/log_spec.rb +8 -16
  94. data/spec/groupdocs/signature/envelope_spec.rb +9 -17
  95. data/spec/groupdocs/signature/field/location_spec.rb +32 -65
  96. data/spec/groupdocs/signature/field_spec.rb +48 -95
  97. data/spec/groupdocs/signature/form_spec.rb +22 -43
  98. data/spec/groupdocs/signature/list_spec.rb +6 -11
  99. data/spec/groupdocs/signature/recipient_spec.rb +11 -22
  100. data/spec/groupdocs/signature/role_spec.rb +11 -21
  101. data/spec/groupdocs/signature/template_spec.rb +2 -4
  102. data/spec/groupdocs/signature_spec.rb +28 -54
  103. data/spec/groupdocs/storage/file_spec.rb +14 -26
  104. data/spec/groupdocs/storage/folder_spec.rb +16 -22
  105. data/spec/groupdocs/storage/package_spec.rb +2 -4
  106. data/spec/groupdocs/subscription/limit_spec.rb +8 -16
  107. data/spec/groupdocs/subscription_spec.rb +11 -22
  108. data/spec/groupdocs/user_spec.rb +21 -41
  109. data/spec/groupdocs_spec.rb +4 -8
  110. data/spec/spec_helper.rb +12 -0
  111. data/spec/support/files/signature.png +0 -0
  112. data/spec/support/json/annotation_list.json +6 -6
  113. data/spec/support/json/comparison_changes.json +8 -8
  114. data/spec/support/json/document_fields.json +8 -8
  115. data/spec/support/json/document_page_images_get.json +20 -0
  116. data/spec/support/json/questionnaire_collector.json +17 -0
  117. data/spec/support/json/questionnaire_collectors.json +38 -0
  118. data/spec/support/json/questionnaire_collectors_add.json +10 -0
  119. data/spec/support/json/questionnaire_create.json +3 -1
  120. data/spec/support/json/{questionnaire_execution_create.json → questionnaire_execution_add.json} +1 -1
  121. data/spec/support/json/questionnaire_get.json +3 -0
  122. data/spec/support/json/questionnaires_get.json +36 -18
  123. data/spec/support/json/sign_documents.json +16 -0
  124. data/spec/support/json/templates_get.json +21 -0
  125. data/spec/support/shared_examples/api/entity.rb +2 -0
  126. data/spec/support/shared_examples/api/helpers/access_mode_helper.rb +1 -2
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +1 -2
  128. data/spec/support/shared_examples/signature/shared/entity_fields.rb +22 -43
  129. metadata +82 -16
  130. data/examples/annotations/app.rb +0 -67
@@ -4,16 +4,11 @@ describe GroupDocs::Document::Change do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
- it { should respond_to(:id) }
8
- it { should respond_to(:id=) }
9
- it { should respond_to(:type) }
10
- it { should respond_to(:type=) }
11
- it { should respond_to(:box) }
12
- it { should respond_to(:box=) }
13
- it { should respond_to(:text) }
14
- it { should respond_to(:text=) }
15
- it { should respond_to(:page) }
16
- it { should respond_to(:page=) }
7
+ it { should have_accessor(:id) }
8
+ it { should have_accessor(:type) }
9
+ it { should have_accessor(:box) }
10
+ it { should have_accessor(:text) }
11
+ it { should have_accessor(:page) }
17
12
 
18
13
  describe '#type' do
19
14
  it 'returns type as symbol' do
@@ -24,7 +19,7 @@ describe GroupDocs::Document::Change do
24
19
 
25
20
  describe '#box=' do
26
21
  it 'converts passed hash to GroupDocs::Document::Rectangle object' do
27
- subject.box = { X: 0.90, Y: 0.05, Width: 0.06745, Height: 0.005967 }
22
+ subject.box = { x: 0.90, y: 0.05, width: 0.06745, height: 0.005967 }
28
23
  subject.box.should be_a(GroupDocs::Document::Rectangle)
29
24
  subject.box.x.should == 0.90
30
25
  subject.box.y.should == 0.05
@@ -1,28 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe GroupDocs::Document::Field do
4
-
5
4
  it_behaves_like GroupDocs::Api::Entity
6
5
 
7
- it { should respond_to(:page) }
8
- it { should respond_to(:page=) }
9
- it { should respond_to(:name) }
10
- it { should respond_to(:name=) }
11
- it { should respond_to(:type) }
12
- it { should respond_to(:type=) }
13
- it { should respond_to(:rectangle) }
14
- it { should respond_to(:rectangle=) }
15
-
16
- it { should have_alias(:rect=, :rectangle=) }
6
+ it { should have_accessor(:page) }
7
+ it { should have_accessor(:name) }
8
+ it { should have_accessor(:type) }
9
+ it { should have_accessor(:rect) }
17
10
 
18
- describe '#rectangle=' do
11
+ describe '#rect=' do
19
12
  it 'converts passed hash to GroupDocs::Document::Rectangle object' do
20
- subject.rectangle = { X: 0.90, Y: 0.05, Width: 0.06745, Height: 0.005967 }
13
+ subject.rect = { x: 0.90, y: 0.05, width: 0.06745, height: 0.005967 }
21
14
  subject.rectangle.should be_a(GroupDocs::Document::Rectangle)
22
15
  subject.rectangle.x.should == 0.90
23
16
  subject.rectangle.y.should == 0.05
24
17
  subject.rectangle.w.should == 0.06745
25
18
  subject.rectangle.h.should == 0.005967
26
19
  end
20
+
21
+ it 'does nothing when nil is passed' do
22
+ subject.rect = nil
23
+ subject.rectangle.should be_nil
24
+ end
27
25
  end
26
+
27
+ it { should alias_accessor(:rectangle, :rect) }
28
28
  end
@@ -4,16 +4,11 @@ describe GroupDocs::Document::MetaData do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
- it { should respond_to(:id) }
8
- it { should respond_to(:id=) }
9
- it { should respond_to(:guid) }
10
- it { should respond_to(:guid=) }
11
- it { should respond_to(:page_count) }
12
- it { should respond_to(:page_count=) }
13
- it { should respond_to(:views_count) }
14
- it { should respond_to(:views_count=) }
15
- it { should respond_to(:last_view) }
16
- it { should respond_to(:last_view=) }
7
+ it { should have_accessor(:id) }
8
+ it { should have_accessor(:guid) }
9
+ it { should have_accessor(:page_count) }
10
+ it { should have_accessor(:views_count) }
11
+ it { should have_accessor(:last_view) }
17
12
 
18
13
  describe '#last_view=' do
19
14
  it 'converts passed hash to GroupDocs::Document::View object' do
@@ -4,23 +4,11 @@ describe GroupDocs::Document::Rectangle do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
- it { should respond_to(:X) }
8
- it { should respond_to(:X=) }
9
- it { should respond_to(:Y) }
10
- it { should respond_to(:Y=) }
11
- it { should respond_to(:Width) }
12
- it { should respond_to(:Width=) }
13
- it { should respond_to(:Height) }
14
- it { should respond_to(:Height=) }
7
+ it { should have_accessor(:x) }
8
+ it { should have_accessor(:y) }
9
+ it { should have_accessor(:width) }
10
+ it { should have_accessor(:height) }
15
11
 
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) }
12
+ it { should alias_accessor(:w, :width) }
13
+ it { should alias_accessor(:h, :height) }
26
14
  end
@@ -4,12 +4,9 @@ describe GroupDocs::Document::View do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
- it { should respond_to(:document) }
8
- it { should respond_to(:document=) }
9
- it { should respond_to(:short_url) }
10
- it { should respond_to(:short_url=) }
11
- it { should respond_to(:viewed_on) }
12
- it { should respond_to(:viewed_on=) }
7
+ it { should have_accessor(:document) }
8
+ it { should have_accessor(:short_url) }
9
+ it { should have_accessor(:viewed_on) }
13
10
 
14
11
  describe '#document=' do
15
12
  it 'sets document if GroupDocs::Document object is passed' do
@@ -30,16 +30,103 @@ describe GroupDocs::Document do
30
30
  end
31
31
  end
32
32
 
33
- it { should respond_to(:file) }
34
- it { should respond_to(:file=) }
35
- it { should respond_to(:process_date) }
36
- it { should respond_to(:process_date=) }
37
- it { should respond_to(:outputs) }
38
- it { should respond_to(:outputs=) }
39
- it { should respond_to(:output_formats) }
40
- it { should respond_to(:output_formats=) }
41
- it { should respond_to(:order) }
42
- it { should respond_to(:order=) }
33
+ describe '.templates!' do
34
+ before(:each) do
35
+ mock_api_server(load_json('templates_get'))
36
+ end
37
+
38
+ it 'accepts access credentials hash' do
39
+ lambda do
40
+ described_class.templates!(client_id: 'client_id', private_key: 'private_key')
41
+ end.should_not raise_error(ArgumentError)
42
+ end
43
+
44
+ it 'returns an array of GroupDocs::Document objects' do
45
+ templates = described_class.templates!
46
+ templates.should be_an(Array)
47
+ templates.each do |template|
48
+ template.should be_a(GroupDocs::Document)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '.sign_documents!' do
54
+ before(:each) do
55
+ mock_api_server(load_json('sign_documents'))
56
+ end
57
+
58
+ let(:documents) do
59
+ [GroupDocs::Document.new(file: GroupDocs::Storage::File.new(name: 'Document1', local_path: __FILE__)),
60
+ GroupDocs::Document.new(file: GroupDocs::Storage::File.new(name: 'Document2', local_path: 'spec/support/files/resume.pdf'))]
61
+ end
62
+ let(:signatures) { [GroupDocs::Signature.new(name: 'John Smith', image_path: 'spec/support/files/signature.png', position: {})] }
63
+
64
+ it 'accepts access credentials hash' do
65
+ lambda do
66
+ described_class.sign_documents!(documents, signatures, {}, client_id: 'client_id', private_key: 'private_key')
67
+ end.should_not raise_error(ArgumentError)
68
+ end
69
+
70
+ it 'raises error if document is not GroupDocs::Document object' do
71
+ -> { described_class.sign_documents!(['Document'], signatures) }.should raise_error(ArgumentError)
72
+ end
73
+
74
+ it 'raises error if document file does not have name' do
75
+ documents = [GroupDocs::Document.new(file: GroupDocs::Storage::File.new(local_path: __FILE__))]
76
+ -> { described_class.sign_documents!(documents, signatures) }.should raise_error(ArgumentError)
77
+ end
78
+
79
+ it 'raises error if document file does not have local path' do
80
+ documents = [GroupDocs::Document.new(file: GroupDocs::Storage::File.new(name: 'Document'))]
81
+ -> { described_class.sign_documents!(documents, signatures) }.should raise_error(ArgumentError)
82
+ end
83
+
84
+ it 'raises error if signature is not GroupDocs::Signature object' do
85
+ -> { described_class.sign_documents!(documents, ['Signature']) }.should raise_error(ArgumentError)
86
+ end
87
+
88
+ it 'raises error if signature does not have name' do
89
+ signatures = [GroupDocs::Signature.new(image_path: __FILE__, position: {})]
90
+ -> { described_class.sign_documents!(documents, signatures) }.should raise_error(ArgumentError)
91
+ end
92
+
93
+ it 'raises error if signature does not have image path' do
94
+ signatures = [GroupDocs::Signature.new(name: 'John Smith', position: {})]
95
+ -> { described_class.sign_documents!(documents, signatures) }.should raise_error(ArgumentError)
96
+ end
97
+
98
+ it 'raises error if signature does not have position' do
99
+ signatures = [GroupDocs::Signature.new(name: 'John Smith', image_path: __FILE__)]
100
+ -> { described_class.sign_documents!(documents, signatures) }.should raise_error(ArgumentError)
101
+ end
102
+
103
+ it 'detects each document and signature file MIME type' do
104
+ documents.each { |document| described_class.should_receive(:mime_type).with(document.file.local_path).once }
105
+ signatures.each { |signature| described_class.should_receive(:mime_type).with(signature.image_path).once }
106
+ described_class.sign_documents!(documents, signatures)
107
+ end
108
+
109
+ it 'returns array of GroupDocs::Document.objects' do
110
+ signed_documents = described_class.sign_documents!(documents, signatures)
111
+ signed_documents.should be_an(Array)
112
+ signed_documents.each do |document|
113
+ document.should be_a(GroupDocs::Document)
114
+ end
115
+ end
116
+
117
+ it 'calculates file name for each signed document' do
118
+ signed_documents = described_class.sign_documents!(documents, signatures)
119
+ signed_documents[0].file.name.should == "#{documents[0].file.name}_signed.pdf"
120
+ signed_documents[1].file.name.should == "#{documents[1].file.name}_signed.pdf"
121
+ end
122
+ end
123
+
124
+ it { should have_accessor(:file) }
125
+ it { should have_accessor(:process_date) }
126
+ it { should have_accessor(:outputs) }
127
+ it { should have_accessor(:output_formats) }
128
+ it { should have_accessor(:order) }
129
+ it { should have_accessor(:field_count) }
43
130
 
44
131
  it { should have_alias(:access_mode=, :access_mode_set!) }
45
132
 
@@ -91,6 +178,32 @@ describe GroupDocs::Document do
91
178
  end
92
179
  end
93
180
 
181
+ describe '#page_images!' do
182
+ before(:each) do
183
+ mock_api_server(load_json('document_page_images_get'))
184
+ end
185
+
186
+ it 'accepts access credentials hash' do
187
+ lambda do
188
+ subject.page_images!(640, 480, {}, client_id: 'client_id', private_key: 'private_key')
189
+ end.should_not raise_error(ArgumentError)
190
+ end
191
+
192
+ it 'accepts options hash' do
193
+ lambda do
194
+ subject.page_images!(640, 480, first_page: 0, page_count: 1)
195
+ end.should_not raise_error(ArgumentError)
196
+ end
197
+
198
+ it 'returns array of URLs' do
199
+ urls = subject.page_images!(640, 480)
200
+ urls.should be_an(Array)
201
+ urls.each do |url|
202
+ url.should be_a(String)
203
+ end
204
+ end
205
+ end
206
+
94
207
  describe '#access_mode!' do
95
208
  before(:each) do
96
209
  mock_api_server(load_json('document_access_info_get'))
@@ -80,24 +80,15 @@ describe GroupDocs::Job do
80
80
  end
81
81
  end
82
82
 
83
- it { should respond_to(:id) }
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=) }
91
- it { should respond_to(:actions) }
92
- it { should respond_to(:actions=) }
93
- it { should respond_to(:email_results) }
94
- it { should respond_to(:email_results=) }
95
- it { should respond_to(:url_only) }
96
- it { should respond_to(:url_only=) }
97
- it { should respond_to(:documents) }
98
- it { should respond_to(:documents=) }
99
- it { should respond_to(:requested_time) }
100
- it { should respond_to(:requested_time=) }
83
+ it { should have_accessor(:id) }
84
+ it { should have_accessor(:guid) }
85
+ it { should have_accessor(:name) }
86
+ it { should have_accessor(:priority) }
87
+ it { should have_accessor(:actions) }
88
+ it { should have_accessor(:email_results) }
89
+ it { should have_accessor(:url_only) }
90
+ it { should have_accessor(:documents) }
91
+ it { should have_accessor(:requested_time) }
101
92
 
102
93
  describe '#documents=' do
103
94
  let(:response) do
@@ -0,0 +1,201 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Questionnaire::Collector do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+ include_examples GroupDocs::Api::Helpers::Status
7
+
8
+ subject do
9
+ questionnaire = GroupDocs::Questionnaire.new
10
+ described_class.new(questionnaire: questionnaire)
11
+ end
12
+
13
+ describe '.get!' do
14
+ before(:each) do
15
+ mock_api_server(load_json('questionnaire_collector'))
16
+ end
17
+
18
+ it 'accepts access credentials hash' do
19
+ lambda do
20
+ described_class.get!('9fh349hfdskf', client_id: 'client_id', private_key: 'private_key')
21
+ end.should_not raise_error(ArgumentError)
22
+ end
23
+
24
+ it 'returns GroupDocs::Questionnaire::Collector object' do
25
+ described_class.get!('9fh349hfdskf').should be_a(GroupDocs::Questionnaire::Collector)
26
+ end
27
+ end
28
+
29
+ it { should have_accessor(:id) }
30
+ it { should have_accessor(:guid) }
31
+ it { should have_accessor(:questionnaire) }
32
+ it { should have_accessor(:questionnaire_id) }
33
+ it { should have_accessor(:type) }
34
+ it { should have_accessor(:resolved_executions) }
35
+ it { should have_accessor(:emails) }
36
+ it { should have_accessor(:modified) }
37
+
38
+ describe '#initialize' do
39
+ it 'raises error if questionnaire is not specified' do
40
+ -> { described_class.new }.should raise_error(ArgumentError)
41
+ end
42
+
43
+ it 'raises error if questionnaire is not an instance of GroupDocs::Questionnaire' do
44
+ -> { described_class.new(questionnaire: '') }.should raise_error(ArgumentError)
45
+ end
46
+ end
47
+
48
+ describe '#type=' do
49
+ it 'saves type in machine readable format if symbol is passed' do
50
+ subject.type = :binary
51
+ subject.instance_variable_get(:@type).should == 'Binary'
52
+ end
53
+
54
+ it 'does nothing if parameter is not symbol' do
55
+ subject.type = 'Binary'
56
+ subject.instance_variable_get(:@type).should == 'Binary'
57
+ end
58
+ end
59
+
60
+ describe '#type' do
61
+ it 'returns converted to human-readable format type' do
62
+ subject.should_receive(:parse_status).with('Embedded').and_return(:embedded)
63
+ subject.type = 'Embedded'
64
+ subject.type.should == :embedded
65
+ end
66
+ end
67
+
68
+ describe '#modified' do
69
+ it 'returns converted to Time object Unix timestamp' do
70
+ subject.modified = 1330450135000
71
+ subject.modified.should == Time.at(1330450135)
72
+ end
73
+ end
74
+
75
+ describe '#add!' do
76
+ before(:each) do
77
+ mock_api_server(load_json('questionnaire_collectors_add'))
78
+ end
79
+
80
+ it 'accepts access credentials hash' do
81
+ lambda do
82
+ subject.add!(client_id: 'client_id', private_key: 'private_key')
83
+ end.should_not raise_error(ArgumentError)
84
+ end
85
+
86
+ it 'gets questionnaire id' do
87
+ subject.questionnaire.should_receive(:guid)
88
+ subject.add!
89
+ end
90
+
91
+ it 'updates id and guid with response' do
92
+ lambda do
93
+ subject.add!
94
+ end.should change {
95
+ subject.id
96
+ subject.guid
97
+ }
98
+ end
99
+ end
100
+
101
+ describe '#update!' do
102
+ before(:each) do
103
+ mock_api_server('{ "status": "Ok", "result": { "collector_id": 123456 }}')
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
+ end
112
+
113
+ describe '#remove!' do
114
+ before(:each) do
115
+ mock_api_server('{ "status": "Ok", "result": {}}')
116
+ end
117
+
118
+ it 'accepts access credentials hash' do
119
+ lambda do
120
+ subject.remove!(client_id: 'client_id', private_key: 'private_key')
121
+ end.should_not raise_error(ArgumentError)
122
+ end
123
+ end
124
+
125
+ describe '#executions!' do
126
+ before(:each) do
127
+ mock_api_server(load_json('questionnaire_executions'))
128
+ end
129
+
130
+ it 'accepts access credentials hash' do
131
+ lambda do
132
+ subject.executions!(client_id: 'client_id', private_key: 'private_key')
133
+ end.should_not raise_error(ArgumentError)
134
+ end
135
+
136
+ it 'returns an array of GroupDocs::Questionnaire::Execution objects' do
137
+ executions = subject.executions!
138
+ executions.should be_an(Array)
139
+ executions.each do |execution|
140
+ execution.should be_a(GroupDocs::Questionnaire::Execution)
141
+ end
142
+ end
143
+ end
144
+
145
+ describe '#add_execution!' do
146
+ before(:each) do
147
+ mock_api_server(load_json('questionnaire_execution_add'))
148
+ end
149
+
150
+ let(:execution) { GroupDocs::Questionnaire::Execution.new }
151
+
152
+ it 'accepts access credentials hash' do
153
+ lambda do
154
+ subject.add_execution!(execution, client_id: 'client_id', private_key: 'private_key')
155
+ end.should_not raise_error(ArgumentError)
156
+ end
157
+
158
+ it 'raises error if execution is not GroupDocs::Questionnaire::Execution object' do
159
+ -> { subject.add_execution!('Execution') }.should raise_error(ArgumentError)
160
+ end
161
+
162
+ it 'uses hashed version of execution along with executive payload' do
163
+ execution.should_receive(:to_hash)
164
+ subject.add_execution!(execution)
165
+ end
166
+
167
+ it 'returns GroupDocs::Questionnaire::Execution object' do
168
+ subject.add_execution!(execution).should be_a(GroupDocs::Questionnaire::Execution)
169
+ end
170
+ end
171
+
172
+ describe '#fill!' do
173
+ before(:each) do
174
+ mock_api_server(load_json('document_datasource'))
175
+ end
176
+
177
+ let(:datasource) do
178
+ GroupDocs::DataSource.new(id: 1)
179
+ end
180
+
181
+ it 'accepts access credentials hash' do
182
+ lambda do
183
+ subject.fill!(datasource, {}, client_id: 'client_id', private_key: 'private_key')
184
+ end.should_not raise_error(ArgumentError)
185
+ end
186
+
187
+ it 'accepts options hash' do
188
+ lambda do
189
+ subject.fill!(datasource, new_type: :pdf)
190
+ end.should_not raise_error(ArgumentError)
191
+ end
192
+
193
+ it 'raises error if datasource is not GroupDocs::Datasource object' do
194
+ -> { subject.fill!('Datasource') }.should raise_error(ArgumentError)
195
+ end
196
+
197
+ it 'returns GroupDocs::Job object' do
198
+ subject.fill!(datasource).should be_a(GroupDocs::Job)
199
+ end
200
+ end
201
+ end