Skip to content

Commit

Permalink
Merge branch 'to-html-with-block' of git://github.com/insside/later_d…
Browse files Browse the repository at this point in the history
…ude into insside-to-html-with-block
  • Loading branch information
Clemens Kofler committed Aug 20, 2012
2 parents 6ff85ac + d229180 commit 2464009
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/later_dude/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def initialize(year, month, options={}, &block)
@block = block
end

def to_html
def to_html(&block)
@block = block if block_given?
content_tag(:table, :class => "#{@options[:calendar_class]}") do
content_tag(:thead, "#{show_month_names}#{show_day_names}".html_safe) + content_tag(:tbody, show_days)
end
Expand Down
9 changes: 9 additions & 0 deletions test/calendar_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,14 @@ class CalendarTest < ActiveSupport::TestCase
assert_equal calendar2.last_rendered_date, Date.new(2011, 7, 31)
end

test "allows pass block to to_html method" do
proc = lambda { |day| day.day }

calendar_html1 = LaterDude::Calendar.new(2009, 1, &proc).to_html
calendar_html2 = LaterDude::Calendar.new(2009, 1).to_html(&proc)

assert_equal calendar_html1, calendar_html2
end

# TODO: Should I do "real" output testing despite the good coverage of output-related methods? Testing HTML is tedious ...
end

0 comments on commit 2464009

Please sign in to comment.