Permalink
Browse files

Prevent engine from blowing up if the mail doesnt have a rich text ve…

…rsion
  • Loading branch information...
fgrehm committed Feb 2, 2013
1 parent c5e32f2 commit e51b3c4ea9b6880ae24b3f7df1ca91ba38830f20
@@ -38,12 +38,22 @@ def to_param
id
end
def default_style
style_exists?('rich') ?
'rich' :
'plain'
end
private
def read_file(style)
File.read("#{letters_location}/#{id}/#{style}.html")
end
def style_exists?(style)
File.exists?("#{letters_location}/#{id}/#{style}.html")
end
def adjust_link_targets(contents)
# We cannot feed the whole file to an XML parser as some mails are
# "complete" (as in they have the whole <html> structure) and letter_opener
@@ -23,15 +23,15 @@
<% if first_letter = @letters.shift %>
<tr class="active">
<td>
<%= link_to(first_letter.id, letter_path(first_letter, style: 'rich'), target: 'mail') %>
<%= link_to(first_letter.id, letter_path(first_letter, style: first_letter.default_style), target: 'mail') %>
</td>
<td><%= first_letter.sent_at %></td>
</tr>
<% end %>
<% @letters.each do |letter| %>
<tr>
<td>
<%= link_to(letter.id, letter_path(letter, style: 'rich'), target: 'mail') %>
<%= link_to(letter.id, letter_path(letter, style: letter.default_style), target: 'mail') %>
</td>
<td><%= letter.sent_at %></td>
</tr>
@@ -40,5 +40,5 @@
</table>
</div>
<div class="col right">
<iframe name="mail" id="mail" src="<%= first_letter.present? ? letter_path(first_letter, style: 'rich') : 'about:blank' %>"></iframe>
<iframe name="mail" id="mail" src="<%= first_letter.present? ? letter_path(first_letter, style: first_letter.default_style) : 'about:blank' %>"></iframe>
</div>
@@ -50,6 +50,20 @@ def rich_text(mail_id)
it { should =~ /Plain text for 2222_2222/ }
end
describe 'default style' do
let(:id) { '2222_2222' }
subject { described_class.new(id: id) }
it 'returns rich if rich text version is present' do
subject.default_style.should == 'rich'
end
it 'returns plain if rich text version is not present' do
File.stub(:exists? => false)
subject.default_style.should == 'plain'
end
end
describe '.search' do
let(:search_results) { described_class.search }
let(:first_letter) { search_results.first }

0 comments on commit e51b3c4

Please sign in to comment.