arpa 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +42 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +138 -0
  8. data/Rakefile +2 -0
  9. data/arpa.gemspec +33 -0
  10. data/lib/arpa.rb +91 -0
  11. data/lib/arpa/additions/resource.rb +29 -0
  12. data/lib/arpa/assets/stylesheets/ar_accordion.scss +80 -0
  13. data/lib/arpa/controllers/profiles_controller.rb +106 -0
  14. data/lib/arpa/controllers/resources_controller.rb +47 -0
  15. data/lib/arpa/controllers/roles_controller.rb +106 -0
  16. data/lib/arpa/data_mappers/action_mapper.rb +13 -0
  17. data/lib/arpa/data_mappers/base.rb +117 -0
  18. data/lib/arpa/data_mappers/profile_mapper.rb +14 -0
  19. data/lib/arpa/data_mappers/resource_mapper.rb +11 -0
  20. data/lib/arpa/data_mappers/role_mapper.rb +14 -0
  21. data/lib/arpa/entities/action.rb +24 -0
  22. data/lib/arpa/entities/permissions.rb +35 -0
  23. data/lib/arpa/entities/profile.rb +22 -0
  24. data/lib/arpa/entities/resource.rb +58 -0
  25. data/lib/arpa/entities/role.rb +28 -0
  26. data/lib/arpa/exceptions/record_invalid.rb +13 -0
  27. data/lib/arpa/repositories/actions/creator.rb +18 -0
  28. data/lib/arpa/repositories/actions/finder.rb +23 -0
  29. data/lib/arpa/repositories/actions/remover.rb +22 -0
  30. data/lib/arpa/repositories/actions/repository_action.rb +15 -0
  31. data/lib/arpa/repositories/base.rb +15 -0
  32. data/lib/arpa/repositories/profiles/creator.rb +18 -0
  33. data/lib/arpa/repositories/profiles/finder.rb +29 -0
  34. data/lib/arpa/repositories/profiles/remover.rb +29 -0
  35. data/lib/arpa/repositories/profiles/repository_profile.rb +12 -0
  36. data/lib/arpa/repositories/profiles/updater.rb +23 -0
  37. data/lib/arpa/repositories/registrator.rb +44 -0
  38. data/lib/arpa/repositories/resources/creator.rb +18 -0
  39. data/lib/arpa/repositories/resources/finder.rb +45 -0
  40. data/lib/arpa/repositories/resources/remover.rb +22 -0
  41. data/lib/arpa/repositories/resources/repository_resource.rb +12 -0
  42. data/lib/arpa/repositories/roles/creator.rb +18 -0
  43. data/lib/arpa/repositories/roles/finder.rb +29 -0
  44. data/lib/arpa/repositories/roles/remover.rb +29 -0
  45. data/lib/arpa/repositories/roles/repository_role.rb +13 -0
  46. data/lib/arpa/repositories/roles/updater.rb +23 -0
  47. data/lib/arpa/services/actions/create/action_creator.rb +50 -0
  48. data/lib/arpa/services/actions/remove/action_remover.rb +24 -0
  49. data/lib/arpa/services/base.rb +41 -0
  50. data/lib/arpa/services/profiles/create/profile_creator.rb +32 -0
  51. data/lib/arpa/services/profiles/profile_manager_creator.rb +22 -0
  52. data/lib/arpa/services/profiles/profile_manager_remover.rb +24 -0
  53. data/lib/arpa/services/profiles/profile_manager_updater.rb +22 -0
  54. data/lib/arpa/services/profiles/remove/profile_remover.rb +25 -0
  55. data/lib/arpa/services/profiles/update/profile_updater.rb +32 -0
  56. data/lib/arpa/services/resources/create/resource_creator.rb +42 -0
  57. data/lib/arpa/services/resources/remove/resource_remover.rb +31 -0
  58. data/lib/arpa/services/resources/resource_manager_creator.rb +50 -0
  59. data/lib/arpa/services/roles/create/role_creator.rb +33 -0
  60. data/lib/arpa/services/roles/remove/role_remover.rb +25 -0
  61. data/lib/arpa/services/roles/role_manager_creator.rb +23 -0
  62. data/lib/arpa/services/roles/role_manager_remover.rb +23 -0
  63. data/lib/arpa/services/roles/role_manager_updater.rb +22 -0
  64. data/lib/arpa/services/roles/update/role_updater.rb +32 -0
  65. data/lib/arpa/services/verifier.rb +24 -0
  66. data/lib/arpa/validators/action_validator.rb +17 -0
  67. data/lib/arpa/validators/profile_validator.rb +19 -0
  68. data/lib/arpa/validators/resource_validator.rb +17 -0
  69. data/lib/arpa/validators/role_validator.rb +20 -0
  70. data/lib/arpa/version.rb +3 -0
  71. data/lib/arpa/views/profiles/_form.html.erb +41 -0
  72. data/lib/arpa/views/profiles/edit.html.erb +6 -0
  73. data/lib/arpa/views/profiles/index.html.erb +29 -0
  74. data/lib/arpa/views/profiles/new.html.erb +5 -0
  75. data/lib/arpa/views/profiles/show.html.erb +37 -0
  76. data/lib/arpa/views/resources/index.html.erb +27 -0
  77. data/lib/arpa/views/resources/show.html.erb +33 -0
  78. data/lib/arpa/views/roles/_form.html.erb +55 -0
  79. data/lib/arpa/views/roles/edit.html.erb +6 -0
  80. data/lib/arpa/views/roles/index.html.erb +29 -0
  81. data/lib/arpa/views/roles/new.html.erb +5 -0
  82. data/lib/arpa/views/roles/show.html.erb +37 -0
  83. data/lib/config/locales/arpa.en.yml +38 -0
  84. data/lib/generators/ar/install_generator.rb +74 -0
  85. data/lib/generators/ar/templates/migration.rb +48 -0
  86. data/spec/factories/repository_actions.rb +19 -0
  87. data/spec/factories/repository_profiles.rb +11 -0
  88. data/spec/factories/repository_resources.rb +15 -0
  89. data/spec/factories/repository_roles.rb +11 -0
  90. data/spec/lib/ar/additions/resource_spec.rb +34 -0
  91. data/spec/lib/ar/data_mappers/action_mapper_spec.rb +46 -0
  92. data/spec/lib/ar/data_mappers/base_spec.rb +47 -0
  93. data/spec/lib/ar/data_mappers/profile_mapper_spec.rb +43 -0
  94. data/spec/lib/ar/data_mappers/resource_mapper_spec.rb +38 -0
  95. data/spec/lib/ar/data_mappers/role_mapper_spec.rb +47 -0
  96. data/spec/lib/ar/entities/action_spec.rb +19 -0
  97. data/spec/lib/ar/entities/permissions_spec.rb +61 -0
  98. data/spec/lib/ar/entities/resource_spec.rb +35 -0
  99. data/spec/lib/ar/repositories/actions/finder_spec.rb +40 -0
  100. data/spec/lib/ar/repositories/base_spec.rb +37 -0
  101. data/spec/lib/ar/repositories/profiles/finder_spec.rb +43 -0
  102. data/spec/lib/ar/repositories/profiles/remover_spec.rb +31 -0
  103. data/spec/lib/ar/repositories/resources/finder_spec.rb +92 -0
  104. data/spec/lib/ar/repositories/resources/remover_spec.rb +38 -0
  105. data/spec/lib/ar/repositories/roles/finder_spec.rb +43 -0
  106. data/spec/lib/ar/repositories/roles/remover_spec.rb +31 -0
  107. data/spec/lib/ar/requests/profiles/create_request_spec.rb +51 -0
  108. data/spec/lib/ar/requests/profiles/remove_request_spec.rb +36 -0
  109. data/spec/lib/ar/requests/resources/create_request_spec.rb +107 -0
  110. data/spec/lib/ar/requests/roles/create_request_spec.rb +40 -0
  111. data/spec/lib/ar/requests/roles/remove_request_spec.rb +23 -0
  112. data/spec/lib/ar/requests/roles/update_request_spec.rb +50 -0
  113. data/spec/lib/ar/services/actions/create/action_creator_spec.rb +88 -0
  114. data/spec/lib/ar/services/actions/remove/action_remover_spec.rb +36 -0
  115. data/spec/lib/ar/services/base_spec.rb +94 -0
  116. data/spec/lib/ar/services/profiles/create/profile_creator_spec.rb +68 -0
  117. data/spec/lib/ar/services/profiles/profile_manager_creator_spec.rb +31 -0
  118. data/spec/lib/ar/services/profiles/profile_manager_remover_spec.rb +44 -0
  119. data/spec/lib/ar/services/profiles/profile_manager_updater_spec.rb +31 -0
  120. data/spec/lib/ar/services/profiles/remove/profile_remover_spec.rb +45 -0
  121. data/spec/lib/ar/services/profiles/update/profile_updater_spec.rb +68 -0
  122. data/spec/lib/ar/services/resources/create/resource_creator_spec.rb +87 -0
  123. data/spec/lib/ar/services/resources/remove/resource_remover_spec.rb +50 -0
  124. data/spec/lib/ar/services/resources/resource_manager_creator_spec.rb +71 -0
  125. data/spec/lib/ar/services/roles/create/role_creator_spec.rb +68 -0
  126. data/spec/lib/ar/services/roles/remove/role_remover_spec.rb +50 -0
  127. data/spec/lib/ar/services/roles/role_manager_creator_spec.rb +31 -0
  128. data/spec/lib/ar/services/roles/role_manager_remover_spec.rb +32 -0
  129. data/spec/lib/ar/services/roles/role_manager_updater_spec.rb +31 -0
  130. data/spec/lib/ar/services/roles/update/role_updater_spec.rb +68 -0
  131. data/spec/lib/ar/services/verifier_spec.rb +44 -0
  132. data/spec/lib/ar/validators/action_validator_spec.rb +15 -0
  133. data/spec/lib/ar/validators/profile_validator_spec.rb +16 -0
  134. data/spec/lib/ar/validators/resource_validator_spec.rb +15 -0
  135. data/spec/lib/ar/validators/role_validator_spec.rb +16 -0
  136. data/spec/spec_helper.rb +33 -0
  137. data/spec/support/repositories/test_repository.rb +2 -0
  138. data/spec/support/schema.rb +58 -0
  139. metadata +380 -0
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ class BaseImplementationTest
4
+ include Arpa::Repositories::Base
5
+ end
6
+
7
+ describe Arpa::Repositories::Base, type: :repository, fast: true do
8
+
9
+ let(:base_implementation) { BaseImplementationTest.new }
10
+
11
+ context 'when Implementation class do not override methods from Base' do
12
+
13
+ context 'when call :mapper_instance' do
14
+
15
+ it 'should raise NotImplementedError' do
16
+ expect { base_implementation.mapper_instance }.to raise_error do |error|
17
+ expect(error).to be_a NotImplementedError
18
+ expect(error.message).to eql 'This BaseImplementationTest cannot respond :mapper_instance'
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ context 'when call :repository_class' do
25
+
26
+ it 'should raise NotImplementedError' do
27
+ expect { base_implementation.repository_class}.to raise_error do |error|
28
+ expect(error).to be_a NotImplementedError
29
+ expect(error.message).to eql 'This BaseImplementationTest cannot respond :repository_class'
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Profiles::Finder, type: :repository, slow: true do
4
+
5
+ let(:record_001) { create :repository_profile, name: 'profile_01' }
6
+ let(:record_002) { create :repository_profile, name: 'profile_02' }
7
+
8
+ before do
9
+ record_001
10
+ record_002
11
+ end
12
+
13
+ describe '#find' do
14
+ let(:result) { subject.find(record_001.id) }
15
+
16
+ it 'the Profile entity should has name "profile_01"' do
17
+ expect(result.name).to eql 'profile_01'
18
+ end
19
+
20
+ it 'the result should be an Arpa::Entities::Profile' do
21
+ expect(result).to be_an Arpa::Entities::Profile
22
+ end
23
+
24
+ end
25
+
26
+ describe '#all' do
27
+ let(:result) { subject.all }
28
+
29
+ it 'should return size 2' do
30
+ expect(result.size).to be == 2
31
+ end
32
+
33
+ it 'the first Profile entity should has name "profile_01"' do
34
+ expect(result.first.name).to eql 'profile_01'
35
+ end
36
+
37
+ it 'the result should be an Array of Arpa::Entities::Profile' do
38
+ expect(result.first).to be_an Arpa::Entities::Profile
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Profiles::Remover, type: :repository, slow: true do
4
+
5
+ let(:created_profile) { create :repository_profile }
6
+
7
+ before { created_profile }
8
+
9
+ describe '#destroy' do
10
+ let(:destroy_profile) { subject.destroy(created_profile) }
11
+
12
+ it 'should destroy the role' do
13
+ expect { destroy_profile }.to change(Arpa::Repositories::Profiles::RepositoryProfile, :count).by(-1)
14
+ end
15
+
16
+ end
17
+
18
+ describe '#disable' do
19
+ let(:disable_profile) { subject.disable(created_profile) }
20
+
21
+ it 'should disable the role' do
22
+ expect { disable_profile }.to change(Arpa::Repositories::Profiles::RepositoryProfile, :count).by(-1)
23
+ end
24
+
25
+ it 'role should be setted to removed: true' do
26
+ expect(disable_profile.removed).to be_truthy
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Resources::Finder, type: :repository, slow: true do
4
+
5
+ let(:record_001) { create :repository_resource, :user }
6
+ let(:record_002) { create :repository_resource, :contact }
7
+
8
+ describe '#find' do
9
+ let(:result) { subject.find(record_001.id) }
10
+
11
+ it 'the Resource entity should has name "users"' do
12
+ expect(result.name).to eql 'users'
13
+ end
14
+
15
+ it 'the result should be an Arpa::Entities::Resource' do
16
+ expect(result).to be_an Arpa::Entities::Resource
17
+ end
18
+
19
+ end
20
+
21
+ describe '#all' do
22
+ let(:result) { subject.all }
23
+
24
+ before do
25
+ record_001
26
+ record_002
27
+ end
28
+
29
+
30
+ it 'should return size 2' do
31
+ expect(result.size).to be == 2
32
+ end
33
+
34
+ it 'the first Resource entity should has full_name "ContactsController"' do
35
+ expect(result.first.full_name).to eql 'ContactsController'
36
+ end
37
+
38
+ it 'the result should be an Array of Arpa::Entities::Resource' do
39
+ expect(result.first).to be_an Arpa::Entities::Resource
40
+ end
41
+
42
+ end
43
+
44
+ describe '#by_full_name' do
45
+
46
+ before do
47
+ record_001
48
+ record_002
49
+ end
50
+
51
+ context 'when exist with the full_name' do
52
+
53
+ let(:result) { subject.by_full_name('UsersController') }
54
+
55
+ it 'should return a resource with name "users"' do
56
+ expect(result.name).to eql 'users'
57
+ end
58
+
59
+ it 'the result should be an instance of Arpa::Entities::Resource' do
60
+ expect(result).to be_an Arpa::Entities::Resource
61
+ end
62
+ end
63
+
64
+ context 'when nonexist with the full_name' do
65
+
66
+ let(:result) { subject.by_full_name('NonessController') }
67
+
68
+ it 'the result should return nil' do
69
+ expect(result).to be_nil
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ describe 'getting permissions from profile_ids' do
76
+ let(:profile_001) { create :repository_profile, :with_complete_association, name: 'prof_001' }
77
+ let(:profile_002) { create :repository_profile, :with_complete_association, name: 'prof_002' }
78
+ let(:profile_ids) { [profile_001.id, profile_002.id] }
79
+
80
+ let(:result) { subject.permissions(profile_ids) }
81
+ let(:first) { result.first }
82
+
83
+ it 'should return an Arpa::Entities::Permissions' do
84
+ expect(result).to be_an Arpa::Entities::Permissions
85
+ end
86
+
87
+ it 'should has just one permission' do
88
+ expect(result.permissions.size).to be == 1
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Resources::Remover, type: :repository, slow: true do
4
+
5
+ let(:resource_001) { create :repository_resource, :user }
6
+ let(:destroy_resource) { subject.destroy(resource_001) }
7
+
8
+ describe '#destroy' do
9
+
10
+ context 'when resource has no actions associate' do
11
+ let(:actions) { [] }
12
+
13
+ it 'should destroy the resource' do
14
+ expect { destroy_resource }.to change(Arpa::Repositories::Resources::RepositoryResource, :count).by(0)
15
+ end
16
+ end
17
+
18
+ context 'when resource has actions associate' do
19
+ let(:action_001) { create :repository_action, :index, resource: resource_001 }
20
+ let(:action_002) { create :repository_action, :show, resource: resource_001 }
21
+
22
+ before do
23
+ action_001
24
+ action_002
25
+ end
26
+
27
+ it 'should destroy the resource' do
28
+ expect { destroy_resource }.to change(Arpa::Repositories::Resources::RepositoryResource, :count).by(-1)
29
+ end
30
+
31
+ it 'should destroy all actions associate with resource' do
32
+ expect { destroy_resource }.to change(Arpa::Repositories::Actions::RepositoryAction, :count).by(-2)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Roles::Finder, type: :repository, slow: true do
4
+
5
+ let(:record_001) { create :repository_role, name: 'role_01' }
6
+ let(:record_002) { create :repository_role, name: 'role_02' }
7
+
8
+ before do
9
+ record_001
10
+ record_002
11
+ end
12
+
13
+ describe '#find' do
14
+ let(:result) { subject.find(record_001.id) }
15
+
16
+ it 'the Role entity should has name "role_01"' do
17
+ expect(result.name).to eql 'role_01'
18
+ end
19
+
20
+ it 'the result should be an Arpa::Entities::Role' do
21
+ expect(result).to be_an Arpa::Entities::Role
22
+ end
23
+
24
+ end
25
+
26
+ describe '#all' do
27
+ let(:result) { subject.all }
28
+
29
+ it 'should return size 2' do
30
+ expect(result.size).to be == 2
31
+ end
32
+
33
+ it 'the first Role entity should has name "role_01"' do
34
+ expect(result.first.name).to eql 'role_01'
35
+ end
36
+
37
+ it 'the result should be an Array of Arpa::Entities::Role' do
38
+ expect(result.first).to be_an Arpa::Entities::Role
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Roles::Remover, type: :repository, slow: true do
4
+
5
+ let(:created_role) { create :repository_role }
6
+
7
+ before { created_role }
8
+
9
+ describe '#destroy' do
10
+ let(:destroy_role) { subject.destroy(created_role) }
11
+
12
+ it 'should destroy the role' do
13
+ expect { destroy_role }.to change(Arpa::Repositories::Roles::RepositoryRole, :count).by(-1)
14
+ end
15
+
16
+ end
17
+
18
+ describe '#disable' do
19
+ let(:disable_role) { subject.disable(created_role) }
20
+
21
+ it 'should disable the role' do
22
+ expect { disable_role }.to change(Arpa::Repositories::Roles::RepositoryRole, :count).by(-1)
23
+ end
24
+
25
+ it 'role should be setted to removed: true' do
26
+ expect(disable_role.removed).to be_truthy
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Create Profile", type: [:request, :profile] do
4
+ let(:finder_profile_repo) { Arpa::Repositories::Profiles::Finder.new }
5
+ let(:finder_resource_repo) { Arpa::Repositories::Resources::Finder.new }
6
+ let(:finder_role_repo) { Arpa::Repositories::Roles::Finder.new }
7
+ let(:creator_resource_service) { Arpa::Services::Resources::ResourceManagerCreator.new }
8
+ let(:creator_role_service) { Arpa::Services::Roles::RoleManagerCreator.new }
9
+ let(:creator_profile_service) { Arpa::Services::Profiles::ProfileManagerCreator.new }
10
+ let(:success_proc) { ->(r) {} }
11
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
12
+
13
+ context 'when have no created resources or actions' do
14
+ let(:resourceable_001) { double to_s: 'UsersController', action_methods: [:index, :show, 'edit'] }
15
+ let(:resourceable_002) { double to_s: 'ContactsController', action_methods: [:index, 'edit'] }
16
+ let(:resourceables) { [resourceable_001, resourceable_002] }
17
+ let(:created_resources) { creator_resource_service.create({resourceables: resourceables}, callback) }
18
+
19
+ let(:action_ids) { finder_resource_repo.all.first.actions.collect{ |action| action.id} }
20
+ let(:role_001_params) { {role: {name: 'role_name_001', description: 'role_description_001', action_ids: action_ids}} }
21
+ let(:role_002_params) { {role: {name: 'role_name_002', description: 'role_description_002', action_ids: action_ids}} }
22
+ let(:created_roles) do
23
+ creator_role_service.create(role_001_params, callback)
24
+ creator_role_service.create(role_002_params, callback)
25
+ end
26
+
27
+ let(:role_ids) { finder_role_repo.all.map { |r| r.id } }
28
+
29
+ before do
30
+ created_resources
31
+ created_roles
32
+ profile_params = {profile: {name: 'profile_name', description: 'profile_description', role_ids: role_ids}}
33
+ creator_profile_service.create(profile_params, callback)
34
+ end
35
+
36
+ it 'should be recorded one profile' do
37
+ expect(finder_profile_repo.all.size).to be == 1
38
+ end
39
+
40
+ it 'should has 2 roles associated' do
41
+ expect(finder_profile_repo.all.first.roles.size).to be == 2
42
+ end
43
+
44
+ context 'names of associated roles' do
45
+ it {expect(finder_profile_repo.all.first.roles.first.name).to eql 'role_name_001'}
46
+ it {expect(finder_profile_repo.all.first.roles.second.name).to eql 'role_name_002'}
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Remove Profile", type: [:request, :profile] do
4
+ let(:finder_profile_repo) { Arpa::Repositories::Profiles::Finder.new }
5
+ let(:remover_profile_service) { Arpa::Services::Profiles::ProfileManagerRemover.new }
6
+ let(:success_proc) { ->(r) {} }
7
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
8
+
9
+ describe 'removing a Profile' do
10
+
11
+ before do
12
+ create :repository_profile
13
+ remover_profile_service.remove(profile_params_to_remove, callback)
14
+ end
15
+
16
+ context 'when need destroy a Profile' do
17
+ let(:profile_params_to_remove) { {profile: finder_profile_repo.all.first } }
18
+
19
+ it 'record should be removed ' do
20
+ expect(finder_profile_repo.all.size).to be == 0
21
+ end
22
+
23
+ end
24
+
25
+ context 'when need disable a Profile' do
26
+ let(:profile_params_to_remove) { {profile: finder_profile_repo.all.first, disable: true } }
27
+
28
+ it 'record should be removed ' do
29
+ expect(finder_profile_repo.all.size).to be == 0
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Create Resource", type: [:request, :resource] do
4
+ let(:finder_repo) { Arpa::Repositories::Resources::Finder.new }
5
+ let(:creator_service) { Arpa::Services::Resources::ResourceManagerCreator.new }
6
+ let(:success_proc) { ->(r) {} }
7
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
8
+
9
+ context 'when have no created resources or actions' do
10
+ let(:resourceable_001) { double to_s: 'UsersController', action_methods: [:index, :show, 'edit'] }
11
+ let(:resourceable_002) { double to_s: 'ContactsController', action_methods: [:index, 'edit'] }
12
+ let(:resourceables) { [resourceable_001, resourceable_002] }
13
+
14
+ before do
15
+ creator_service.create({resourceables: resourceables}, callback)
16
+ end
17
+
18
+ it 'should be recorded two resources' do
19
+ expect(finder_repo.all.size).to be == 2
20
+ end
21
+
22
+ context 'names of resources' do
23
+ it {expect(finder_repo.all.first.name).to eql('contacts') }
24
+ it {expect(finder_repo.all.second.name).to eql('users') }
25
+ end
26
+
27
+ context 'Contacts resource' do
28
+ let(:contacts_resource) { finder_repo.all.first }
29
+
30
+ it 'should has two actions' do
31
+ expect(contacts_resource.actions.size).to be == 2
32
+ end
33
+
34
+ context 'names of actions' do
35
+ it {expect(contacts_resource.actions.first.name).to eql('edit') }
36
+ it {expect(contacts_resource.actions.second.name).to eql('index') }
37
+ end
38
+ end
39
+
40
+ context 'Users resource' do
41
+ let(:users_resource) { finder_repo.all.second }
42
+
43
+ it 'should has three actions' do
44
+ expect(users_resource.actions.size).to be == 3
45
+ end
46
+
47
+ context 'names of actions' do
48
+ it {expect(users_resource.actions.first.name).to eql('edit') }
49
+ it {expect(users_resource.actions.second.name).to eql('index') }
50
+ it {expect(users_resource.actions.third.name).to eql('show') }
51
+ end
52
+
53
+ end
54
+ end
55
+
56
+ context 'when have created resources or actions' do
57
+ let(:resourceable_001) { double to_s: 'UsersController', action_methods: [:index, :show, 'edit'] }
58
+ let(:resourceable_002) { double to_s: 'ContactsController', action_methods: [:index, 'edit'] }
59
+ let(:created_resourceables) { [resourceable_001, resourceable_002] }
60
+
61
+ let(:resourceable_003) { double to_s: 'Arpa::NewUsersController', action_methods: [:show, 'edit'] }
62
+ let(:resourceable_004) { double to_s: 'ContactsController', action_methods: [:index, 'new_edit'] }
63
+ let(:new_resourceables) { [resourceable_003, resourceable_004] }
64
+
65
+ before do
66
+ creator_service.create({resourceables: created_resourceables}, callback)
67
+ creator_service.create({resourceables: new_resourceables}, callback)
68
+ end
69
+
70
+ it 'should be recorded two resources' do
71
+ expect(finder_repo.all.size).to be == 2
72
+ end
73
+
74
+ context 'names of resources' do
75
+ it {expect(finder_repo.all.first.name).to eql('arpa/new_users') }
76
+ it {expect(finder_repo.all.second.name).to eql('contacts') }
77
+ end
78
+
79
+ context 'Contacts resource' do
80
+ let(:contacts_resource) { finder_repo.all.second }
81
+
82
+ it 'should has two actions' do
83
+ expect(contacts_resource.actions.size).to be == 2
84
+ end
85
+
86
+ context 'names of actions' do
87
+ it {expect(contacts_resource.actions.first.name).to eql('index') }
88
+ it {expect(contacts_resource.actions.second.name).to eql('new_edit') }
89
+ end
90
+ end
91
+
92
+ context 'Arpa::NewUsers resource' do
93
+ let(:users_resource) { finder_repo.all.first }
94
+
95
+ it 'should has two actions' do
96
+ expect(users_resource.actions.size).to be == 2
97
+ end
98
+
99
+ context 'names of actions' do
100
+ it {expect(users_resource.actions.first.name).to eql('edit') }
101
+ it {expect(users_resource.actions.second.name).to eql('show') }
102
+ end
103
+
104
+ end
105
+ end
106
+
107
+ end