enterprise_registration_controller_test.rb
2.85 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require File.dirname(__FILE__) + '/../test_helper'
require 'enterprise_registration_controller'
# Re-raise errors caught by the controller.
class EnterpriseRegistrationController; def rescue_action(e) raise e end; end
class EnterpriseRegistrationControllerTest < Test::Unit::TestCase
fixtures :users
def setup
@controller = EnterpriseRegistrationController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
login_as 'ze'
end
should 'go to the first step on index' do
get :index
assert_response :success
assert_template 'basic_information'
end
should 'prompt for basic information' do
get :index
%w[ name identifier address contact_phone contact_person
acronym foundation_year legal_form economic_activity ].each do |item|
assert_tag :tag => 'input', :attributes => { :name => "create_enterprise[#{item}]" }
end
assert_tag :tag => 'textarea', :attributes => { :name => "create_enterprise[management_information]"}
assert_tag :tag => 'select', :attributes => { :name => "create_enterprise[region_id]"}
end
should 'get back to entering basic information if data is invalid' do
post :index, :create_enterprise => {}
assert_response :success
assert_template 'basic_information'
end
should 'prompt for selecting validator' do
data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' }
create_enterprise = CreateEnterprise.new
CreateEnterprise.expects(:new).with(data).returns(create_enterprise)
validator1 = mock()
validator1.expects(:id).returns(1)
validator1.expects(:name).returns("validator1")
validator2 = mock()
validator2.expects(:id).returns(2)
validator2.expects(:name).returns("validator2")
region = mock()
region.expects(:validators).returns([validator1, validator2]).at_least_once
create_enterprise.expects(:region).returns(region)
# all data but validator selected
create_enterprise.expects(:valid_before_selecting_target?).returns(true)
create_enterprise.expects(:valid?).returns(false)
post :index, :create_enterprise => data
assert_template 'select_validator'
end
should 'provide confirmation at the end of the process' do
data = { 'name' => 'My new enterprise', 'identifier' => 'mynew' }
create_enterprise = CreateEnterprise.new
CreateEnterprise.expects(:new).with(data).returns(create_enterprise)
# all including validator selected
validator = mock()
validator.stubs(:name).returns("lalala")
create_enterprise.expects(:valid_before_selecting_target?).returns(true)
create_enterprise.expects(:valid?).returns(true) # validator already selected
create_enterprise.expects(:save!)
create_enterprise.expects(:target).returns(validator)
post :index, :create_enterprise => data
assert_template 'confirmation'
end
end