ref: master
test/functional/events_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
require_relative "../test_helper" class EventsControllerTest < ActionController::TestCase def setup @profile = create_user('testuser').person end attr_reader :profile should 'list today events by default' do profile.events << Event.new(:name => 'Joao Birthday', :start_date => DateTime.now) profile.events << Event.new(:name => 'Maria Birthday', :start_date => DateTime.now) get :events, :profile => profile.identifier today = DateTime.now.strftime("%B %d, %Y").html_safe assert_tag :tag => 'div', :attributes => {:id => "agenda-items"}, :descendant => {:tag => 'h3', :content => "Events for #{today}"}, :descendant => {:tag => 'tr', :content => "Joao Birthday"}, :descendant => {:tag => 'tr', :content => "Maria Birthday"} end should 'display calendar of current month' do get :events, :profile => profile.identifier month = DateTime.now.strftime("%B %Y") assert_tag :tag => 'table', :attributes => {:class => /current-month/}, :descendant => {:tag => 'caption', :content => /#{month}/} end should 'display links to previous and next month' do get :events, :profile => profile.identifier prev_month = DateTime.now - 1.month next_month = DateTime.now + 1.month prev_month_name = prev_month.strftime("%B") next_month_name = next_month.strftime("%B") assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{prev_month.year}/#{prev_month.month}"}, :content => prev_month_name assert_tag :tag =>'a', :attributes => {:href => "/profile/#{profile.identifier}/events/#{next_month.year}/#{next_month.month}"}, :content => next_month_name end should 'see the events paginated' do 30.times do |i| profile.events << Event.new(:name => "Lesson #{i}", :start_date => DateTime.now) end get :events, :profile => profile.identifier assert_equal 20, assigns(:events).size end should "show events for current month only" do profile.events << Event.create(:name => 'Maria Birthday', :start_date => DateTime.now.at_end_of_month - 1) profile.events << Event.create(:name => 'Joao Birthday', :start_date => DateTime.now + 31) get :events, :profile => profile.identifier assert_no_tag :tag =>'a', :content => /Joao Birthday/ assert_tag :tag =>'a', :content => /Maria Birthday/ end should 'show events of specific day' do profile.events << Event.new(:name => 'Joao Birthday', :start_date => DateTime.new(2009, 10, 28)) get :events_by_day, :profile => profile.identifier, :year => 2009, :month => 10, :day => 28 assert_tag :tag => 'a', :content => /Joao Birthday/ end should 'not show events page to non members of private community' do community = fast_create(Community, :identifier => 'private-community', :name => 'Private Community', :public_profile => false) post :events, :profile => community.identifier assert_response :forbidden assert_template "profile/_private_profile" end should 'not show events page to non members of invisible community' do community = fast_create(Community, :identifier => 'invisible-community', :name => 'Private Community', :visible => false) post :events, :profile => community.identifier assert_response :forbidden assert_template 'shared/access_denied' end should 'show events page to members of private community' do community = fast_create(Community, :identifier => 'private-community', :name => 'Private Community', :public_profile => false) community.add_member(@profile) login_as('testuser') post :events, :profile => community.identifier assert_response :success end end |