aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/attachment_to_html
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-04-02 12:11:56 +0100
committerGareth Rees <gareth@mysociety.org>2014-04-07 17:09:58 +0100
commit0532eeee63f06e796f0e967f39dfa5f23d4821f7 (patch)
tree06b6755504b189f9ab2ace3d050dd93990a0e5ec /spec/lib/attachment_to_html
parente7d0f9a8b350ffe3c17451d6bb18051c7230ca61 (diff)
Simpler AttachmentToHTML::Adapters::RTF interface
TODO: We really should be testing the full output of RTF#body, but we currently want to remain consistent with Adapters::PDF as many methods are shared between the Adapters. A more correct spec might be: expected = %Q(<font size=3><font color="#000000">thisisthebody</font></font>) adapter.body.should == expected
Diffstat (limited to 'spec/lib/attachment_to_html')
-rw-r--r--spec/lib/attachment_to_html/adapters/rtf_spec.rb82
1 files changed, 22 insertions, 60 deletions
diff --git a/spec/lib/attachment_to_html/adapters/rtf_spec.rb b/spec/lib/attachment_to_html/adapters/rtf_spec.rb
index 75fd467f6..a3bf0e27e 100644
--- a/spec/lib/attachment_to_html/adapters/rtf_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/rtf_spec.rb
@@ -3,70 +3,39 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::RTF do
let(:attachment) { FactoryGirl.build(:rtf_attachment) }
- let(:rtf_adapter) { AttachmentToHTML::Adapters::RTF.new(attachment) }
-
- describe :wrapper do
-
- it 'defaults to wrapper' do
- rtf_adapter.wrapper.should == 'wrapper'
- end
-
- it 'accepts a wrapper option' do
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :wrapper => 'wrap')
- rtf_adapter.wrapper.should == 'wrap'
- end
-
- end
+ let(:adapter) { AttachmentToHTML::Adapters::RTF.new(attachment) }
describe :tmpdir do
it 'defaults to the rails tmp directory' do
- rtf_adapter.tmpdir.should == Rails.root.join('tmp')
+ adapter.tmpdir.should == Rails.root.join('tmp')
end
it 'allows a tmpdir to be specified to store the converted document' do
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :tmpdir => '/tmp')
- rtf_adapter.tmpdir.should == '/tmp'
+ adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :tmpdir => '/tmp')
+ adapter.tmpdir.should == '/tmp'
end
end
- describe :to_html do
+ describe :title do
- it 'should be a valid html document' do
- parsed = Nokogiri::HTML.parse(rtf_adapter.to_html) do |config|
- config.strict
- end
- parsed.errors.any?.should be_false
- end
-
- it 'contains the attachment filename in the title tag' do
- parsed = Nokogiri::HTML.parse(rtf_adapter.to_html) do |config|
- config.strict
- end
- parsed.css('head title').inner_html.should == attachment.display_filename
+ it 'uses the attachment filename for the title' do
+ adapter.title.should == attachment.display_filename
end
+
+ end
- it 'contains the wrapper div in the body tag' do
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :wrapper => 'wrap')
- parsed = Nokogiri::HTML.parse(rtf_adapter.to_html) do |config|
- config.strict
- end
- parsed.css('body div').first.attributes['id'].value.should == 'wrap'
- end
+ describe :body do
- it 'contains the attachment body in the wrapper div' do
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :wrapper => 'wrap')
- parsed = Nokogiri::HTML.parse(rtf_adapter.to_html) do |config|
- config.strict
- end
- parsed.css('div#wrap div#view-html-content').inner_text.should include('thisisthebody')
+ it 'extracts the body from the document' do
+ adapter.body.should include('thisisthebody')
end
it 'operates in the context of the supplied tmpdir' do
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :tmpdir => '/tmp')
+ adapter = AttachmentToHTML::Adapters::RTF.new(attachment, :tmpdir => '/tmp')
Dir.should_receive(:chdir).with('/tmp').and_call_original
- rtf_adapter.to_html
+ adapter.body
end
it 'does not result in incorrect conversion when unrtf returns an invalid doctype' do
@@ -88,34 +57,27 @@ describe AttachmentToHTML::Adapters::RTF do
DOC
AlaveteliExternalCommand.stub(:run).and_return(invalid)
- parsed = Nokogiri::HTML.parse(rtf_adapter.to_html) do |config|
- config.strict
- end
- parsed.css('body').inner_text.should_not include('//W3C//DTD HTML 4.01 Transitional//EN')
+ adapter.body.should_not include('//W3C//DTD HTML 4.01 Transitional//EN')
end
end
+
describe :success? do
it 'is successful if the body has content excluding the tags' do
- rtf_adapter.to_html
- rtf_adapter.success?.should be_true
+ adapter.stub(:body).and_return('<p>some content</p>')
+ adapter.success?.should be_true
end
it 'is successful if the body contains images' do
- mocked_return = %Q(<!DOCTYPE html><html><head></head><body><img src="logo.png" /></body></html>)
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment)
- rtf_adapter.stub(:to_html).and_return(mocked_return)
- rtf_adapter.success?.should be_true
+ adapter.stub(:body).and_return(%Q(<img src="logo.png" />))
+ adapter.success?.should be_true
end
it 'is not successful if the body has no content other than tags' do
- empty_rtf = load_file_fixture('empty.rtf')
- attachment = FactoryGirl.build(:rtf_attachment, :body => empty_rtf)
- rtf_adapter = AttachmentToHTML::Adapters::RTF.new(attachment)
- rtf_adapter.to_html
- rtf_adapter.success?.should be_false
+ adapter.stub(:body).and_return('<p></p>')
+ adapter.success?.should be_false
end
end