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,19 @@
1
+ FactoryGirl.define do
2
+ factory :repository_action, class: Arpa::Repositories::Actions::RepositoryAction do
3
+
4
+ trait :index do
5
+ name 'index'
6
+ resource { FactoryGirl.create(:repository_resource, :user) }
7
+ end
8
+
9
+ trait :show do
10
+ name 'show'
11
+ resource { FactoryGirl.create(:repository_resource, :user) }
12
+ end
13
+
14
+ trait :with_complete_association do
15
+ name 'index_new'
16
+ resource { FactoryGirl.create(:repository_resource, :user) }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :repository_profile, class: Arpa::Repositories::Profiles::RepositoryProfile do
3
+
4
+ name 'some_profile'
5
+ description 'description_profile'
6
+
7
+ trait :with_complete_association do
8
+ roles { [FactoryGirl.create(:repository_role, :with_complete_association)] }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ FactoryGirl.define do
2
+ factory :repository_resource, class: Arpa::Repositories::Resources::RepositoryResource do
3
+
4
+ trait :user do
5
+ full_name 'UsersController'
6
+ name 'users'
7
+ end
8
+
9
+ trait :contact do
10
+ full_name 'ContactsController'
11
+ name 'contacts'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :repository_role, class: Arpa::Repositories::Roles::RepositoryRole do
3
+
4
+ name 'some_role'
5
+ description 'description_role'
6
+
7
+ trait :with_complete_association do
8
+ actions {[FactoryGirl.create(:repository_action, :with_complete_association)] }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ class ResourceImplementation
4
+ def self.helper_method(args);end
5
+ include Arpa::Additions::Resource
6
+ def session;'';end
7
+ def current_user;'';end
8
+ end
9
+
10
+ describe Arpa::Additions::Resource, type: :addition, fast: true do
11
+
12
+ let(:resource_implementation) { ResourceImplementation.new }
13
+
14
+ describe '#has_access?' do
15
+ let(:verifier) { double }
16
+ let(:resource) { double }
17
+ let(:action) { double }
18
+
19
+ before do
20
+ allow(Arpa::Services::Verifier).to receive(:new).and_return(verifier)
21
+ allow(verifier).to receive(:has_access?)
22
+ resource_implementation.has_access?(resource, action)
23
+ end
24
+
25
+ it 'should call :new from Arpa::Services::Verifier' do
26
+ expect(Arpa::Services::Verifier).to have_received(:new).once
27
+ end
28
+
29
+ it 'verifier should call :has_access? with resource and action as parameter' do
30
+ expect(verifier).to have_received(:has_access?).with(resource, action).once
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::DataMappers::ActionMapper, type: :mapper, fast: true do
4
+ let(:mapper) { Arpa::DataMappers::ActionMapper.instance }
5
+
6
+ describe 'mapping to record instance' do
7
+ let(:entity) { Arpa::Entities::Action.new(name: 'index', resource_id: 1)}
8
+ let(:record_instance) { mapper.map_to_record(entity) }
9
+
10
+ it 'record_instance should be an instance of ActiveRecord::Base' do
11
+ expect(record_instance).to be_a ActiveRecord::Base
12
+ end
13
+
14
+ it 'record_instance should fill the property :name from entity property' do
15
+ expect(record_instance.name).to eql 'index'
16
+ end
17
+
18
+ it 'record_instance should fill the property :resource_id and :repository_resource_id from entity property' do
19
+ expect(record_instance.resource_id).to be == 1
20
+ expect(record_instance.repository_resource_id).to be == 1
21
+ end
22
+
23
+ end
24
+
25
+ describe 'mapping to entity instance' do
26
+ let(:record) { create :repository_action, :index }
27
+ let(:entity_instance) { mapper.map_to_entity(record) }
28
+
29
+ it 'entity_instance should fill the property :name from record property' do
30
+ expect(entity_instance.name).to eql 'index'
31
+ end
32
+
33
+ it 'entity_instance should fill the property :id from record property' do
34
+ expect(entity_instance.id).to be == record.id
35
+ end
36
+
37
+ it 'entity_instance should fill the property :resource_id from record property' do
38
+ expect(entity_instance.resource_id).to be == record.resource_id
39
+ end
40
+
41
+ it 'entity_instance should fill the property :resource from record property' do
42
+ expect(entity_instance.resource).to be_an Arpa::Entities::Resource
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ class TestMapper < Arpa::DataMappers::Base
4
+ entity_class 'TestRepository'
5
+ repository_class 'TestRepository'
6
+ attributes_to_map :id, :name
7
+ end
8
+
9
+ describe Arpa::DataMappers::Base, type: :mapper, fast: true do
10
+ let(:mapper) { TestMapper.instance }
11
+
12
+ context 'when initialize more than one Mapper' do
13
+
14
+ let(:mapper_002) { TestMapper.instance }
15
+
16
+ it 'the instances should use singleton pattern' do
17
+ expect(mapper).to eq mapper_002
18
+ end
19
+ end
20
+
21
+ describe 'mapping to record instance' do
22
+ let(:entity) { double id: nil, name: 'Some Name' }
23
+ let(:record_instance) { mapper.map_to_record(entity) }
24
+
25
+ it 'record_instance should be an instance of ActiveRecord::Base' do
26
+ expect(record_instance).to be_a ActiveRecord::Base
27
+ end
28
+
29
+ it 'record_instance should fill the property :name from entity property' do
30
+ expect(record_instance.name).to eql 'Some Name'
31
+ end
32
+ end
33
+
34
+ describe 'mapping to entity instance' do
35
+ let(:record) { TestRepository.create(name: 'Name One') }
36
+ let(:entity_instance) { mapper.map_to_entity(record) }
37
+
38
+ it 'entity_instance should fill the property :name from record property' do
39
+ expect(entity_instance.name).to eql 'Name One'
40
+ end
41
+
42
+ it 'entity_instance should fill the property :id from record property' do
43
+ expect(entity_instance.id).to be == record.id
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::DataMappers::ProfileMapper, type: :mapper, fast: true do
4
+ let(:mapper) { Arpa::DataMappers::ProfileMapper.instance }
5
+
6
+ describe 'mapping to record instance' do
7
+ let(:entity) { Arpa::Entities::Profile.new(name: 'some_profile')}
8
+ let(:record_instance) { mapper.map_to_record(entity) }
9
+
10
+ it 'record_instance should be an instance of Arpa::Repositories::Profiles::RepositoryProfile' do
11
+ expect(record_instance).to be_a Arpa::Repositories::Profiles::RepositoryProfile
12
+ end
13
+
14
+ it 'record_instance should fill the property :name from entity property' do
15
+ expect(record_instance.name).to eql 'some_profile'
16
+ end
17
+ end
18
+
19
+ describe 'mapping to entity instance' do
20
+ let(:action_record) { create :repository_action, :index }
21
+ let(:role_record) { create :repository_role, action_ids: [action_record.id] }
22
+ let(:record) { create :repository_profile, role_ids: [role_record.id] }
23
+ let(:entity_instance) { mapper.map_to_entity(record) }
24
+
25
+ it 'entity_instance should fill the property :name from record property' do
26
+ expect(entity_instance.name).to eql 'some_profile'
27
+ end
28
+
29
+ it 'entity_instance should fill the property :id from record property' do
30
+ expect(entity_instance.id).to be == record.id
31
+ end
32
+
33
+ it 'entity_instance should fill the property :roles from record property' do
34
+ expect(entity_instance.roles.first).to be_an Arpa::Entities::Role
35
+ end
36
+
37
+ it 'entity_instance should fill the property :role_ids from record property' do
38
+ expect(entity_instance.role_ids).to eq [role_record.id]
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::DataMappers::ResourceMapper, type: :mapper, fast: true do
4
+ let(:mapper) { Arpa::DataMappers::ResourceMapper.instance }
5
+
6
+ describe 'mapping to record instance' do
7
+ let(:entity) { Arpa::Entities::Resource.new(full_name: 'UsersController')}
8
+ let(:record_instance) { mapper.map_to_record(entity) }
9
+
10
+ it 'record_instance should be an instance of ActiveRecord::Base' do
11
+ expect(record_instance).to be_a ActiveRecord::Base
12
+ end
13
+
14
+ it 'record_instance should fill the property :name from entity property' do
15
+ expect(record_instance.full_name).to eql 'UsersController'
16
+ end
17
+ end
18
+
19
+ describe 'mapping to entity instance' do
20
+ let(:action_record) { create :repository_action, :index }
21
+ let(:record) { create :repository_resource, :user, actions: [action_record] }
22
+ let(:entity_instance) { mapper.map_to_entity(record.reload) }
23
+
24
+ it 'entity_instance should fill the property :name from record property' do
25
+ expect(entity_instance.full_name).to eql 'UsersController'
26
+ end
27
+
28
+ it 'entity_instance should fill the property :id from record property' do
29
+ expect(entity_instance.id).to be == record.id
30
+ end
31
+
32
+ it 'entity_instance should fill the property :actions from record property' do
33
+ expect(entity_instance.actions.first).to be_an Arpa::Entities::Action
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::DataMappers::RoleMapper, type: :mapper, fast: true do
4
+ let(:mapper) { Arpa::DataMappers::RoleMapper.instance }
5
+
6
+ describe 'mapping to record instance' do
7
+ let(:entity) { Arpa::Entities::Role.new(name: 'some_role')}
8
+ let(:record_instance) { mapper.map_to_record(entity) }
9
+
10
+ it 'record_instance should be an instance of Arpa::Repositories::Roles::RepositoryRole' do
11
+ expect(record_instance).to be_a Arpa::Repositories::Roles::RepositoryRole
12
+ end
13
+
14
+ it 'record_instance should fill the property :name from entity property' do
15
+ expect(record_instance.name).to eql 'some_role'
16
+ end
17
+ end
18
+
19
+ describe 'mapping to entity instance' do
20
+ let(:action_record) { create :repository_action, :index }
21
+ let(:profile_record) { create :repository_profile }
22
+ let(:record) { create :repository_role, profile_ids: [profile_record.id], action_ids: [action_record.id] }
23
+ let(:entity_instance) { mapper.map_to_entity(record) }
24
+
25
+ it 'entity_instance should fill the property :name from record property' do
26
+ expect(entity_instance.name).to eql 'some_role'
27
+ end
28
+
29
+ it 'entity_instance should fill the property :id from record property' do
30
+ expect(entity_instance.id).to be == record.id
31
+ end
32
+
33
+ it 'entity_instance should fill the property :actions from record property' do
34
+ expect(entity_instance.actions.first).to be_an Arpa::Entities::Action
35
+ end
36
+
37
+ it 'entity_instance should fill the property :action_ids from record property' do
38
+ expect(entity_instance.action_ids).to eq [action_record.id]
39
+ end
40
+
41
+ it 'entity_instance should fill the property :profiles from record property' do
42
+ expect(entity_instance.profiles.first).to be_an Arpa::Entities::Profile
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Entities::Action, type: :entity, fast: true do
4
+ let(:resource) { double(name: 'users') }
5
+
6
+ subject { Arpa::Entities::Action.new resource: resource, name: 'index'}
7
+
8
+ describe 'getting description by action name and resource name' do
9
+
10
+ context 'when resource.name is "users" and action.name is "index"' do
11
+
12
+ it 'description should be "List of Users"' do
13
+ expect(subject.description).to eql "List of Users"
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Entities::Permissions, type: :presenter, fast: true do
4
+ let(:index_action) { double name: 'index_new' }
5
+ let(:resource_001) { double name: 'users', actions: [index_action] }
6
+ let(:resource_002) { double name: 'users', actions: [index_action] }
7
+ let(:resources) { [resource_001, resource_002] }
8
+
9
+ subject { Arpa::Entities::Permissions.new(resources)}
10
+
11
+ describe 'intializing' do
12
+ let(:result) { subject.permissions }
13
+
14
+ it 'attr :permissions should be an Array' do
15
+ expect(result).to be_an Array
16
+ end
17
+
18
+ it 'should fill attr :permissions as an Array of Hash with keys :resource and :action' do
19
+ first = result.first
20
+
21
+ expect(first).to be_a Hash
22
+ expect(first.has_key?('resource')).to be_truthy
23
+ expect(first.has_key?('action')).to be_truthy
24
+ end
25
+
26
+ context 'when try fill permissions with duplicate resource and action' do
27
+ let(:hash_permission) { {'resource' => 'users', 'action' => 'index_new' } }
28
+
29
+ it 'should has only one Hash with that duplicated resource and action' do
30
+ duplicated_hash_permission = result.detect{ |e| result.count(e) > 1 }
31
+ expect(duplicated_hash_permission).to be_nil
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ describe '#has_permission?' do
38
+ let(:resource_name) { 'users' }
39
+ let(:result) { subject.has_permission?(resource_name, action_name) }
40
+
41
+ context 'when has' do
42
+ let(:action_name) { 'index_new' }
43
+
44
+ it 'should return true' do
45
+ expect(result).to be_truthy
46
+ end
47
+
48
+ end
49
+
50
+ context 'when has not' do
51
+ let(:action_name) { 'index' }
52
+
53
+ it 'should return false' do
54
+ expect(result).to be_falsey
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Entities::Resource, type: :entity, fast: true do
4
+
5
+ describe '#build_correct_name' do
6
+
7
+ before { subject.build_correct_name }
8
+
9
+ context 'when pass :full_name as "UsersController"' do
10
+ subject { Arpa::Entities::Resource.new full_name: 'UsersController' }
11
+
12
+ it 'full_name should be "UsersController"' do
13
+ expect(subject.full_name).to eql 'UsersController'
14
+ end
15
+
16
+ it 'name should be builded as "users"' do
17
+ expect(subject.name).to eql 'users'
18
+ end
19
+ end
20
+
21
+ context 'when pass :full_name as "Authentication::Someone::UsersController"' do
22
+ subject { Arpa::Entities::Resource.new full_name: 'Authentication::Someone::UsersController' }
23
+
24
+ it 'full_name should be "Authentication::Someone::UsersController"' do
25
+ expect(subject.full_name).to eql 'Authentication::Someone::UsersController'
26
+ end
27
+
28
+ it 'name should be builded as "authentication/someone/users"' do
29
+ expect(subject.name).to eql 'authentication/someone/users'
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Arpa::Repositories::Actions::Finder, type: :repository, slow: true do
4
+
5
+ let(:resource_record) { create :repository_resource, :user }
6
+ let(:action_record_001) { create :repository_action, :index, resource: resource_record }
7
+ let(:action_record_002) { create :repository_action, :show, resource: resource_record}
8
+
9
+ before do
10
+ action_record_001
11
+ action_record_002
12
+ end
13
+
14
+ describe '#by_name_and_resource' do
15
+
16
+ context 'when exist with the params' do
17
+
18
+ let(:result) { subject.by_name_and_resource('index', resource_record) }
19
+
20
+ it 'should return a resource with name "index"' do
21
+ expect(result.name).to eql 'index'
22
+ end
23
+
24
+ it 'the result should be an instance of Arpa::Entities::Action' do
25
+ expect(result).to be_an Arpa::Entities::Action
26
+ end
27
+ end
28
+
29
+ context 'when nonexist with the params' do
30
+
31
+ let(:result) { subject.by_name_and_resource('nonexist_action', resource_record) }
32
+
33
+ it 'the result should return nil' do
34
+ expect(result).to be_nil
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end