summaryrefslogtreecommitdiff
path: root/test/unit/conference_test.rb
blob: 85f7ddb1ac580c542f8755d652a6037bea05ba68 (plain)
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
require 'test_helper'

class ConferenceTest < ActiveSupport::TestCase
  
  def test_should_have_a_valid_factory
    assert FactoryGirl.build(:conference).valid?
  end
  
  def test_dates_must_make_sense
    # We can't create a conference in the past.
    assert !FactoryGirl.build(:conference, :start => Time.now - 1.day, :end => Time.now + 1.day).valid?
    
    # But we can create a conference which started 2 minutes ago.
    assert FactoryGirl.build(:conference, :start => Time.now - 2.minutes, :end => Time.now + 1.hour).valid?
    
    # The end must be before the start.
    assert !FactoryGirl.build(:conference, :start => Time.now + 2.day, :end => Time.now + 1.day).valid?
    
    # No date at all is fine.
    assert FactoryGirl.build(:conference, :start => nil, :end => nil).valid?
    
    # Just start or just end is not ok.
    assert !FactoryGirl.build(:conference, :start => nil, :end => Time.now + 1.day).valid?
    assert !FactoryGirl.build(:conference, :start => Time.now + 1.day, :end => nil).valid?
  end
  
  def test_pin_must_be_nil_or_more_than_6_digits
    conference = FactoryGirl.build(:conference, :pin => nil)
    
    assert conference.valid?
    
    (MINIMUM_PIN_LENGTH - 1).times do |i|
      pin = "#{10**i}"
      conference.pin = pin
      assert !conference.valid?      
    end
    
    conference.pin = "#{10**(MINIMUM_PIN_LENGTH - 1)}"
    assert conference.valid? 

    conference.pin = "-#{10**(MINIMUM_PIN_LENGTH - 1)}"
    assert !conference.valid?     
    
    conference.pin = 'Teststring'
    assert !conference.valid?     
  end
  
end