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,40 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Create Role", type: [:request, :role] do
4
+ let(:finder_role_repo) { Arpa::Repositories::Roles::Finder.new }
5
+ let(:finder_resource_repo) { Arpa::Repositories::Resources::Finder.new }
6
+ let(:creator_resource_service) { Arpa::Services::Resources::ResourceManagerCreator.new }
7
+ let(:creator_role_service) { Arpa::Services::Roles::RoleManagerCreator.new }
8
+ let(:success_proc) { ->(r) {} }
9
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
10
+
11
+ context 'when have no created resources or actions' do
12
+ let(:resourceable_001) { double to_s: 'UsersController', action_methods: [:index, :show, 'edit'] }
13
+ let(:resourceable_002) { double to_s: 'ContactsController', action_methods: [:index, 'edit'] }
14
+ let(:resourceables) { [resourceable_001, resourceable_002] }
15
+ let(:created_resources) { creator_resource_service.create({resourceables: resourceables}, callback) }
16
+
17
+ let(:action_ids) { finder_resource_repo.all.first.actions.collect {|action| action.id} }
18
+
19
+ before do
20
+ created_resources
21
+ role_params = {role: {name: 'role_name', description: 'role_description', action_ids: action_ids}}
22
+ creator_role_service.create(role_params, callback)
23
+ end
24
+
25
+ it 'should be recorded one role' do
26
+ expect(finder_role_repo.all.size).to be == 1
27
+ end
28
+
29
+ it 'should has 2 actions associated' do
30
+ expect(finder_role_repo.all.first.actions.size).to be == 2
31
+ end
32
+
33
+ context 'names of associated actions' do
34
+ it {expect(finder_role_repo.all.first.actions.first.name).to eql 'edit'}
35
+ it {expect(finder_role_repo.all.first.actions.second.name).to eql 'index'}
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Remove Role", type: [:request, :role] do
4
+ let(:finder_role_repo) { Arpa::Repositories::Roles::Finder.new }
5
+ let(:remover_role_service) { Arpa::Services::Roles::RoleManagerRemover.new }
6
+ let(:success_proc) { ->(r) {} }
7
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
8
+
9
+ describe 'removing a Role' do
10
+
11
+ before do
12
+ create :repository_role
13
+ role_params_to_remove = {role: finder_role_repo.all.first }
14
+ remover_role_service.remove(role_params_to_remove, callback)
15
+ end
16
+
17
+ it 'record should be removed ' do
18
+ expect(finder_role_repo.all.size).to be == 0
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "Update Role", type: [:request, :role] do
4
+ let(:finder_role_repo) { Arpa::Repositories::Roles::Finder.new }
5
+ let(:finder_resource_repo) { Arpa::Repositories::Resources::Finder.new }
6
+ let(:creator_resource_service) { Arpa::Services::Resources::ResourceManagerCreator.new }
7
+ let(:creator_role_service) { Arpa::Services::Roles::RoleManagerCreator.new }
8
+ let(:updater_role_service) { Arpa::Services::Roles::RoleManagerUpdater.new }
9
+ let(:success_proc) { ->(r) {} }
10
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
11
+
12
+ context 'updating a Role' do
13
+ let(:resourceable_001) { double to_s: 'UsersController', action_methods: [:index, :show, 'edit'] }
14
+ let(:resourceable_002) { double to_s: 'ContactsController', action_methods: [:index, 'edit'] }
15
+ let(:resourceables) { [resourceable_001, resourceable_002] }
16
+ let(:created_resources) { creator_resource_service.create({resourceables: resourceables}, callback) }
17
+ let(:action_ids) { finder_resource_repo.all.first.actions.collect {|action| action.id} }
18
+
19
+ let(:create_resources_and_role) do
20
+ created_resources
21
+ role_params = {role: {name: 'role_name', description: 'role_description', action_ids: action_ids}}
22
+ creator_role_service.create(role_params, callback)
23
+ end
24
+
25
+ before do
26
+ create_resources_and_role
27
+ found_role = finder_role_repo.all.first
28
+ role_params_to_update = {role: {id: found_role.id, name: 'updated_role_name', description: 'role_description', action_ids: [action_ids[0]] }}
29
+ updater_role_service.update(role_params_to_update, callback)
30
+ end
31
+
32
+ it 'should be recorded one role' do
33
+ expect(finder_role_repo.all.size).to be == 1
34
+ end
35
+
36
+ it 'should has 1 actions associated' do
37
+ expect(finder_role_repo.all.first.actions.size).to be == 1
38
+ end
39
+
40
+ it 'name should be "updated_role_name"' do
41
+ expect(finder_role_repo.all.first.name).to eql 'updated_role_name'
42
+ end
43
+
44
+ context 'names of associated actions' do
45
+ it {expect(finder_role_repo.all.first.actions.first.name).to eql 'edit'}
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Services::Actions::Create::ActionCreator, type: :service, fast: true do
4
+
5
+ let(:action_entity_class) { Arpa::Entities::Action }
6
+ let(:action) { double }
7
+ let(:resource) { double id: 1 }
8
+ let(:actions_names) { ['index', 'new'] }
9
+ let(:params) { {resource: resource, actions_names: actions_names} }
10
+ let(:action_found) { nil }
11
+
12
+ let(:actions_created) { subject.create_many(params) }
13
+ let(:validator_class) { Arpa::Validators::ActionValidator }
14
+ let(:validator) { instance_double validator_class }
15
+
16
+ let(:finder_repo_class) { Arpa::Repositories::Actions::Finder}
17
+ let(:finder_repo) { instance_double finder_repo_class }
18
+
19
+ before do
20
+ allow(finder_repo_class).to receive(:new).and_return(finder_repo)
21
+ allow(finder_repo).to receive(:by_name_and_resource).and_return(action_found)
22
+
23
+ allow(validator_class).to receive(:new).with(action).and_return(validator)
24
+ allow(action_entity_class).to receive(:new).and_return(action)
25
+ end
26
+
27
+ describe 'creating a new action' do
28
+
29
+ context 'when resource is invalid' do
30
+ let(:errors) { instance_double('ActiveModel::Errors') }
31
+
32
+ before do
33
+ allow(validator).to receive(:valid?).and_return false
34
+ allow(validator).to receive(:errors).and_return(errors)
35
+ allow(errors).to receive(:messages)
36
+ end
37
+
38
+ it 'should raise a Arpa::Exceptions::RecordInvalid with :errors of ActiveModel::Errors' do
39
+ expect { actions_created }.to raise_error { |error|
40
+ expect(error).to be_a Arpa::Exceptions::RecordInvalid
41
+ expect(error.errors).not_to be_nil
42
+ }
43
+ end
44
+
45
+ end
46
+
47
+ context 'when actino already exists' do
48
+ let(:action_found) { double }
49
+
50
+ it 'should return the action found' do
51
+ expect(actions_created).to eq [action_found, action_found]
52
+ end
53
+
54
+ end
55
+
56
+ context 'when resource is valid' do
57
+ let(:creator_repo_class) { Arpa::Repositories::Actions::Creator }
58
+ let(:creator_repo) { instance_double creator_repo_class }
59
+
60
+ before do
61
+ allow(validator).to receive(:valid?).and_return true
62
+ allow(creator_repo_class).to receive(:new).and_return(creator_repo)
63
+ allow(creator_repo).to receive(:create).with(action)
64
+ actions_created
65
+ end
66
+
67
+ it 'creator repository should call :new' do
68
+ expect(creator_repo_class).to have_received(:new).once
69
+ end
70
+
71
+ it 'creator_repo should call create method with action as parameter' do
72
+ expect(creator_repo).to have_received(:create).with(action).twice
73
+ end
74
+
75
+ context 'when build an instance of action' do
76
+
77
+ it 'entity action should call new method' do
78
+ expect(action_entity_class).to have_received(:new).with({resource_id: resource.id, name: 'index'}).once
79
+ expect(action_entity_class).to have_received(:new).with({resource_id: resource.id, name: 'new'}).once
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Services::Actions::Remove::ActionRemover, type: :service, fast: true do
4
+
5
+ let(:action_001) { double name: 'index' }
6
+ let(:action_002) { double name: 'old_index' }
7
+ let(:actions) { [action_001, action_002]}
8
+ let(:resource) { double actions: actions }
9
+
10
+ let(:actions_names) { ['index', 'show'] }
11
+
12
+ let(:params) { {resource: resource, actions_names: actions_names} }
13
+
14
+ describe 'removing nonexistent actions' do
15
+ let(:remover_repo_class) { Arpa::Repositories::Actions::Remover }
16
+ let(:remover_repo) { instance_double remover_repo_class }
17
+
18
+ before do
19
+ allow(remover_repo_class).to receive(:new).and_return(remover_repo)
20
+ allow(remover_repo).to receive(:destroy)
21
+
22
+ subject.remove_nonexistent_actions(params)
23
+ end
24
+
25
+ it 'remover repository should call :new once' do
26
+ expect(remover_repo_class).to have_received(:new).once
27
+ end
28
+
29
+ it 'remover repository should call :destroy once' do
30
+ expect(remover_repo).to have_received(:destroy).once
31
+ expect(remover_repo).to have_received(:destroy).with(action_002).once
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ class CustomTransactionClass
4
+ def self.transaction
5
+ yield
6
+ end
7
+ end
8
+
9
+ class ManagerImplementationTest
10
+ include Arpa::Services::Base
11
+
12
+ def create_raise callback
13
+ manager_action callback do
14
+ raise Exceptions::RecordInvalid.new 'some error'
15
+ end
16
+ end
17
+
18
+ def create callback
19
+ manager_action callback do
20
+ 'success'
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ describe Arpa::Services::Base, type: :service, fast: true do
27
+
28
+ let(:manager_implementation) { ManagerImplementationTest.new }
29
+ let(:callback) {
30
+ {
31
+ success: -> (result) {},
32
+ fail: -> (exception){}
33
+ }
34
+ }
35
+
36
+ describe 'calling .transaction' do
37
+ before do
38
+ set_custom_transaction_class
39
+ allow(transaction_class).to receive(:transaction)
40
+ manager_implementation.create callback
41
+ end
42
+
43
+ context 'when use the default transaction_class from Services::ManagerBase' do
44
+ let(:set_custom_transaction_class) { manager_implementation.class.repository_transaction nil }
45
+ let(:transaction_class) { ActiveRecord::Base }
46
+
47
+ it 'transaction_class should call .transaction' do
48
+ expect(transaction_class).to have_received(:transaction)
49
+ end
50
+
51
+ end
52
+
53
+ context 'when use a custom transaction_class' do
54
+ let(:set_custom_transaction_class) { manager_implementation.class.repository_transaction 'CustomTransactionClass' }
55
+ let(:transaction_class) { CustomTransactionClass }
56
+
57
+ it 'transaction_class should call .transaction' do
58
+ expect(transaction_class).to have_received(:transaction)
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ describe 'calling correct callback' do
65
+ before do
66
+ manager_implementation.class.repository_transaction 'CustomTransactionClass'
67
+ end
68
+
69
+ context 'when success transaction' do
70
+ before do
71
+ allow(callback[:success]).to receive(:call)
72
+ manager_implementation.create callback
73
+ end
74
+
75
+ it 'should call the callback[:success]' do
76
+ expect(callback[:success]).to have_received(:call).once
77
+ end
78
+ end
79
+
80
+ context 'when fail transaction' do
81
+ before do
82
+ allow(callback[:fail]).to receive(:call).with kind_of StandardError
83
+ manager_implementation.create_raise callback
84
+ end
85
+
86
+
87
+ it 'should call the callback[:fail] with Exceptions::RecordInvalid' do
88
+ expect(callback[:fail]).to have_received(:call).with(kind_of StandardError)
89
+ end
90
+
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Services::Profiles::Create::ProfileCreator, type: :service, fast: true do
4
+
5
+ let(:profile_entity_class) { Arpa::Entities::Profile }
6
+ let(:profile) { double }
7
+ let(:params) { double }
8
+
9
+ let(:profile_created) { subject.create(params) }
10
+ let(:validator_class) { Arpa::Validators::ProfileValidator }
11
+ let(:validator) { instance_double validator_class }
12
+
13
+ before do
14
+ allow(validator_class).to receive(:new).and_return(validator)
15
+ allow(profile_entity_class).to receive(:new).and_return(profile)
16
+ end
17
+
18
+ describe 'creating a new profile' do
19
+
20
+ context 'when profile is invalid' do
21
+ let(:errors) { instance_double('ActiveModel::Errors') }
22
+
23
+ before do
24
+ allow(validator).to receive(:valid?).and_return false
25
+ allow(validator).to receive(:errors).and_return(errors)
26
+ allow(errors).to receive(:messages)
27
+ end
28
+
29
+ it 'should raise a Arpa::Exceptions::RecordInvalid with :errors of ActiveModel::Errors' do
30
+ expect { profile_created }.to raise_error { |error|
31
+ expect(error).to be_a Arpa::Exceptions::RecordInvalid
32
+ expect(error.errors).not_to be_nil
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ context 'when profile is valid' do
39
+ let(:creator_repo_class) { Arpa::Repositories::Profiles::Creator }
40
+ let(:creator_repo) { instance_double creator_repo_class }
41
+
42
+ before do
43
+ allow(validator).to receive(:valid?).and_return true
44
+ allow(creator_repo_class).to receive(:new).and_return(creator_repo)
45
+ allow(creator_repo).to receive(:create).with(profile)
46
+ profile_created
47
+ end
48
+
49
+ it 'creator repository should call :new' do
50
+ expect(creator_repo_class).to have_received(:new)
51
+ end
52
+
53
+ it 'creator_repo should call create method with profile as parameter' do
54
+ expect(creator_repo).to have_received(:create).with(profile).once
55
+ end
56
+
57
+ context 'when build the profile' do
58
+
59
+ it 'entity profile should call new method' do
60
+ expect(profile_entity_class).to have_received(:new).once
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Services::Profiles::ProfileManagerCreator, type: :service, fast: true do
4
+
5
+ let(:profile_creator) { double }
6
+ let(:params) { {profile: {name: 'profile_name', description: 'profile_description', role_ids: [1, 2]}} }
7
+ let(:success_proc) { ->(r) {} }
8
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
9
+
10
+ let(:setup_creators) do
11
+ allow(Arpa::Services::Profiles::Create::ProfileCreator).to receive(:new).and_return(profile_creator)
12
+ end
13
+
14
+ let(:setup_creators_methods) do
15
+ allow(profile_creator).to receive(:create)
16
+ end
17
+
18
+ let(:result) { subject.create params, callback }
19
+
20
+ before do
21
+ setup_creators
22
+ setup_creators_methods
23
+ allow(success_proc).to receive(:call)
24
+ result
25
+ end
26
+
27
+ it 'profile_creator should call :create with parameters' do
28
+ expect(profile_creator).to have_received(:create).with(params[:profile]).once
29
+ end
30
+
31
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Services::Profiles::ProfileManagerRemover, type: :service, fast: true do
4
+
5
+ let(:profile_remover) { double }
6
+ let(:profile) { double }
7
+ let(:success_proc) { ->(r) {} }
8
+ let(:callback) { {success: success_proc, fail: ->(e) {raise e} } }
9
+
10
+ let(:setup_updaters) do
11
+ allow(Arpa::Services::Profiles::Remove::ProfileRemover).to receive(:new).and_return(profile_remover)
12
+ end
13
+
14
+ let(:setup_updaters_methods) do
15
+ allow(profile_remover).to receive(:remove)
16
+ end
17
+
18
+ let(:result) { subject.remove params, callback }
19
+
20
+ before do
21
+ setup_updaters
22
+ setup_updaters_methods
23
+ allow(success_proc).to receive(:call)
24
+ result
25
+ end
26
+
27
+ context 'when is to destroy' do
28
+ let(:params) { {profile: profile} }
29
+
30
+ it 'profile_remover should call :remove with profile as parameter' do
31
+ expect(profile_remover).to have_received(:remove).with(profile, nil).once
32
+ end
33
+ end
34
+
35
+ context 'when is to disable' do
36
+ let(:params) { {profile: profile, disable: true} }
37
+
38
+ it 'profile_remover should call :remove with profile and disable: true as parameter' do
39
+ expect(profile_remover).to have_received(:remove).with(profile, true).once
40
+ end
41
+
42
+ end
43
+
44
+ end