unidom-action 1.17.7 → 1.17.8

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: 75bcb3792ea47a2cc2d82a913067499296ac7e51
4
- data.tar.gz: 270fd5519f607b163141640292b60e060795aa91
3
+ metadata.gz: 35a1ddf1d651c7c47f46f565225f1e12077f71ab
4
+ data.tar.gz: 5fc152d0396f643dc51aa8e88b8233a9ebaf4272
5
5
  SHA512:
6
- metadata.gz: 4bcadc922fd84aebf0eca25237372addb505701018d1c2086d91b339f8f92d580cdb9e593b5afcfc99c3c8e8fb8d710bb21a10ee9db01e6b9ab7f17feadfed49
7
- data.tar.gz: 5caeedbe12357df9701117f614469e83821a7124e0ab64b13ab1bc1c7ba9fd9df2effe580eab3d24f68487842958fc62047e5d489c807289e2ba29c1bde3d466
6
+ metadata.gz: '09bb6ca560d99656459fac9f381356ea4711b01ea93b345ca3bb458cabaa923433793f7ca44d90972f3275bfd88b29dba67917f8f968f105aa47c3254668ad6a'
7
+ data.tar.gz: 39fad39e1f09aa7b2624b60756c02ebfddaa02a916f758f8634ae6a0d526e5ea0892aa90a34da8e3c5a858d316b93187f5e795d25f76d687844b1b4fcdf4c087
data/README.md CHANGED
@@ -125,6 +125,14 @@ The As Actor Party concern do the following tasks for the includer automatically
125
125
 
126
126
  3. Define the #act? method as: ``act?(on: nil, due_to: nil, via: nil, at: Time.now, action_code: 'C')``
127
127
 
128
+ ### As Caused concern
129
+
130
+ The As Caused concern do the following tasks for the includer automatically:
131
+
132
+ 1. Define the belongs_to :reason macro as: ``belongs_to :reason, class_name: 'Unidom::Action::Reason'``
133
+
134
+ 2. Define the caused_by scope as: ``scope :caused_by, ->(reason) { where reason_id: to_id(reason) }``
135
+
128
136
  ### As Obsolesced concern
129
137
 
130
138
  The As Obsolesced concern do the following tasks for the includer automatically:
@@ -216,6 +224,8 @@ end
216
224
 
217
225
  ## RSpec examples
218
226
 
227
+ ### RSpec example manifest (run automatically)
228
+
219
229
  ```ruby
220
230
  # spec/models/unidom_spec.rb
221
231
  require 'unidom/action/models_rspec'
@@ -226,3 +236,30 @@ require 'unidom/action/types_rspec'
226
236
  # spec/validators/unidom_spec.rb
227
237
  require 'unidom/action/validators_rspec'
228
238
  ```
239
+
240
+ ### RSpec shared examples (to be integrated)
241
+
242
+ ```ruby
243
+ # The Unidom::Action::Acting model, the Unidom::Action::Obsolescing model, the Unidom::Action::Searching model, & the Unidom::Action::StateTransition model already include the Unidom::Action::Concerns::AsCaused concern
244
+
245
+ # app/models/your_caused.rb
246
+ class YourCaused < ApplicationRecord
247
+
248
+ include Unidom::Common::Concerns::ModelExtension
249
+ include Unidom::Action::Concerns::AsCaused
250
+
251
+ end
252
+
253
+ # spec/support/unidom_rspec_shared_examples.rb
254
+ require 'unidom/action/rspec_shared_examples'
255
+
256
+ # spec/models/your_caused_spec.rb
257
+ describe YourCaused, type: :model do
258
+
259
+ model_attribtues = {
260
+ }
261
+
262
+ it_behaves_like 'Unidom::Action::Concerns::AsCaused', model_attribtues
263
+
264
+ end
265
+ ```
@@ -10,16 +10,17 @@ class Unidom::Action::Acting < Unidom::Action::ApplicationRecord
10
10
 
11
11
  include Unidom::Common::Concerns::ModelExtension
12
12
  include ProgneTapera::EnumCode
13
+ include Unidom::Action::Concerns::AsCaused
13
14
 
14
15
  belongs_to :actor_visitor, polymorphic: true
15
16
  belongs_to :actor_party, polymorphic: true
16
17
  belongs_to :acted, polymorphic: true
17
- belongs_to :reason, class_name: 'Unidom::Action::Reason'
18
+ #belongs_to :reason, class_name: 'Unidom::Action::Reason'
18
19
 
19
20
  scope :acted_via, ->(actor_visitor) { where actor_visitor: actor_visitor }
20
21
  scope :acted_by, ->(actor_party) { where actor_party: actor_party }
21
22
  scope :acted_is, ->(acted) { where acted: acted }
22
- scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
23
+ #scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
23
24
 
24
25
  code :action, Unidom::Action::Action
25
26
 
@@ -0,0 +1,16 @@
1
+ module Unidom::Action::Concerns::AsCaused
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ belongs_to :reason, class_name: 'Unidom::Action::Reason'
8
+
9
+ scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
10
+
11
+ end
12
+
13
+ module ClassMethods
14
+ end
15
+
16
+ end
@@ -10,16 +10,15 @@ class Unidom::Action::Obsolescing < Unidom::Action::ApplicationRecord
10
10
 
11
11
  include Unidom::Common::Concerns::ModelExtension
12
12
  include ProgneTapera::EnumCode
13
+ include Unidom::Action::Concerns::AsCaused
13
14
 
14
15
  belongs_to :obsolescer_visitor, polymorphic: true
15
16
  belongs_to :obsolescer_party, polymorphic: true
16
17
  belongs_to :obsolesced, polymorphic: true
17
- belongs_to :reason, class_name: 'Unidom::Action::Reason'
18
18
 
19
19
  scope :obsolesced_via, ->(obsolescer_visitor) { where obsolescer_visitor: obsolescer_visitor }
20
20
  scope :obsolesced_by, ->(obsolescer_party) { where obsolescer_party: obsolescer_party }
21
21
  scope :obsolesced_is, ->(obsolesced) { where obsolesced: obsolesced }
22
- scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
23
22
 
24
23
  code :obsolescence, Unidom::Action::Obsolescence
25
24
 
@@ -7,6 +7,7 @@ class Unidom::Action::Searching < Unidom::Action::ApplicationRecord
7
7
  self.table_name = 'unidom_searchings'
8
8
 
9
9
  include Unidom::Common::Concerns::ModelExtension
10
+ include Unidom::Action::Concerns::AsCaused
10
11
 
11
12
  validates :resource_name, presence: true, length: { in: 1..self.columns_hash['resource_name'].limit }
12
13
  validates :platform_name, presence: true, length: { in: 1..self.columns_hash['platform_name'].limit }
@@ -20,11 +21,9 @@ class Unidom::Action::Searching < Unidom::Action::ApplicationRecord
20
21
 
21
22
  belongs_to :searcher_visitor, polymorphic: true
22
23
  belongs_to :searcher_party, polymorphic: true
23
- belongs_to :reason, class_name: 'Unidom::Action::Reason'
24
24
 
25
25
  scope :searched_by, ->(searcher_party) { where searcher_party: searcher_party }
26
26
  scope :searched_via, ->(searcher_visitor) { where searcher_visitor: searcher_visitor }
27
- scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
28
27
 
29
28
  scope :resource_name_is, ->(resource_name) { where resource_name: resource_name }
30
29
  scope :platform_name_is, ->(platform_name) { where platform_name: platform_name }
@@ -8,16 +8,15 @@ class Unidom::Action::StateTransition < Unidom::Action::ApplicationRecord
8
8
  self.table_name = 'unidom_state_transitions'
9
9
 
10
10
  include Unidom::Common::Concerns::ModelExtension
11
+ include Unidom::Action::Concerns::AsCaused
11
12
 
12
13
  belongs_to :transitor_visitor, polymorphic: true
13
14
  belongs_to :transitor_party, polymorphic: true
14
15
  belongs_to :subject, polymorphic: true
15
- belongs_to :reason, class_name: 'Unidom::Action::Reason'
16
16
 
17
17
  scope :transited_via, ->(transitor_visitor) { where transitor_visitor: transitor_visitor }
18
18
  scope :transited_by, ->(transitor_party) { where transitor_party: transitor_party }
19
19
  scope :subject_is, ->(subject) { where subject: subject }
20
- scope :caused_by, ->(reason) { where reason_id: to_id(reason) }
21
20
 
22
21
  def self.transit!(subject: nil, from_state: nil, thru_state: nil, transitor_visitor: nil, transitor_party: nil, reason: nil, opened_at: Time.now)
23
22
  create! transitor_visitor: transitor_visitor, transitor_party: transitor_party, subject: subject, reason: reason, from_state: from_state, thru_state: thru_state, opened_at: opened_at
@@ -22,13 +22,10 @@ describe Unidom::Action::Acting, type: :model do
22
22
  }
23
23
 
24
24
  it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
25
+ it_behaves_like 'Unidom::Action::Concerns::AsCaused', model_attributes
25
26
 
26
27
  it_behaves_like 'ProgneTapera::EnumCode', described_class.new(model_attributes), :action, Unidom::Action::Action
27
28
 
28
- it_behaves_like 'belongs_to', model_attributes, :reason, Unidom::Action::Reason, { name: 'Some Reason' }
29
-
30
- it_behaves_like 'monomorphic scope', model_attributes, :caused_by, :reason
31
-
32
29
  end
33
30
 
34
31
  end
@@ -0,0 +1,11 @@
1
+ shared_examples 'Unidom::Action::Concerns::AsCaused' do |model_attributes|
2
+
3
+ context do
4
+
5
+ it_behaves_like 'belongs_to', model_attributes, :reason, Unidom::Action::Reason, { name: 'Some Reason' }
6
+
7
+ it_behaves_like 'monomorphic scope', model_attributes, :caused_by, :reason
8
+
9
+ end
10
+
11
+ end
@@ -20,13 +20,10 @@ describe Unidom::Action::Obsolescing, type: :model do
20
20
  }
21
21
 
22
22
  it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
23
+ it_behaves_like 'Unidom::Action::Concerns::AsCaused', model_attributes
23
24
 
24
25
  it_behaves_like 'ProgneTapera::EnumCode', described_class.new(model_attributes), :obsolescence, Unidom::Action::Obsolescence
25
26
 
26
- it_behaves_like 'belongs_to', model_attributes, :reason, Unidom::Action::Reason, { name: 'Some Reason' }
27
-
28
- it_behaves_like 'monomorphic scope', model_attributes, :caused_by, :reason
29
-
30
27
  end
31
28
 
32
29
  end
@@ -26,10 +26,7 @@ describe Unidom::Action::Searching, type: :model do
26
26
  }
27
27
 
28
28
  it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
29
-
30
- it_behaves_like 'belongs_to', model_attributes, :reason, Unidom::Action::Reason, { name: 'Some Reason' }
31
-
32
- it_behaves_like 'monomorphic scope', model_attributes, :caused_by, :reason
29
+ it_behaves_like 'Unidom::Action::Concerns::AsCaused', model_attributes
33
30
 
34
31
  it_behaves_like 'validates text', model_attributes, :resource_name,
35
32
  length: 1..described_class.columns_hash['resource_name'].limit
@@ -21,10 +21,7 @@ describe Unidom::Action::StateTransition, type: :model do
21
21
  }
22
22
 
23
23
  it_behaves_like 'Unidom::Common::Concerns::ModelExtension', model_attributes
24
-
25
- it_behaves_like 'belongs_to', model_attributes, :reason, Unidom::Action::Reason, { name: 'Some Reason' }
26
-
27
- it_behaves_like 'monomorphic scope', model_attributes, :caused_by, :reason
24
+ it_behaves_like 'Unidom::Action::Concerns::AsCaused', model_attributes
28
25
 
29
26
  end
30
27
 
@@ -0,0 +1 @@
1
+ require 'rspec/models/unidom/action/concerns/as_caused_shared_examples'
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Action
3
- VERSION = '1.17.7'.freeze
3
+ VERSION = '1.17.8'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-action
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.7
4
+ version: 1.17.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -47,6 +47,7 @@ files:
47
47
  - app/models/unidom/action/application_record.rb
48
48
  - app/models/unidom/action/concerns/as_acted.rb
49
49
  - app/models/unidom/action/concerns/as_actor_party.rb
50
+ - app/models/unidom/action/concerns/as_caused.rb
50
51
  - app/models/unidom/action/concerns/as_obsolesced.rb
51
52
  - app/models/unidom/action/concerns/as_obsolescer_party.rb
52
53
  - app/models/unidom/action/concerns/as_searcher_party.rb
@@ -68,6 +69,7 @@ files:
68
69
  - db/migrate/20000512000000_create_unidom_obsolescings.rb
69
70
  - db/migrate/20000513000000_create_unidom_searchings.rb
70
71
  - lib/rspec/models/unidom/action/acting_spec.rb
72
+ - lib/rspec/models/unidom/action/concerns/as_caused_shared_examples.rb
71
73
  - lib/rspec/models/unidom/action/obsolescing_spec.rb
72
74
  - lib/rspec/models/unidom/action/reason_spec.rb
73
75
  - lib/rspec/models/unidom/action/searching_spec.rb
@@ -78,6 +80,7 @@ files:
78
80
  - lib/unidom/action.rb
79
81
  - lib/unidom/action/engine.rb
80
82
  - lib/unidom/action/models_rspec.rb
83
+ - lib/unidom/action/rspec_shared_examples.rb
81
84
  - lib/unidom/action/types_rspec.rb
82
85
  - lib/unidom/action/validators_rspec.rb
83
86
  - lib/unidom/action/version.rb