aboutsummaryrefslogtreecommitdiff
blob: 2dd5bde7d799ac90e0b9c6a942884783dcade973 (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
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
require 'spec_helper.rb'

describe User do
  it "should run spec test with shoulda and models from application" do
    Guest.new.should_not be_administrator
  end

  it "should set correct roles for new user" do
    u = User.new :name => 'Example', :email => 'example@example.com',
                  :password => 'Example', :irc_nick => 'example'
    u.save!
    u.should_not be_administrator
    u.should_not be_council_member
    u.should_not be_guest
    u.should     be_signed_up
  end

  describe '.slacking_status_in_period' do
    it 'should give "Was on last meeting" slacking status to user who was on all meetings' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a)
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'Was on last meeting'
    end

    it 'should give "Was on last meeting" slacking status to user who was on last meeting and skipped some meetings in past (but not two consecutive)' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a) if i.even?
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'Was on last meeting'
    end

    it 'should give "Skipped last meeting" slacking status to user who was absent on last meeting and skipped some meetings in past (but not two consecutive)' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a) if i.odd?
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'Skipped last meeting'
    end

    it 'should give "Slacker" slacking status to user who was present on last meeting skipped two consecutive meeting in the past' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a) unless [1, 3, 5, 6].include?(i)
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'Slacker'
    end

    it 'should give "No more a council" slacking status to user who skipped two consecutive meeting in the past and the last one' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a) unless [1, 3, 5, 6, 10].include?(i)
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'No more a council'
    end

    it 'should give "No more a council" slacking status to user who skipped two consecutive meeting in the past and then one more' do
      u = users_factory(:council)
      agendas = (1..10).collect do |i|
        a = Factory(:agenda, :state => 'old')
        Factory(:participation, :participant => u, :agenda => a) unless [5, 6, 8].include?(i)
        a
      end
      u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                    agendas.last.meeting_time + 1.minute).should == 'No more a council'
    end
  end
end