Created
July 8, 2009 12:31
-
-
Save lmarburger/142779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EventsHelper | |
def events_list(events) | |
content_tag(:ul) do | |
events.inject('') do |list_content, event| | |
list_content << event_list_item(event) | |
end | |
end | |
end | |
private | |
def event_list_item(event) | |
content_tag(:li) do | |
item_content = content_tag(:h3, link_to(event.name, '')) | |
item_content << event_details(event) | |
end | |
end | |
def event_details(event) | |
content_tag(:div, :class => 'content') do | |
details_content = event.picture? ? image_tag(event.picture.url) : '' | |
details_content << simple_format(event.description) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class EventsHelperTest < ActionView::TestCase | |
context 'Given events' do | |
setup do | |
3.times { Factory(:event) } | |
@events = Event.all | |
end | |
context 'when displaying the events' do | |
setup { get_events_list } | |
should 'show all events' do | |
assert_select 'ul', :count => 1 do | |
assert_select 'li', :count => @events.size | |
end | |
end | |
should 'link each event title' do | |
@events.each do |event| | |
assert_select "li h3 a[href=]", :count => 1, :text => event.name | |
end | |
end | |
should 'show the event details' do | |
assert_select 'li div.content', :count => @events.size do | |
@events.each do |event| | |
assert_select 'p', :count => 1, :text => event.description | |
end | |
end | |
end | |
should 'not show a picture' do | |
assert_select 'img', :count => 0 | |
end | |
end | |
end | |
context 'Given an event with line breaks in the description' do | |
setup do | |
Factory :event, :description => <<-EOS | |
This is some text. | |
This is more text. | |
Break. | |
EOS | |
@events = Event.all | |
get_events_list | |
end | |
should 'format the description' do | |
assert_select('div.content p', :count => 2) do | |
assert_select 'br', :count => 1 | |
end | |
end | |
end | |
context 'Given an event with a picture' do | |
setup do | |
Factory :event_with_picture | |
@events = Event.all | |
end | |
context 'when displaying the events' do | |
setup { get_events_list } | |
should 'show the picture' do | |
event = @events.first | |
assert_select 'li div.content img[src=?] + p', | |
%r{/system/events/pictures/#{ event.id }/normal/#{ event.picture_file_name }\?\d+}, | |
:count => 1 | |
end | |
end | |
end | |
private | |
def get_events_list | |
set_response_body(events_list(@events)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment