enterprise_activation_test.rb
1.93 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class EnterpriseActivationTest < ActiveSupport::TestCase
  fixtures :users, :profiles
  should 'be a Task' do
    assert_kind_of Task, EnterpriseActivation.new
  end
  should 'keep enterprise_id' do
    assert_nil EnterpriseActivation.new.enterprise_id
  end
  should 'have an enteprise through enterprise_id' do
    ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent')
    assert_equal ent, EnterpriseActivation.new(:enterprise_id => ent.id).enterprise
  end
  should 'require an enterprise' do
    t = EnterpriseActivation.new
    t.valid?
    assert t.errors.invalid?(:enterprise_id), "enterprise must be required"
    ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent')
    t.enterprise = ent
    t.valid?
    assert !t.errors.invalid?(:enterprise_id), "must validate after enterprise is set"
  end
  should 'activate enterprise when finished' do
    ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :enabled => false)
    t = EnterpriseActivation.create!(:enterprise => ent)
    t.requestor = profiles(:ze)
    t.finish
    ent.reload
    assert ent.enabled, "finishing task should left enterprise enabled"
  end
  should 'require requestor to finish' do
    ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :enabled => false)
    t = EnterpriseActivation.create!(:enterprise => ent)
    assert_raise EnterpriseActivation::RequestorRequired do
      t.finish
    end
  end
  should 'put requestor as enterprise owner when finishing' do
    ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :enabled => false)
    t = EnterpriseActivation.create!(:enterprise => ent)
    person = profiles(:ze)
    t.requestor = person
    t.stubs(:enterprise).returns(ent)
    # must pass the requestor to the enterprise activation
    ent.expects(:enable).with(person)
    t.finish
  end
end