Commit cd3edc920b84d558267fa128f1c53f762ac12ff1
Exists in
master
and in
15 other branches
Merge branch 'plugins_to_rails4' into 'master'
Plugins to rails4 Migrate sub_organization and recent_content plugins to rails 4. See merge request !765
Showing
13 changed files
with
213 additions
and
209 deletions
Show diff stats
plugins/sub_organizations/test/functional/sub_organizations_plugin_myprofile_controller_test.rb
1 | 1 | require 'test_helper' |
2 | 2 | require_relative '../../controllers/sub_organizations_plugin_myprofile_controller' |
3 | 3 | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class SubOrganizationsPluginMyprofileController; def rescue_action(e) raise e end; end | |
6 | + | |
4 | 7 | class SubOrganizationsPluginMyprofileControllerTest < ActionController::TestCase |
5 | 8 | def setup |
6 | 9 | @controller = SubOrganizationsPluginMyprofileController.new | ... | ... |
plugins/sub_organizations/test/functional/sub_organizations_plugin_profile_controller_test.rb
1 | 1 | require 'test_helper' |
2 | 2 | require_relative '../../controllers/sub_organizations_plugin_profile_controller' |
3 | 3 | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class SubOrganizationsPluginProfileController; def rescue_action(e) raise e end; end | |
6 | + | |
4 | 7 | class SubOrganizationsPluginProfileControllerTest < ActionController::TestCase |
5 | 8 | |
6 | 9 | def setup | ... | ... |
plugins/sub_organizations/test/unit/approve_paternity_relation_test.rb
0 → 100644
... | ... | @@ -0,0 +1,32 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class ApprovePaternityRelationTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @requestor = create_user('some-user').person | |
7 | + end | |
8 | + | |
9 | + attr_reader :requestor | |
10 | + | |
11 | + should 'return parent' do | |
12 | + org1 = fast_create(Organization) | |
13 | + org2 = fast_create(Organization) | |
14 | + task = SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org2, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name) | |
15 | + | |
16 | + assert_equal SubOrganizationsPlugin::ApprovePaternityRelation.parent_approval(task), org1 | |
17 | + end | |
18 | + | |
19 | + should 'list pending children' do | |
20 | + organization = fast_create(Organization) | |
21 | + org1 = fast_create(Organization) | |
22 | + org2 = fast_create(Organization) | |
23 | + org3 = fast_create(Organization) | |
24 | + | |
25 | + SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org1, :temp_parent_id => organization.id, :temp_parent_type => organization.class.name) | |
26 | + SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org2, :temp_parent_id => organization.id, :temp_parent_type => organization.class.name) | |
27 | + | |
28 | + assert_includes Organization.pending_children(organization), org1 | |
29 | + assert_includes Organization.pending_children(organization), org2 | |
30 | + assert_not_includes Organization.pending_children(organization), org3 | |
31 | + end | |
32 | +end | ... | ... |
plugins/sub_organizations/test/unit/approve_paternity_test.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class ApprovePaternityTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @requestor = create_user('some-user').person | |
7 | + end | |
8 | + | |
9 | + attr_reader :requestor | |
10 | + | |
11 | + should 'create relation after creation' do | |
12 | + org1 = fast_create(Organization) | |
13 | + org2 = fast_create(Organization) | |
14 | + assert_difference 'SubOrganizationsPlugin::ApprovePaternityRelation.count', 1 do | |
15 | + SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name, :target => org2) | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + should 'add children to parent after approving' do | |
20 | + org1 = fast_create(Organization) | |
21 | + org2 = fast_create(Organization) | |
22 | + | |
23 | + task = SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name, :target => org2) | |
24 | + assert_not_includes Organization.children(org1), org2 | |
25 | + | |
26 | + task.finish | |
27 | + assert_includes Organization.children(org1), org2 | |
28 | + end | |
29 | +end | ... | ... |
plugins/sub_organizations/test/unit/create_enterprise_test.rb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class CreateEnterpriseTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'inlude the parent field in create enterprise' do | |
6 | + create_enterprise = CreateEnterprise.new | |
7 | + assert_nothing_raised { create_enterprise.sub_organizations_plugin_parent_to_be = '999' } | |
8 | + end | |
9 | + | |
10 | +end | ... | ... |
plugins/sub_organizations/test/unit/organization_test.rb
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class OrganizationTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'inlude the parent field in organization' do | |
6 | + organization = Organization.new | |
7 | + assert_nothing_raised { organization.sub_organizations_plugin_parent_to_be = '999' } | |
8 | + end | |
9 | + | |
10 | + should 'include the parent field in the FIELDS constant' do | |
11 | + assert_includes Organization::FIELDS, 'sub_organizations_plugin_parent_to_be' | |
12 | + end | |
13 | + | |
14 | + should 'relate organization with parent if the attribute is set' do | |
15 | + parent = fast_create(Organization) | |
16 | + organization = build(Organization, :identifier => 'some-org',:name => 'Some Org', :sub_organizations_plugin_parent_to_be => parent.id) | |
17 | + assert_not_includes Organization.children(parent), organization | |
18 | + | |
19 | + organization.save! | |
20 | + assert_includes Organization.children(parent), organization | |
21 | + end | |
22 | + | |
23 | +end | ... | ... |
... | ... | @@ -0,0 +1,110 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class RelationTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'validates presence of child and parent' do | |
6 | + org = fast_create(Organization) | |
7 | + relation = SubOrganizationsPlugin::Relation.new | |
8 | + | |
9 | + relation.parent = org | |
10 | + relation.valid? | |
11 | + assert relation.errors.include?(:child) | |
12 | + | |
13 | + relation.parent = nil | |
14 | + relation.child = org | |
15 | + relation.valid? | |
16 | + assert relation.errors.include?(:parent) | |
17 | + end | |
18 | + | |
19 | + should 'relate two organizations' do | |
20 | + org1 = fast_create(Organization) | |
21 | + org2 = fast_create(Organization) | |
22 | + relation = SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
23 | + | |
24 | + assert_equal org1, relation.parent | |
25 | + assert_equal org2, relation.child | |
26 | + end | |
27 | + | |
28 | + should 'not allow self relation' do | |
29 | + org = fast_create(Organization) | |
30 | + relation = SubOrganizationsPlugin::Relation.new(:parent => org, :child => org) | |
31 | + refute relation.valid? | |
32 | + assert relation.errors.include?(:child) | |
33 | + end | |
34 | + | |
35 | + should 'be able to retrieve parents of an organization' do | |
36 | + child = fast_create(Organization) | |
37 | + parent1 = fast_create(Organization) | |
38 | + parent2 = fast_create(Organization) | |
39 | + SubOrganizationsPlugin::Relation.create!(:parent => parent1, :child => child) | |
40 | + SubOrganizationsPlugin::Relation.create!(:parent => parent2, :child => child) | |
41 | + | |
42 | + assert_includes Organization.parents(child), parent1 | |
43 | + assert_includes Organization.parents(child), parent2 | |
44 | + end | |
45 | + | |
46 | + should 'be able to retrieve children of an organization' do | |
47 | + parent = fast_create(Organization) | |
48 | + child1 = fast_create(Organization) | |
49 | + child2 = fast_create(Organization) | |
50 | + SubOrganizationsPlugin::Relation.create!(:parent => parent, :child => child1) | |
51 | + SubOrganizationsPlugin::Relation.create!(:parent => parent, :child => child2) | |
52 | + | |
53 | + assert_includes Organization.children(parent), child1 | |
54 | + assert_includes Organization.children(parent), child2 | |
55 | + end | |
56 | + | |
57 | + should 'not allow cyclical reference' do | |
58 | + org1 = fast_create(Organization) | |
59 | + org2 = fast_create(Organization) | |
60 | + SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
61 | + relation = SubOrganizationsPlugin::Relation.new(:parent => org2, :child => org1) | |
62 | + | |
63 | + refute relation.valid? | |
64 | + assert relation.errors.include?(:child) | |
65 | + end | |
66 | + | |
67 | + should 'not allow multi-level paternity' do | |
68 | + org1 = fast_create(Organization) | |
69 | + org2 = fast_create(Organization) | |
70 | + org3 = fast_create(Organization) | |
71 | + SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
72 | + r1 = SubOrganizationsPlugin::Relation.new(:parent => org2, :child => org3) | |
73 | + r2 = SubOrganizationsPlugin::Relation.new(:parent => org3, :child => org1) | |
74 | + | |
75 | + refute r1.valid? | |
76 | + assert r1.errors.include?(:child) | |
77 | + | |
78 | + refute r2.valid? | |
79 | + assert r2.errors.include?(:child) | |
80 | + end | |
81 | + | |
82 | + should 'add children' do | |
83 | + org1 = fast_create(Organization) | |
84 | + org2 = fast_create(Organization) | |
85 | + org3 = fast_create(Organization) | |
86 | + org4 = fast_create(Organization) | |
87 | + | |
88 | + SubOrganizationsPlugin::Relation.add_children(org1,org2) | |
89 | + assert_includes Organization.children(org1), org2 | |
90 | + | |
91 | + SubOrganizationsPlugin::Relation.add_children(org1,org3,org4) | |
92 | + assert_includes Organization.children(org1), org3 | |
93 | + assert_includes Organization.children(org1), org4 | |
94 | + end | |
95 | + | |
96 | + should 'remove children' do | |
97 | + org1 = fast_create(Organization) | |
98 | + org2 = fast_create(Organization) | |
99 | + org3 = fast_create(Organization) | |
100 | + org4 = fast_create(Organization) | |
101 | + SubOrganizationsPlugin::Relation.add_children(org1,org2,org3,org4) | |
102 | + | |
103 | + SubOrganizationsPlugin::Relation.remove_children(org1,org2) | |
104 | + assert_not_includes Organization.children(org1), org2 | |
105 | + | |
106 | + SubOrganizationsPlugin::Relation.remove_children(org1,org3,org4) | |
107 | + assert_not_includes Organization.children(org1), org3 | |
108 | + assert_not_includes Organization.children(org1), org4 | |
109 | + end | |
110 | +end | ... | ... |
plugins/sub_organizations/test/unit/sub_organizations_plugin/approve_paternity_relation_test.rb
... | ... | @@ -1,32 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class SubOrganizationsPlugin::ApprovePaternityRelationTest < ActiveSupport::TestCase | |
4 | - | |
5 | - def setup | |
6 | - @requestor = create_user('some-user').person | |
7 | - end | |
8 | - | |
9 | - attr_reader :requestor | |
10 | - | |
11 | - should 'return parent' do | |
12 | - org1 = fast_create(Organization) | |
13 | - org2 = fast_create(Organization) | |
14 | - task = SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org2, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name) | |
15 | - | |
16 | - assert_equal SubOrganizationsPlugin::ApprovePaternityRelation.parent_approval(task), org1 | |
17 | - end | |
18 | - | |
19 | - should 'list pending children' do | |
20 | - organization = fast_create(Organization) | |
21 | - org1 = fast_create(Organization) | |
22 | - org2 = fast_create(Organization) | |
23 | - org3 = fast_create(Organization) | |
24 | - | |
25 | - SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org1, :temp_parent_id => organization.id, :temp_parent_type => organization.class.name) | |
26 | - SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :target => org2, :temp_parent_id => organization.id, :temp_parent_type => organization.class.name) | |
27 | - | |
28 | - assert_includes Organization.pending_children(organization), org1 | |
29 | - assert_includes Organization.pending_children(organization), org2 | |
30 | - assert_not_includes Organization.pending_children(organization), org3 | |
31 | - end | |
32 | -end |
plugins/sub_organizations/test/unit/sub_organizations_plugin/approve_paternity_test.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class SubOrganizationsPlugin::ApprovePaternityTest < ActiveSupport::TestCase | |
4 | - | |
5 | - def setup | |
6 | - @requestor = create_user('some-user').person | |
7 | - end | |
8 | - | |
9 | - attr_reader :requestor | |
10 | - | |
11 | - should 'create relation after creation' do | |
12 | - org1 = fast_create(Organization) | |
13 | - org2 = fast_create(Organization) | |
14 | - assert_difference 'SubOrganizationsPlugin::ApprovePaternityRelation.count', 1 do | |
15 | - SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name, :target => org2) | |
16 | - end | |
17 | - end | |
18 | - | |
19 | - should 'add children to parent after approving' do | |
20 | - org1 = fast_create(Organization) | |
21 | - org2 = fast_create(Organization) | |
22 | - | |
23 | - task = SubOrganizationsPlugin::ApprovePaternity.create!(:requestor => requestor, :temp_parent_id => org1.id, :temp_parent_type => org1.class.name, :target => org2) | |
24 | - assert_not_includes Organization.children(org1), org2 | |
25 | - | |
26 | - task.finish | |
27 | - assert_includes Organization.children(org1), org2 | |
28 | - end | |
29 | -end |
plugins/sub_organizations/test/unit/sub_organizations_plugin/ext/create_enterprise_test.rb
... | ... | @@ -1,11 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class CreateEnterpriseTest < ActiveSupport::TestCase | |
4 | - | |
5 | - should 'inlude the parent field in create enterprise' do | |
6 | - create_enterprise = CreateEnterprise.new | |
7 | - assert_nothing_raised { create_enterprise.sub_organizations_plugin_parent_to_be = '999' } | |
8 | - end | |
9 | - | |
10 | -end | |
11 | - |
plugins/sub_organizations/test/unit/sub_organizations_plugin/ext/organization.rb
... | ... | @@ -1,23 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class OrganizationTest < ActiveSupport::TestCase | |
4 | - | |
5 | - should 'inlude the parent field in organization' do | |
6 | - organization = Organization.new | |
7 | - assert_nothing_raised { organization.sub_organizations_plugin_parent_to_be = '999' } | |
8 | - end | |
9 | - | |
10 | - should 'include the parent field in the FIELDS constant' do | |
11 | - assert_includes Organization::FIELDS, 'sub_organizations_plugin_parent_to_be' | |
12 | - end | |
13 | - | |
14 | - should 'relate organization with parent if the attribute is set' do | |
15 | - parent = fast_create(Organization) | |
16 | - organization = build(Organization, :identifier => 'some-org',:name => 'Some Org', :sub_organizations_plugin_parent_to_be => parent.id) | |
17 | - assert_not_includes Organization.children(parent), organization | |
18 | - | |
19 | - organization.save! | |
20 | - assert_includes Organization.children(parent), organization | |
21 | - end | |
22 | - | |
23 | -end |
plugins/sub_organizations/test/unit/sub_organizations_plugin/relation_test.rb
... | ... | @@ -1,110 +0,0 @@ |
1 | -require 'test_helper' | |
2 | - | |
3 | -class SubOrganizationsPlugin::RelationTest < ActiveSupport::TestCase | |
4 | - | |
5 | - should 'validates presence of child and parent' do | |
6 | - org = fast_create(Organization) | |
7 | - relation = SubOrganizationsPlugin::Relation.new | |
8 | - | |
9 | - relation.parent = org | |
10 | - relation.valid? | |
11 | - assert relation.errors.include?(:child) | |
12 | - | |
13 | - relation.parent = nil | |
14 | - relation.child = org | |
15 | - relation.valid? | |
16 | - assert relation.errors.include?(:parent) | |
17 | - end | |
18 | - | |
19 | - should 'relate two organizations' do | |
20 | - org1 = fast_create(Organization) | |
21 | - org2 = fast_create(Organization) | |
22 | - relation = SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
23 | - | |
24 | - assert_equal org1, relation.parent | |
25 | - assert_equal org2, relation.child | |
26 | - end | |
27 | - | |
28 | - should 'not allow self relation' do | |
29 | - org = fast_create(Organization) | |
30 | - relation = SubOrganizationsPlugin::Relation.new(:parent => org, :child => org) | |
31 | - refute relation.valid? | |
32 | - assert relation.errors.include?(:child) | |
33 | - end | |
34 | - | |
35 | - should 'be able to retrieve parents of an organization' do | |
36 | - child = fast_create(Organization) | |
37 | - parent1 = fast_create(Organization) | |
38 | - parent2 = fast_create(Organization) | |
39 | - SubOrganizationsPlugin::Relation.create!(:parent => parent1, :child => child) | |
40 | - SubOrganizationsPlugin::Relation.create!(:parent => parent2, :child => child) | |
41 | - | |
42 | - assert_includes Organization.parents(child), parent1 | |
43 | - assert_includes Organization.parents(child), parent2 | |
44 | - end | |
45 | - | |
46 | - should 'be able to retrieve children of an organization' do | |
47 | - parent = fast_create(Organization) | |
48 | - child1 = fast_create(Organization) | |
49 | - child2 = fast_create(Organization) | |
50 | - SubOrganizationsPlugin::Relation.create!(:parent => parent, :child => child1) | |
51 | - SubOrganizationsPlugin::Relation.create!(:parent => parent, :child => child2) | |
52 | - | |
53 | - assert_includes Organization.children(parent), child1 | |
54 | - assert_includes Organization.children(parent), child2 | |
55 | - end | |
56 | - | |
57 | - should 'not allow cyclical reference' do | |
58 | - org1 = fast_create(Organization) | |
59 | - org2 = fast_create(Organization) | |
60 | - SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
61 | - relation = SubOrganizationsPlugin::Relation.new(:parent => org2, :child => org1) | |
62 | - | |
63 | - refute relation.valid? | |
64 | - assert relation.errors.include?(:child) | |
65 | - end | |
66 | - | |
67 | - should 'not allow multi-level paternity' do | |
68 | - org1 = fast_create(Organization) | |
69 | - org2 = fast_create(Organization) | |
70 | - org3 = fast_create(Organization) | |
71 | - SubOrganizationsPlugin::Relation.create!(:parent => org1, :child => org2) | |
72 | - r1 = SubOrganizationsPlugin::Relation.new(:parent => org2, :child => org3) | |
73 | - r2 = SubOrganizationsPlugin::Relation.new(:parent => org3, :child => org1) | |
74 | - | |
75 | - refute r1.valid? | |
76 | - assert r1.errors.include?(:child) | |
77 | - | |
78 | - refute r2.valid? | |
79 | - assert r2.errors.include?(:child) | |
80 | - end | |
81 | - | |
82 | - should 'add children' do | |
83 | - org1 = fast_create(Organization) | |
84 | - org2 = fast_create(Organization) | |
85 | - org3 = fast_create(Organization) | |
86 | - org4 = fast_create(Organization) | |
87 | - | |
88 | - SubOrganizationsPlugin::Relation.add_children(org1,org2) | |
89 | - assert_includes Organization.children(org1), org2 | |
90 | - | |
91 | - SubOrganizationsPlugin::Relation.add_children(org1,org3,org4) | |
92 | - assert_includes Organization.children(org1), org3 | |
93 | - assert_includes Organization.children(org1), org4 | |
94 | - end | |
95 | - | |
96 | - should 'remove children' do | |
97 | - org1 = fast_create(Organization) | |
98 | - org2 = fast_create(Organization) | |
99 | - org3 = fast_create(Organization) | |
100 | - org4 = fast_create(Organization) | |
101 | - SubOrganizationsPlugin::Relation.add_children(org1,org2,org3,org4) | |
102 | - | |
103 | - SubOrganizationsPlugin::Relation.remove_children(org1,org2) | |
104 | - assert_not_includes Organization.children(org1), org2 | |
105 | - | |
106 | - SubOrganizationsPlugin::Relation.remove_children(org1,org3,org4) | |
107 | - assert_not_includes Organization.children(org1), org3 | |
108 | - assert_not_includes Organization.children(org1), org4 | |
109 | - end | |
110 | -end |
plugins/sub_organizations/test/unit/sub_organizations_plugin_test.rb
1 | 1 | require 'test_helper' |
2 | 2 | |
3 | -class SubOrganizationsTest < ActiveSupport::TestCase | |
3 | +class SubOrganizationsPluginTest < ActiveSupport::TestCase | |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @plugin = SubOrganizationsPlugin.new |
... | ... | @@ -29,7 +29,7 @@ class SubOrganizationsTest < ActiveSupport::TestCase |
29 | 29 | |
30 | 30 | org1_members = plugin.organization_members(org1) |
31 | 31 | |
32 | - assert_equal ActiveRecord::Relation, org1_members.class | |
32 | + assert_equal Person::ActiveRecord_Relation, org1_members.class | |
33 | 33 | assert_not_includes org1_members, member1 |
34 | 34 | assert_includes org1_members, member2 |
35 | 35 | assert_includes org1_members, member3 |
... | ... | @@ -59,7 +59,7 @@ class SubOrganizationsTest < ActiveSupport::TestCase |
59 | 59 | person1_memberships = plugin.person_memberships(person1) |
60 | 60 | person2_memberships = plugin.person_memberships(person2) |
61 | 61 | |
62 | - assert_equal ActiveRecord::Relation, person1_memberships.class | |
62 | + assert_equal Organization::ActiveRecord_Relation, person1_memberships.class | |
63 | 63 | assert_includes person1_memberships, org1 |
64 | 64 | assert_not_includes person1_memberships, org2 |
65 | 65 | assert_not_includes person1_memberships, org3 |
... | ... | @@ -109,4 +109,3 @@ class SubOrganizationsTest < ActiveSupport::TestCase |
109 | 109 | assert_nil plugin.control_panel_buttons |
110 | 110 | end |
111 | 111 | end |
112 | - | ... | ... |