groupdocs 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +3 -0
  3. data/README.md +141 -0
  4. data/Rakefile +9 -0
  5. data/groupdocs.gemspec +28 -0
  6. data/lib/groupdocs.rb +53 -0
  7. data/lib/groupdocs/api.rb +3 -0
  8. data/lib/groupdocs/api/entity.rb +113 -0
  9. data/lib/groupdocs/api/helpers.rb +5 -0
  10. data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
  11. data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
  12. data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
  13. data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
  14. data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
  15. data/lib/groupdocs/api/request.rb +73 -0
  16. data/lib/groupdocs/api/sugar/lookup.rb +48 -0
  17. data/lib/groupdocs/datasource.rb +162 -0
  18. data/lib/groupdocs/datasource/field.rb +44 -0
  19. data/lib/groupdocs/document.rb +513 -0
  20. data/lib/groupdocs/document/annotation.rb +215 -0
  21. data/lib/groupdocs/document/annotation/reply.rb +167 -0
  22. data/lib/groupdocs/document/change.rb +35 -0
  23. data/lib/groupdocs/document/field.rb +27 -0
  24. data/lib/groupdocs/document/metadata.rb +26 -0
  25. data/lib/groupdocs/document/rectangle.rb +24 -0
  26. data/lib/groupdocs/document/view.rb +36 -0
  27. data/lib/groupdocs/errors.rb +10 -0
  28. data/lib/groupdocs/job.rb +201 -0
  29. data/lib/groupdocs/questionnaire.rb +221 -0
  30. data/lib/groupdocs/questionnaire/execution.rb +120 -0
  31. data/lib/groupdocs/questionnaire/page.rb +43 -0
  32. data/lib/groupdocs/questionnaire/question.rb +75 -0
  33. data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
  34. data/lib/groupdocs/storage.rb +37 -0
  35. data/lib/groupdocs/storage/file.rb +248 -0
  36. data/lib/groupdocs/storage/folder.rb +314 -0
  37. data/lib/groupdocs/storage/package.rb +42 -0
  38. data/lib/groupdocs/user.rb +50 -0
  39. data/lib/groupdocs/version.rb +3 -0
  40. data/spec/groupdocs/api/entity_spec.rb +54 -0
  41. data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
  42. data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
  43. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
  44. data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
  45. data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
  46. data/spec/groupdocs/api/request_spec.rb +85 -0
  47. data/spec/groupdocs/datasource/field_spec.rb +50 -0
  48. data/spec/groupdocs/datasource_spec.rb +156 -0
  49. data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
  50. data/spec/groupdocs/document/annotation_spec.rb +226 -0
  51. data/spec/groupdocs/document/change_spec.rb +35 -0
  52. data/spec/groupdocs/document/field_spec.rb +31 -0
  53. data/spec/groupdocs/document/metadata_spec.rb +26 -0
  54. data/spec/groupdocs/document/rectangle_spec.rb +34 -0
  55. data/spec/groupdocs/document/view_spec.rb +36 -0
  56. data/spec/groupdocs/document_spec.rb +509 -0
  57. data/spec/groupdocs/errors_spec.rb +7 -0
  58. data/spec/groupdocs/job_spec.rb +196 -0
  59. data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
  60. data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
  61. data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
  62. data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
  63. data/spec/groupdocs/questionnaire_spec.rb +217 -0
  64. data/spec/groupdocs/storage/file_spec.rb +242 -0
  65. data/spec/groupdocs/storage/folder_spec.rb +310 -0
  66. data/spec/groupdocs/storage/package_spec.rb +41 -0
  67. data/spec/groupdocs/storage_spec.rb +27 -0
  68. data/spec/groupdocs/user_spec.rb +53 -0
  69. data/spec/groupdocs_spec.rb +56 -0
  70. data/spec/spec_helper.rb +46 -0
  71. data/spec/support/files/resume.pdf +0 -0
  72. data/spec/support/json/annotation_collaborators_set.json +16 -0
  73. data/spec/support/json/annotation_create.json +12 -0
  74. data/spec/support/json/annotation_list.json +32 -0
  75. data/spec/support/json/annotation_remove.json +9 -0
  76. data/spec/support/json/annotation_replies_create.json +9 -0
  77. data/spec/support/json/annotation_replies_get.json +25 -0
  78. data/spec/support/json/comparison_changes.json +46 -0
  79. data/spec/support/json/comparison_compare.json +8 -0
  80. data/spec/support/json/comparison_document.json +10 -0
  81. data/spec/support/json/datasource_add.json +8 -0
  82. data/spec/support/json/datasource_get.json +22 -0
  83. data/spec/support/json/datasource_remove.json +8 -0
  84. data/spec/support/json/datasource_update.json +8 -0
  85. data/spec/support/json/document_access_info_get.json +14 -0
  86. data/spec/support/json/document_convert.json +8 -0
  87. data/spec/support/json/document_datasource.json +10 -0
  88. data/spec/support/json/document_fields.json +34 -0
  89. data/spec/support/json/document_formats.json +8 -0
  90. data/spec/support/json/document_metadata.json +15 -0
  91. data/spec/support/json/document_questionnaire_create.json +9 -0
  92. data/spec/support/json/document_questionnaires.json +23 -0
  93. data/spec/support/json/document_sharers_remove.json +8 -0
  94. data/spec/support/json/document_sharers_set.json +16 -0
  95. data/spec/support/json/document_views.json +32 -0
  96. data/spec/support/json/file_compress.json +8 -0
  97. data/spec/support/json/file_copy.json +14 -0
  98. data/spec/support/json/file_delete.json +5 -0
  99. data/spec/support/json/file_move.json +14 -0
  100. data/spec/support/json/file_upload.json +8 -0
  101. data/spec/support/json/folder_create.json +8 -0
  102. data/spec/support/json/folder_delete.json +5 -0
  103. data/spec/support/json/folder_list.json +21 -0
  104. data/spec/support/json/folder_move.json +8 -0
  105. data/spec/support/json/folder_sharers_get.json +16 -0
  106. data/spec/support/json/folder_sharers_remove.json +8 -0
  107. data/spec/support/json/folder_sharers_set.json +16 -0
  108. data/spec/support/json/job_add_url.json +8 -0
  109. data/spec/support/json/job_create.json +8 -0
  110. data/spec/support/json/job_documents.json +39 -0
  111. data/spec/support/json/job_file_add.json +8 -0
  112. data/spec/support/json/job_update.json +7 -0
  113. data/spec/support/json/jobs_get.json +52 -0
  114. data/spec/support/json/package_create.json +7 -0
  115. data/spec/support/json/questionnaire_create.json +8 -0
  116. data/spec/support/json/questionnaire_datasources.json +26 -0
  117. data/spec/support/json/questionnaire_execution_create.json +9 -0
  118. data/spec/support/json/questionnaire_execution_status_set.json +8 -0
  119. data/spec/support/json/questionnaire_execution_update.json +8 -0
  120. data/spec/support/json/questionnaire_executions.json +24 -0
  121. data/spec/support/json/questionnaire_get.json +14 -0
  122. data/spec/support/json/questionnaire_remove.json +8 -0
  123. data/spec/support/json/questionnaire_update.json +8 -0
  124. data/spec/support/json/questionnaires_get.json +22 -0
  125. data/spec/support/json/storage_info.json +10 -0
  126. data/spec/support/shared_examples/api/entity.rb +37 -0
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
  128. data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
  129. metadata +356 -0
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ %w(NoClientIdError NoPrivateKeyError UnsupportedMethodError BadResponseError).each do |error|
4
+ describe GroupDocs::Errors.const_get(error) do
5
+ it { should be_a(StandardError) }
6
+ end
7
+ end
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Job do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+ include_examples GroupDocs::Api::Helpers::Status
7
+
8
+ describe '.all!' do
9
+ before(:each) do
10
+ mock_api_server(load_json('jobs_get'))
11
+ end
12
+
13
+ it 'accepts access credentials hash' do
14
+ lambda do
15
+ described_class.all!({}, client_id: 'client_id', private_key: 'private_key')
16
+ end.should_not raise_error(ArgumentError)
17
+ end
18
+
19
+ it 'accepts options hash' do
20
+ lambda do
21
+ described_class.all!(page: 1, count: 2)
22
+ end.should_not raise_error(ArgumentError)
23
+ end
24
+
25
+ it 'returns an array of GroupDocs::Job objects' do
26
+ jobs = described_class.all!
27
+ jobs.should be_an(Array)
28
+ jobs.each do |job|
29
+ job.should be_a(GroupDocs::Job)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '.create!' do
35
+ before(:each) do
36
+ mock_api_server(load_json('job_create'))
37
+ end
38
+
39
+ let(:actions) { %w(convert compress_zip) }
40
+
41
+ it 'accepts access credentials hash' do
42
+ lambda do
43
+ described_class.create!({ actions: %w(convert) }, client_id: 'client_id', private_key: 'private_key')
44
+ end.should_not raise_error(ArgumentError)
45
+ end
46
+
47
+ it 'raises error if actions are passed' do
48
+ -> { described_class.create!({}) }.should raise_error(ArgumentError)
49
+ end
50
+
51
+ it 'convert actions to byte flag' do
52
+ described_class.should_receive(:convert_actions).with(actions).and_return(5)
53
+ described_class.create!(actions: actions)
54
+ end
55
+
56
+ it 'converts array of out formats to string' do
57
+ formats = %w(pdf txt)
58
+ formats.should_receive(:join).with(?;)
59
+ described_class.create!(actions: actions, out_formats: formats)
60
+ end
61
+
62
+ it 'returns GroupDocs::Job object' do
63
+ described_class.create!(actions: actions).should be_a(GroupDocs::Job)
64
+ end
65
+ end
66
+
67
+ it { should respond_to(:id) }
68
+ it { should respond_to(:id=) }
69
+ it { should respond_to(:documents) }
70
+ it { should respond_to(:documents=) }
71
+
72
+ describe '#documents=' do
73
+ let(:response) do
74
+ [{ id: 1, guid: 'fhy9yh94u238dgf', status: 0, outputs: [] },
75
+ { id: 2, guid: 'ofh9rhy9rfohf9s', status: 2, outputs: [] }]
76
+ end
77
+
78
+ it 'saves documents as array of GroupDocs::Document objects' do
79
+ subject.documents = response
80
+ documents = subject.documents
81
+ documents.should be_an(Array)
82
+ documents.each do |document|
83
+ document.should be_a(GroupDocs::Document)
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '#documents!' do
89
+ before(:each) do
90
+ mock_api_server(load_json('job_documents'))
91
+ end
92
+
93
+ it 'accepts access credentials hash' do
94
+ lambda do
95
+ subject.documents!(client_id: 'client_id', private_key: 'private_key')
96
+ end.should_not raise_error(ArgumentError)
97
+ end
98
+
99
+ it 'returns array of GroupDocs::Document objects' do
100
+ documents = subject.documents!
101
+ documents.should be_an(Array)
102
+ documents.each do |document|
103
+ document.should be_a(GroupDocs::Document)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#add_document!' do
109
+ before(:each) do
110
+ mock_api_server(load_json('job_file_add'))
111
+ end
112
+
113
+ let(:document) do
114
+ GroupDocs::Document.new(file: GroupDocs::Storage::File.new)
115
+ end
116
+
117
+ it 'accepts access credentials hash' do
118
+ lambda do
119
+ subject.add_document!(document, {}, client_id: 'client_id', private_key: 'private_key')
120
+ end.should_not raise_error(ArgumentError)
121
+ end
122
+
123
+ it 'accepts options hash' do
124
+ lambda do
125
+ subject.add_document!(document, output_formats: %w(pdf txt))
126
+ end.should_not raise_error(ArgumentError)
127
+ end
128
+
129
+ it 'raises error if document is not an instance of GroupDocs::Document' do
130
+ -> { subject.add_document!('Document') }.should raise_error(ArgumentError)
131
+ end
132
+
133
+ it 'returns document ID' do
134
+ subject.add_document!(document).should be_an(Integer)
135
+ end
136
+ end
137
+
138
+ describe '#add_datasource!' do
139
+ let(:document) do
140
+ GroupDocs::Document.new(file: GroupDocs::Storage::File.new)
141
+ end
142
+
143
+ let(:datasource) do
144
+ GroupDocs::DataSource.new
145
+ end
146
+
147
+ it 'accepts access credentials hash' do
148
+ lambda do
149
+ subject.add_datasource!(document, datasource, client_id: 'client_id', private_key: 'private_key')
150
+ end.should_not raise_error(ArgumentError)
151
+ end
152
+
153
+ it 'raises error if document is not an instance of GroupDocs::Document' do
154
+ -> { subject.add_datasource!('Document') }.should raise_error(ArgumentError)
155
+ end
156
+
157
+ it 'raises error if datasource is not an instance of GroupDocs::DataSource' do
158
+ -> { subject.add_datasource!(document, 'DataSource') }.should raise_error(ArgumentError)
159
+ end
160
+ end
161
+
162
+ describe '#add_url!' do
163
+ before(:each) do
164
+ mock_api_server(load_json('job_add_url'))
165
+ end
166
+
167
+ let(:url) { 'http://www.google.com' }
168
+
169
+ it 'accepts access credentials hash' do
170
+ lambda do
171
+ subject.add_url!(url, {}, client_id: 'client_id', private_key: 'private_key')
172
+ end.should_not raise_error(ArgumentError)
173
+ end
174
+
175
+ it 'accepts options hash' do
176
+ lambda do
177
+ subject.add_url!(url, out_formats: %W(pdf txt))
178
+ end.should_not raise_error(ArgumentError)
179
+ end
180
+
181
+ it 'returns document ID' do
182
+ subject.add_url!(url).should be_an(Integer)
183
+ end
184
+ end
185
+
186
+ describe '#update!' do
187
+ before(:each) do
188
+ mock_api_server(load_json('job_update'))
189
+ end
190
+
191
+ it 'parses status' do
192
+ subject.should_receive(:parse_status).with(:draft).and_return(-1)
193
+ subject.update!(status: :draft)
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Questionnaire::Execution do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe 'STATUSES' do
8
+ it 'contains hash of execution statuses' do
9
+ described_class::STATUSES.should == {
10
+ draft: 0,
11
+ submitted: 1,
12
+ executed: 2,
13
+ approved: 3,
14
+ rejected: 4,
15
+ closed: 5,
16
+ }
17
+ end
18
+ end
19
+
20
+ describe '.all!' do
21
+ it 'accepts access credentials hash' do
22
+ lambda do
23
+ described_class.all!(client_id: 'client_id', private_key: 'private_key')
24
+ end.should_not raise_error(ArgumentError)
25
+ end
26
+
27
+ it 'just calls GroupDocs::Questionnaire.executions! method' do
28
+ GroupDocs::Questionnaire.should_receive(:executions!).with({})
29
+ described_class.all!
30
+ end
31
+ end
32
+
33
+ it { should respond_to(:id) }
34
+ it { should respond_to(:id=) }
35
+ it { should respond_to(:ownerId) }
36
+ it { should respond_to(:ownerId=) }
37
+ it { should respond_to(:questionnaireId) }
38
+ it { should respond_to(:questionnaireId=) }
39
+ it { should respond_to(:executiveId) }
40
+ it { should respond_to(:executiveId=) }
41
+ it { should respond_to(:approverId) }
42
+ it { should respond_to(:approverId=) }
43
+ it { should respond_to(:datasourceId) }
44
+ it { should respond_to(:datasourceId=) }
45
+ it { should respond_to(:documentId) }
46
+ it { should respond_to(:documentId=) }
47
+ it { should respond_to(:status) }
48
+ it { should respond_to(:status=) }
49
+ it { should respond_to(:guid) }
50
+ it { should respond_to(:guid=) }
51
+
52
+ it 'has human-readable accessors' do
53
+ subject.should respond_to(:owner_id)
54
+ subject.should respond_to(:owner_id=)
55
+ subject.should respond_to(:questionnaire_id)
56
+ subject.should respond_to(:questionnaire_id=)
57
+ subject.should respond_to(:executive_id)
58
+ subject.should respond_to(:executive_id=)
59
+ subject.should respond_to(:approver_id)
60
+ subject.should respond_to(:approver_id=)
61
+ subject.should respond_to(:datasource_id)
62
+ subject.should respond_to(:datasource_id=)
63
+ subject.should respond_to(:document_id)
64
+ subject.should respond_to(:document_id=)
65
+ subject.method(:owner_id).should == subject.method(:ownerId)
66
+ subject.method(:owner_id=).should == subject.method(:ownerId=)
67
+ subject.method(:questionnaire_id).should == subject.method(:questionnaireId)
68
+ subject.method(:questionnaire_id=).should == subject.method(:questionnaireId=)
69
+ subject.method(:executive_id).should == subject.method(:executiveId)
70
+ subject.method(:executive_id=).should == subject.method(:executiveId=)
71
+ subject.method(:approver_id).should == subject.method(:approverId)
72
+ subject.method(:approver_id=).should == subject.method(:approverId=)
73
+ subject.method(:datasource_id).should == subject.method(:datasourceId)
74
+ subject.method(:datasource_id=).should == subject.method(:datasourceId=)
75
+ subject.method(:document_id).should == subject.method(:documentId)
76
+ subject.method(:document_id=).should == subject.method(:documentId=)
77
+ end
78
+
79
+ describe '#status=' do
80
+ it 'saves status in machine readable format if symbol is passed' do
81
+ subject.status = :executed
82
+ subject.instance_variable_get(:@status).should == 2
83
+ end
84
+
85
+ it 'does nothing if parameter is not symbol' do
86
+ subject.status = 2
87
+ subject.instance_variable_get(:@status).should == 2
88
+ end
89
+
90
+ it 'raises error if status is unknown' do
91
+ -> { subject.status = :unknown }.should raise_error(ArgumentError)
92
+ end
93
+ end
94
+
95
+ describe '#status' do
96
+ it 'returns status in human-readable format' do
97
+ subject.status = 2
98
+ subject.status.should == :executed
99
+ end
100
+ end
101
+
102
+ describe '#set_status!' do
103
+ before(:each) do
104
+ mock_api_server(load_json('questionnaire_execution_status_set'))
105
+ end
106
+
107
+ it 'accepts access credentials hash' do
108
+ lambda do
109
+ subject.set_status!(:submitted, client_id: 'client_id', private_key: 'private_key')
110
+ end.should_not raise_error(ArgumentError)
111
+ end
112
+
113
+ it 'updates status of execution object' do
114
+ lambda do
115
+ subject.set_status!(:submitted)
116
+ end.should change(subject, :status).to(:submitted)
117
+ end
118
+ end
119
+
120
+ describe '#update!' do
121
+ before(:each) do
122
+ mock_api_server(load_json('questionnaire_execution_update'))
123
+ end
124
+
125
+ it 'accepts access credentials hash' do
126
+ lambda do
127
+ subject.update!(client_id: 'client_id', private_key: 'private_key')
128
+ end.should_not raise_error(ArgumentError)
129
+ end
130
+
131
+ it 'uses hashed version of self as request body' do
132
+ subject.should_receive(:to_hash).and_return({})
133
+ subject.update!
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Questionnaire::Page do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ it { should respond_to(:questions) }
8
+ it { should respond_to(:questions=) }
9
+ it { should respond_to(:number) }
10
+ it { should respond_to(:number=) }
11
+ it { should respond_to(:title) }
12
+ it { should respond_to(:title=) }
13
+
14
+ describe '#questions=' do
15
+ it 'converts each question to GroupDocs::Questionnaire::Question object if hash is passed' do
16
+ subject.questions = [{ field: 'Field1', text: 'Text1', def_answer: 'A1' }]
17
+ questions = subject.questions
18
+ questions.should be_an(Array)
19
+ questions.each do |question|
20
+ question.should be_a(GroupDocs::Questionnaire::Question)
21
+ end
22
+ end
23
+
24
+ it 'saves each question if it is GroupDocs::Questionnaire::Question object' do
25
+ question1 = GroupDocs::Questionnaire::Question.new(field: 'field1')
26
+ question2 = GroupDocs::Questionnaire::Question.new(field: 'field2')
27
+ subject.questions = [question1, question2]
28
+ subject.questions.should include(question1)
29
+ subject.questions.should include(question2)
30
+ end
31
+
32
+ it 'does nothing if nil is passed' do
33
+ lambda do
34
+ subject.questions = nil
35
+ end.should_not change(subject, :questions)
36
+ end
37
+ end
38
+
39
+ describe '#add_question' do
40
+ it 'raises error if question is not GroupDocs::Questionnaire::Page object' do
41
+ -> { subject.add_question('Page') }.should raise_error(ArgumentError)
42
+ end
43
+
44
+ it 'saves question' do
45
+ question = GroupDocs::Questionnaire::Question.new
46
+ subject.add_question(question)
47
+ subject.questions.should == [question]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Questionnaire::Question::Answer do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ it { should respond_to(:text) }
8
+ it { should respond_to(:text=) }
9
+ it { should respond_to(:value) }
10
+ it { should respond_to(:value=) }
11
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe GroupDocs::Questionnaire::Question do
4
+
5
+ it_behaves_like GroupDocs::Api::Entity
6
+
7
+ describe 'TYPES' do
8
+ it 'contains hash of field types' do
9
+ described_class::TYPES.should == {
10
+ simple: 0,
11
+ multiple_choice: 1,
12
+ }
13
+ end
14
+ end
15
+
16
+ it { should respond_to(:field) }
17
+ it { should respond_to(:field=) }
18
+ it { should respond_to(:text) }
19
+ it { should respond_to(:text=) }
20
+ it { should respond_to(:def_answer) }
21
+ it { should respond_to(:def_answer=) }
22
+ it { should respond_to(:required) }
23
+ it { should respond_to(:required=) }
24
+ it { should respond_to(:type) }
25
+ it { should respond_to(:type=) }
26
+ it { should respond_to(:answers) }
27
+ it { should respond_to(:answers=) }
28
+
29
+ describe '#answers=' do
30
+ it 'converts each answer to GroupDocs::Questionnaire::Question::Answer object' do
31
+ subject.answers = [{ text: 'Text1', value: 'Value1' }, { text: 'Text2', value: 'Value2' }]
32
+ answers = subject.answers
33
+ answers.should be_an(Array)
34
+ answers.each do |answer|
35
+ answer.should be_a(GroupDocs::Questionnaire::Question::Answer)
36
+ end
37
+ end
38
+
39
+ it 'saves each answer if it is GroupDocs::Questionnaire::Question::Answer object' do
40
+ answer1 = GroupDocs::Questionnaire::Question::Answer.new(text: 'text1')
41
+ answer2 = GroupDocs::Questionnaire::Question::Answer.new(text: 'text2')
42
+ subject.answers = [answer1, answer2]
43
+ subject.answers.should include(answer1)
44
+ subject.answers.should include(answer2)
45
+ end
46
+
47
+ it 'does nothing if nil is passed' do
48
+ lambda do
49
+ subject.answers = nil
50
+ end.should_not change(subject, :answers)
51
+ end
52
+ end
53
+
54
+ describe '#add_answer' do
55
+ it 'raises error if answer is not GroupDocs::Questionnaire::Question::Answer object' do
56
+ -> { subject.add_answer('Answer') }.should raise_error(ArgumentError)
57
+ end
58
+
59
+ it 'saves answer' do
60
+ answer = GroupDocs::Questionnaire::Question::Answer.new(text: 'Text', value: 'Value')
61
+ subject.add_answer(answer)
62
+ subject.answers.should == [answer]
63
+ end
64
+ end
65
+
66
+ describe '#type=' do
67
+ it 'saves type in machine readable format if symbol is passed' do
68
+ subject.type = :multiple_choice
69
+ subject.instance_variable_get(:@type).should == 1
70
+ end
71
+
72
+ it 'does nothing if parameter is not symbol' do
73
+ subject.type = 1
74
+ subject.instance_variable_get(:@type).should == 1
75
+ end
76
+ end
77
+
78
+ describe '#type' do
79
+ it 'returns type in human-readable format' do
80
+ subject.type = 1
81
+ subject.type.should == :multiple_choice
82
+ end
83
+ end
84
+ end