Skip to content

Commit

Permalink
Rescue NoMethodError when updating RSS fachinfo. With unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Jan 19, 2016
1 parent 13a113d commit 707acbd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/view/rss/fachinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def item_to_html(context, fachinfo, feed)
link.value = match
link.to_html(context)
end
rescue NoMethodError | NotImplementedError => e
rescue NoMethodError, NotImplementedError => e
puts "rss/fachinfo #{__LINE__}: rescue #{e.inspect} for rss/fachinfo #{__LINE__}: #{fachinfo.inspect}: backtrace is: \n #{e.backtrace[0..5].join("\n ")}"
return ""
end
Expand Down
48 changes: 33 additions & 15 deletions test/test_view/rss/fachinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def setup
:lookandfeel => @lnf,
:language => 'language'
)
document = flexmock('document',
@document = flexmock('document',
:is_a? => true,
:chapter_names => ['chapter_name']
)
@model = flexmock('model',
:localized_name => 'localized_name',
:language => document,
:language => @document,
:pointer => 'pointer',
:revision => Time.utc(@year,2,3),
:iksnrs => ['iksnrs'],
Expand Down Expand Up @@ -85,17 +85,7 @@ def setup
</item>
</channel>
</rss>)
end
def test_to_html_after_last_year
@@today = Date.new(@year + 1,2,16)
context = flexmock('context', :html => 'html')
assert_equal(@expected_2011, @component.to_html(context))
end

def test_to_html_older_last_year
@@today = Date.new(2013,1,1)
context = flexmock('context', :html => 'html')
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
@no_items = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\"
xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
Expand All @@ -113,15 +103,43 @@ def test_to_html_older_last_year
</image>
</channel>
</rss>"
assert_equal(expected, @component.to_html(context))
end
def test_to_html_after_last_year
@@today = Date.new(@year + 1,2,16)
context = flexmock('context', :html => 'html')
assert_equal(@expected_2011, @component.to_html(context), 'should not item of last year (2011)')
end

def test_to_html_older_last_year
@@today = Date.new(2013,1,1)
context = flexmock('context', :html => 'html')
assert_equal(@no_items, @component.to_html(context), 'should not contain any items')
end

def test_to_html_year_2011
@@today = Date.new(2015,1,1)
context = flexmock('context', :html => 'html')
container = nil
@component = ODDB::View::Rss::Fachinfo.new([@model], @session, container, @year)
assert_equal(@expected_2011, @component.to_html(context))
assert_equal(@expected_2011, @component.to_html(context), 'should not item of 2011')
end

def test_to_html_raise_rrror
@@today = Date.new(2015,1,1)
container = nil
@model = flexmock('model',
:localized_name => 'localized_name',
:language => @document,
:pointer => 'pointer',
:revision => Time.utc(@year,2,3),
)
@raised_no_method_error = false
@model.should_receive(:iksnrs).and_return { @raised_no_method_error = true ; raise(NoMethodError) }
@component = ODDB::View::Rss::Fachinfo.new([@model], @session, container, @year)
context = flexmock('context', :html => 'html')
res = @component.to_html(context)
assert(res.is_a?(String), 'should not raise an error')
assert(@raised_no_method_error, 'must have catched NoMethodError')
end
end
end # Interactions
Expand Down

0 comments on commit 707acbd

Please sign in to comment.