spec/support/shared_examples/signature/shared/field_methods.rb in groupdocs-1.3.0 vs spec/support/shared_examples/signature/shared/field_methods.rb in groupdocs-1.4.0
- old
+ new
@@ -1,6 +1,14 @@
shared_examples_for GroupDocs::Signature::FieldMethods do
+ let(:args) do
+ case described_class.name
+ when 'GroupDocs::Signature::Form'
+ [document]
+ when 'GroupDocs::Signature::Template', 'GroupDocs::Signature::Envelope'
+ [document, recipient]
+ end
+ end
describe '#fields!' do
let(:document) { GroupDocs::Document.new(:file => GroupDocs::Storage::File.new) }
let(:recipient) { GroupDocs::Signature::Recipient.new }
@@ -8,24 +16,16 @@
mock_api_server(load_json('signature_fields_get'))
end
it 'accepts access credentials hash' do
lambda do
- subject.fields!(document, recipient, :client_id => 'client_id', :private_key => 'private_key')
+ subject.fields!(*args, :client_id => 'client_id', :private_key => 'private_key')
end.should_not raise_error(ArgumentError)
end
- it 'raises error if document is not GroupDocs::Document object' do
- lambda { subject.fields!('Document', recipient) }.should raise_error(ArgumentError)
- end
-
- it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
- lambda { subject.fields!(document, 'Recipient') }.should raise_error(ArgumentError)
- end
-
it 'returns array of GroupDocs::Signature::Field objects' do
- fields = subject.fields!(document, recipient)
+ fields = subject.fields!(*args)
fields.should be_an(Array)
fields.each do |field|
field.should be_a(GroupDocs::Signature::Field)
end
end
@@ -40,51 +40,43 @@
mock_api_server(load_json('signature_field_add'))
end
it 'accepts access credentials hash' do
lambda do
- subject.add_field!(field, document, recipient, { :force_new_field => false }, :client_id => 'client_id', :private_key => 'private_key')
+ subject.add_field!(field, *args, { :force_new_field => false }, :client_id => 'client_id', :private_key => 'private_key')
end.should_not raise_error(ArgumentError)
end
it 'raises error if field is not GroupDocs::Signature::Field object' do
- lambda { subject.add_field!('Field', document, recipient) }.should raise_error(ArgumentError)
+ lambda { subject.add_field!('Field', *args) }.should raise_error(ArgumentError)
end
- it 'raises error if document is not GroupDocs::Document object' do
- lambda { subject.add_field!(field, 'Document', recipient) }.should raise_error(ArgumentError)
- end
-
- it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
- lambda { subject.add_field!(field, document, 'Recipient') }.should raise_error(ArgumentError)
- end
-
it 'raises error if field does not specify location' do
field = GroupDocs::Signature::Field.new
- lambda { subject.add_field!(field, document, recipient) }.should raise_error(ArgumentError)
+ lambda { subject.add_field!(field, *args) }.should raise_error(ArgumentError)
end
it 'uses field and field locationas payload' do
hash_one = {}
payload = {}
location = {}
field.should_receive(:to_hash).and_return(payload)
field.location.should_receive(:to_hash).and_return(location)
payload.should_receive(:merge!).with(location).and_return(payload)
payload.should_receive(:merge!).with(:forceNewField => true).and_return({})
- subject.add_field!(field, document, recipient)
+ subject.add_field!(field, *args)
end
it 'allows overriding force new field flag' do
hash_one = {}
payload = {}
location = {}
field.should_receive(:to_hash).and_return(payload)
field.location.should_receive(:to_hash).and_return(location)
payload.should_receive(:merge!).with(location).and_return(payload)
payload.should_receive(:merge!).with(:forceNewField => false).and_return({})
- subject.add_field!(field, document, recipient, :force_new_field => false)
+ subject.add_field!(field, *args, :force_new_field => false)
end
end
describe '#modify_field!' do
let(:field) { GroupDocs::Signature::Field.new }
@@ -119,10 +111,50 @@
payload.should_receive(:merge!).with(location).and_return(payload)
subject.modify_field!(field, document)
end
end
+ describe '#assign_field!' do
+ case described_class.name
+ when 'GroupDocs::Signature::Form'
+ it 'does not have #assign_field! method' do
+ subject.methods.should_not include(:assign_field!)
+ end
+ when 'GroupDocs::Signature::Template', 'GroupDocs::Signature::Envelope'
+ let(:field) { GroupDocs::Signature::Field.new }
+ let(:document) { GroupDocs::Document.new(:file => GroupDocs::Storage::File.new) }
+ let(:assign_from) { GroupDocs::Signature::Recipient.new }
+ let(:assign_to) { GroupDocs::Signature::Recipient.new }
+
+ before(:each) do
+ mock_api_server(load_json('signature_field_add'))
+ end
+
+ it 'accepts access credentials hash' do
+ lambda do
+ subject.assign_field!(field, document, assign_from, assign_to, :client_id => 'client_id', :private_key => 'private_key')
+ end.should_not raise_error(ArgumentError)
+ end
+
+ it 'raises error if field is not GroupDocs::Signature::Field object' do
+ lambda { subject.assign_field!('Field', document, assign_from, assign_to) }.should raise_error(ArgumentError)
+ end
+
+ it 'raises error if document is not GroupDocs::Document object' do
+ lambda { subject.assign_field!(field, 'Document', assign_from, assign_to) }.should raise_error(ArgumentError)
+ end
+
+ it 'raises error if assign from is not GroupDocs::Signature::Recipient object' do
+ lambda { subject.assign_field!(field, document, 'Assign', assign_to) }.should raise_error(ArgumentError)
+ end
+
+ it 'raises error if assign to is not GroupDocs::Signature::Recipient object' do
+ lambda { subject.assign_field!(field, document, assign_from, 'Assign') }.should raise_error(ArgumentError)
+ end
+ end
+ end
+
describe '#delete_field!' do
let(:field) do
GroupDocs::Signature::Field.new
end
@@ -150,27 +182,19 @@
before(:each) do
mock_api_server(load_json('signature_field_add'))
end
it 'raises error if location is not GroupDocs::Signature::Field::Location object' do
- lambda { subject.modify_field_location!('Location', field, document, recipient) }.should raise_error(ArgumentError)
+ lambda { subject.modify_field_location!('Location', field, *args) }.should raise_error(ArgumentError)
end
it 'raises error if field is not GroupDocs::Signature::Field object' do
- lambda { subject.modify_field_location!(location, 'Field', document, recipient) }.should raise_error(ArgumentError)
+ lambda { subject.modify_field_location!(location, 'Field', *args) }.should raise_error(ArgumentError)
end
- it 'raises error if document is not GroupDocs::Document object' do
- lambda { subject.modify_field_location!(location, field, 'Document', recipient) }.should raise_error(ArgumentError)
- end
-
- it 'raises error if recipient is not GroupDocs::Signature::Recipient object' do
- lambda { subject.modify_field_location!(location, field, document, 'Recipient') }.should raise_error(ArgumentError)
- end
-
it 'accepts access credentials hash' do
lambda do
- subject.modify_field_location!(location, field, document, recipient, :client_id => 'client_id', :private_key => 'private_key')
+ subject.modify_field_location!(location, field, *args, :client_id => 'client_id', :private_key => 'private_key')
end.should_not raise_error(ArgumentError)
end
end
describe '#delete_field_location!' do