Added basic specs for attachment CRUD
This commit is contained in:
parent
8d25cbc8b0
commit
e497fbbab4
|
@ -588,7 +588,7 @@ module CouchRest
|
||||||
|
|
||||||
def get_mime_type(file)
|
def get_mime_type(file)
|
||||||
MIME::Types.type_for(file.path).empty? ?
|
MIME::Types.type_for(file.path).empty? ?
|
||||||
'text\/plain' : MIME::Types.type_for(file.path).content_type.gsub(/\//,'\/')
|
'text\/plain' : MIME::Types.type_for(file.path).first.content_type.gsub(/\//,'\/')
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_attachment_attr(file, attachment_name)
|
def set_attachment_attr(file, attachment_name)
|
||||||
|
|
|
@ -727,4 +727,60 @@ describe CouchRest::Model do
|
||||||
lambda{Basic.get(@obj.id)}.should raise_error
|
lambda{Basic.get(@obj.id)}.should raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "creating an attachment" do
|
||||||
|
before(:each) do
|
||||||
|
@obj = Basic.new
|
||||||
|
@obj.save.should == true
|
||||||
|
@file_ext = File.open(FIXTURE_PATH + '/attachments/test.html')
|
||||||
|
@file_no_text = File.open(FIXTURE_PATH + '/attachments/README')
|
||||||
|
@attachment_name = 'my_attachment'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create an attachment from file with an extension" do
|
||||||
|
@obj.create_attachment(@file_ext, @attachment_name)
|
||||||
|
@obj.save.should == true
|
||||||
|
reloaded_obj = Basic.get(@obj.id)
|
||||||
|
reloaded_obj['_attachments'][@attachment_name].should_not be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create an attachment from file without an extension" do
|
||||||
|
@obj.create_attachment(@file_no_text, @attachment_name)
|
||||||
|
@obj.save.should == true
|
||||||
|
reloaded_obj = Basic.get(@obj.id)
|
||||||
|
reloaded_obj['_attachments'][@attachment_name].should_not be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'reading, updating, and deleting an attachment' do
|
||||||
|
before(:each) do
|
||||||
|
@obj = Basic.new
|
||||||
|
@file = File.open(FIXTURE_PATH + '/attachments/test.html')
|
||||||
|
@attachment_name = 'my_attachment'
|
||||||
|
@obj.create_attachment(@file, @attachment_name)
|
||||||
|
@obj.save.should == true
|
||||||
|
@file.rewind
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should read an attachment that exists' do
|
||||||
|
@obj.read_attachment(@attachment_name).should == @file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should update an attachment that exists' do
|
||||||
|
file = File.open(FIXTURE_PATH + '/attachments/README')
|
||||||
|
@file.should_not == file
|
||||||
|
@obj.update_attachment(file, @attachment_name)
|
||||||
|
@obj.save
|
||||||
|
reloaded_obj = Basic.get(@obj.id)
|
||||||
|
file.rewind
|
||||||
|
reloaded_obj.read_attachment(@attachment_name).should_not == @file.read
|
||||||
|
reloaded_obj.read_attachment(@attachment_name).should == file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should delete an attachment that exists' do
|
||||||
|
@obj.delete_attachment(@attachment_name)
|
||||||
|
@obj.save
|
||||||
|
lambda{Basic.get(@obj.id).read_attachment(@attachment_name)}.should raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
3
spec/fixtures/attachments/README
vendored
Normal file
3
spec/fixtures/attachments/README
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
This is an example README file.
|
||||||
|
|
||||||
|
More of the README, whee.
|
Loading…
Reference in a new issue