cirandas.net

ref: master

test/unit/events_helper_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
 97
 98
 99
100
require_relative "../test_helper"

class EventsHelperTest < ActionView::TestCase

  include EventsHelper

  should 'list events' do
    user = create_user('userwithevents').person
    stubs(:user).returns(user)

    event1 = Event.new(name: "Event 1", start_date: Date.today, end_date: (Date.today + 1.day), address: 'The Shire')
    event1.profile = user
    event1.save

    event2 = Event.new(name: 'Event 2', start_date: Date.today, end_date: (Date.today + 1.day), address: 'Valfenda')
    event2.profile = user
    event2.save

    result = list_events(Date.today, [event1, event2])

    assert_match /Event 1/, result
    assert_match /Event 2/, result
  end

  should 'populate calendar with links on days that have events' do
    user = create_user('userwithevents').person
    stubs(:user).returns(user)
    event = fast_create(Event, :profile_id => user.id)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, true, true]
  end

  should 'hide private events from guests' do
    user = create_user('userwithevents').person
    stubs(:user).returns(nil)
    event = fast_create(Event, :profile_id => user.id, :published => false)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, false, true]
  end

  should 'hide events from invisible profiles from guests' do
    user = create_user('usernonvisible', {}, {:visible => false}).person
    stubs(:user).returns(nil)
    event = fast_create(Event, :profile_id => user.id)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, false, true]
  end

  should 'hide events from private profiles from guests' do
    user = create_user('usernonvisible', {}, {:visible => false}).person
    stubs(:user).returns(nil)
    event = fast_create(Event, :profile_id => user.id)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, false, true]
  end

  should 'show private events to owner' do
    user = create_user('userwithevents').person
    stubs(:user).returns(user)
    event = fast_create(Event, :profile_id => user.id, :published => false)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, true, true]
  end

  should 'show events from invisible profiles to owner' do
    user = create_user('usernonvisible', {}, {:visible => false}).person
    stubs(:user).returns(user)
    event = fast_create(Event, :profile_id => user.id)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, true, true]
  end

  should 'show events from private profiles to owner' do
    user = create_user('usernonvisible', {}, {:visible => false}).person
    stubs(:user).returns(user)
    event = fast_create(Event, :profile_id => user.id)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, true, true]
  end

  should 'populate calendar for dates with timezone' do
    user = create_user('userwithevents').person
    stubs(:user).returns(user)
    event = fast_create(Event, :profile_id => user.id, :start_date => ActiveSupport::TimeZone.new('Brasilia').now)
    date = event.start_date
    calendar = populate_calendar(date, Environment.default.events)
    assert_includes calendar, [date.to_date, true, true]
  end

  protected
  include NoosferoTestHelper

end