arpa 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ac3eac89491ad54cb93ebb7f92d8d005004fbd3
4
- data.tar.gz: f3c339ef6098a96b596dd6fa73e8650cf149d248
3
+ metadata.gz: e273592f37ad13daf44a6e0c412ec460ce55d7e9
4
+ data.tar.gz: eb130f2d9ccb47a7593ffabda100d1751aa479d5
5
5
  SHA512:
6
- metadata.gz: 31bcdb54473222eb89294ae09344db43a8af1800b18e8809b82317424aea01b1270e7643a99d0a0616d894a6a8a4d02c0b750683c84c0acfa592719ac201a942
7
- data.tar.gz: f4e7adcd592e476240939e78a2ac9f0a23a7af6ca2d8343f495c7b708d5991393b61749d7b5d522df0887b7fba669d4ddd2786312dabd288cc487a4554e2c903
6
+ metadata.gz: ebfe4e7018c0f15bce6d177f36e9286c996fde7e5895bd5814d1cb28709fe6e79d98a786b567bb7af13a6e110e3c03681d70da4c1a7f0d4dda52221bbeb43a89
7
+ data.tar.gz: c3091d712f1b4fc02c87b81770be3f5253e79d3bed28dd14059c69876bf835c06ebb5e2a5bb628b87d6dfb6bc6b555264c517ad6b10bd7099b15e78c69484ee5
@@ -1,3 +1,10 @@
1
+ ### 0.2.0
2
+
3
+ * additions
4
+ * Add dinamic association for Profiles throuh Entity id and class attriutes;
5
+ * Add find methods to collect all Profiles without Entity and with specific entity;
6
+ * Update all views and controllers with the new attriutes for Profile.
7
+
1
8
  ### 0.0.9
2
9
 
3
10
  * removals
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.7'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
24
- spec.add_development_dependency 'factory_girl', '~> 0'
24
+ spec.add_development_dependency 'factory_girl'
25
25
  spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.3'
26
- spec.add_development_dependency 'database_cleaner', '~> 0'
27
- spec.add_development_dependency 'pry', '~> 0'
26
+ spec.add_development_dependency 'database_cleaner'
27
+ spec.add_development_dependency 'pry'
28
28
 
29
29
  spec.add_dependency 'activerecord', '>= 4.2.0'
30
30
  spec.add_dependency 'railties', '>= 4.2.0'
@@ -4,10 +4,12 @@ module Arpa
4
4
  entity_class 'Arpa::Entities::Profile'
5
5
  repository_class 'Arpa::Repositories::Profiles::RepositoryProfile'
6
6
 
7
- attrs_to_entity :id, :name, :description, :role_ids, :removed, :created_at, :updated_at,
7
+ attrs_to_entity :id, :name, :description, :role_ids, :entity_id, :entity_class,
8
+ :created_at, :updated_at, :removed,
8
9
  roles: {mapper: 'Arpa::DataMappers::RoleMapper'}
9
10
 
10
- attrs_to_record :id, :name, :description, :role_ids, :removed, :created_at, :updated_at
11
+ attrs_to_record :id, :name, :description, :role_ids, :entity_id, :entity_class,
12
+ :created_at, :updated_at, :removed
11
13
 
12
14
  end
13
15
  end
@@ -2,19 +2,22 @@ module Arpa
2
2
  module Entities
3
3
  class Profile
4
4
 
5
- attr_reader :id, :name, :description, :role_ids, :roles, :created_at, :updated_at, :removed
5
+ attr_reader :id, :name, :description, :role_ids, :roles, :entity_id, :entity_class,
6
+ :created_at, :updated_at, :removed
6
7
 
7
8
  def initialize(attrs = {})
8
9
  attrs = attrs.with_indifferent_access
9
10
 
10
- @id = attrs[:id]
11
- @name = attrs[:name]
12
- @description = attrs[:description]
13
- @role_ids = default_value_to_nil_or_empty(attrs[:role_ids], [])
14
- @roles = default_value_to_nil_or_empty(attrs[:roles], [])
15
- @created_at = attrs[:created_at]
16
- @updated_at = attrs[:updated_at]
17
- @removed = default_value_to_nil_or_empty(attrs[:removed], false)
11
+ @id = attrs[:id]
12
+ @name = attrs[:name]
13
+ @description = attrs[:description]
14
+ @role_ids = default_value_to_nil_or_empty(attrs[:role_ids], [])
15
+ @roles = default_value_to_nil_or_empty(attrs[:roles], [])
16
+ @entity_id = attrs[:entity_id]
17
+ @entity_class = attrs[:entity_class]
18
+ @created_at = attrs[:created_at]
19
+ @updated_at = attrs[:updated_at]
20
+ @removed = default_value_to_nil_or_empty(attrs[:removed], false)
18
21
  end
19
22
 
20
23
  private
@@ -15,6 +15,14 @@ module Arpa
15
15
  end
16
16
  end
17
17
 
18
+ def all_by_entity(entity_id, entity_class)
19
+ repository_class
20
+ .where("( (entity_id is null AND entity_class is null) OR (entity_id = '#{entity_id}' AND entity_class = '#{entity_class}') )" )
21
+ .collect do |record|
22
+ mapper_instance.map_to_entity(record)
23
+ end
24
+ end
25
+
18
26
  def mapper_instance
19
27
  Arpa::DataMappers::ProfileMapper.instance
20
28
  end
@@ -1,3 +1,3 @@
1
1
  module Arpa
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -97,7 +97,7 @@ module Arpa
97
97
 
98
98
  def profile_params
99
99
  params.require(:profile).
100
- permit(:id, :name, :description, role_ids: [])
100
+ permit(:id, :name, :description, :entity_id, :entity_class, role_ids: [])
101
101
  end
102
102
 
103
103
  end
@@ -46,5 +46,8 @@ class CreateArpaTables < ActiveRecord::Migration
46
46
 
47
47
  add_column <%= ":#{@associate_table}" %>, :is_arpa_admin, :boolean, default: false
48
48
 
49
+ add_column :repository_profiles, :entity_id, :integer, default: nil
50
+ add_column :repository_profiles, :entity_class, :string, default: nil
51
+
49
52
  end
50
53
  end
@@ -23,6 +23,16 @@
23
23
  <%= f.text_field :description %>
24
24
  </div>
25
25
 
26
+ <div class="field">
27
+ <%= f.label :entity_id %><br>
28
+ <%= f.text_field :entity_id %>
29
+ </div>
30
+
31
+ <div class="field">
32
+ <%= f.label :entity_class %><br>
33
+ <%= f.text_field :entity_class %>
34
+ </div>
35
+
26
36
  <div class="field">
27
37
 
28
38
  <% @roles.each do |role| %>
@@ -7,6 +7,8 @@
7
7
  <tr>
8
8
  <th>Name</th>
9
9
  <th>Description</th>
10
+ <th>Entity ID</th>
11
+ <th>Entity Class</th>
10
12
  <th colspan="3"></th>
11
13
  </tr>
12
14
  </thead>
@@ -16,6 +18,8 @@
16
18
  <tr>
17
19
  <td><%= profile.name %></td>
18
20
  <td><%= profile.description %></td>
21
+ <td><%= profile.entity_id %></td>
22
+ <td><%= profile.entity_class %></td>
19
23
  <td><%= link_to 'Show', profile_path(profile.id) %></td>
20
24
  <td><%= link_to 'Edit', edit_profile_path(profile.id) %></td>
21
25
  <td><%= link_to 'Destroy', profile_path(profile.id), method: :delete, data: { confirm: 'Are you sure?' } %></td>
@@ -10,6 +10,16 @@
10
10
  <%= @profile.description %>
11
11
  </p>
12
12
 
13
+ <p>
14
+ <strong>Entity id:</strong>
15
+ <%= @profile.entity_id %>
16
+ </p>
17
+
18
+ <p>
19
+ <strong>Entity class:</strong>
20
+ <%= @profile.entity_class %>
21
+ </p>
22
+
13
23
  <table>
14
24
  <div class="table-header">
15
25
  <div class="text-sm">
@@ -7,5 +7,10 @@ FactoryGirl.define do
7
7
  trait :with_complete_association do
8
8
  roles { [FactoryGirl.create(:repository_role, :with_complete_association)] }
9
9
  end
10
+
11
+ trait :with_entity do
12
+ entity_id { FactoryGirl.create(:entity) }
13
+ entity_class { FactoryGirl.create(:entity).class.to_s }
14
+ end
10
15
  end
11
16
  end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :entity, class: TestRepository do
3
+ name 'some entity'
4
+ end
5
+ end
@@ -26,7 +26,7 @@ describe Arpa::Repositories::Profiles::Finder, type: :repository, slow: true do
26
26
  describe '#all' do
27
27
  let(:result) { subject.all }
28
28
 
29
- it 'should return size 2' do
29
+ it 'should return all' do
30
30
  expect(result.size).to be == 2
31
31
  end
32
32
 
@@ -40,4 +40,40 @@ describe Arpa::Repositories::Profiles::Finder, type: :repository, slow: true do
40
40
 
41
41
  end
42
42
 
43
+ describe '#all_by_entity' do
44
+
45
+ context 'when have profiles with differents entities' do
46
+ let(:entity_001) { create :entity }
47
+ let(:record_003) { create :repository_profile, name: 'profile_03', entity_id: entity_001.id, entity_class: entity_001.class }
48
+ let(:record_004) { create :repository_profile, :with_entity, name: 'profile_04' }
49
+ let(:result) { subject.all_by_entity entity_001.id, entity_001.class.to_s }
50
+
51
+ before do
52
+ record_003
53
+ record_004
54
+ end
55
+
56
+ it 'should return all without entity and with correct entity' do
57
+ expect(result.size).to be == 3
58
+ end
59
+
60
+ it 'the result without entity should fill with nil value' do
61
+ first = result.first
62
+ expect(first.entity_id).to be_nil
63
+ expect(first.entity_class).to be_nil
64
+
65
+ second = result.second
66
+ expect(second.entity_id).to be_nil
67
+ expect(second.entity_class).to be_nil
68
+ end
69
+
70
+ it 'the result with entity should be filled correct values' do
71
+ third = result.third
72
+ expect(third.entity_id).to be == entity_001.id
73
+ expect(third.entity_class).to eql entity_001.class.to_s
74
+ end
75
+
76
+ end
77
+ end
78
+
43
79
  end
@@ -55,4 +55,7 @@ ActiveRecord::Schema.define do
55
55
  t.index :user_id, name: 'user_profile_id'
56
56
  end
57
57
 
58
+ add_column :repository_profiles, :entity_id, :integer, default: nil
59
+ add_column :repository_profiles, :entity_class, :string, default: nil
60
+
58
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arpa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rachid Calazans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-18 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,14 +62,14 @@ dependencies:
62
62
  name: factory_girl
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
@@ -96,28 +96,28 @@ dependencies:
96
96
  name: database_cleaner
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - "~>"
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - "~>"
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: pry
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  - !ruby/object:Gem::Dependency
@@ -244,6 +244,7 @@ files:
244
244
  - spec/factories/repository_profiles.rb
245
245
  - spec/factories/repository_resources.rb
246
246
  - spec/factories/repository_roles.rb
247
+ - spec/factories/repository_test.rb
247
248
  - spec/lib/arpa/additions/resource_spec.rb
248
249
  - spec/lib/arpa/data_mappers/action_mapper_spec.rb
249
250
  - spec/lib/arpa/data_mappers/base_spec.rb
@@ -314,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
315
  version: '0'
315
316
  requirements: []
316
317
  rubyforge_project:
317
- rubygems_version: 2.4.6
318
+ rubygems_version: 2.6.11
318
319
  signing_key:
319
320
  specification_version: 4
320
321
  summary: Authorization Gem for Ruby and Ruby on Rails projects
@@ -323,6 +324,7 @@ test_files:
323
324
  - spec/factories/repository_profiles.rb
324
325
  - spec/factories/repository_resources.rb
325
326
  - spec/factories/repository_roles.rb
327
+ - spec/factories/repository_test.rb
326
328
  - spec/lib/arpa/additions/resource_spec.rb
327
329
  - spec/lib/arpa/data_mappers/action_mapper_spec.rb
328
330
  - spec/lib/arpa/data_mappers/base_spec.rb