activeshepherd 0.8.2 → 0.8.3

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: 2be7d44a796133c6bc1525d61525bfb8fd41b2a7
4
- data.tar.gz: 855223e0395a13e684e74312b0f321e64f3c5dd8
3
+ metadata.gz: 153175687781797f0c540d8d0f3dfb197fdf5614
4
+ data.tar.gz: b9313dacab98cc1705485bedc41681edd150b337
5
5
  SHA512:
6
- metadata.gz: 77a062d057ef8fda104caada5cb0a5cc305235c5293e494da38d4abe401b487678d104912d07e1157124522f8dcfa354f7c383b192440f527372f5a4d412dc87
7
- data.tar.gz: a5be04b9739418db11ca255759f4a309c2d208ceb2017bca5b244ebabc34edcc08a4cbf2d6c16729c0980bc38988820807ea8e16f14a8a5853054665ea4d676e
6
+ metadata.gz: c2fd7733faa80b4a9bddf7e6eecac5a2739774e9c157fbbe06621f3960e54143803aab9ec88826e717c83741cb281231d1151104a1fc4f6db7f2e44e318fb47f
7
+ data.tar.gz: b4a4fc0c6d5104a9c2d5746532ac3bf88e241040d7d27e68e4a5814b6faa3c0bec639a469a8b341b972b97d0677a8e626a0950585529fd61635a2bcf09e45f2b
@@ -33,6 +33,19 @@ class ActiveShepherd::Aggregate
33
33
  run_through_serializer(attribute_name, value, :load)
34
34
  end
35
35
 
36
+ def in_namespace?(name)
37
+ my_namespace = model.class.to_s
38
+ if name == my_namespace
39
+ false
40
+ elsif name.deconstantize == my_namespace
41
+ true
42
+ elsif name.deconstantize == my_namespace.deconstantize && !name.deconstantize.blank?
43
+ true
44
+ else
45
+ false
46
+ end
47
+ end
48
+
36
49
  private
37
50
 
38
51
  def associations
@@ -62,6 +75,7 @@ private
62
75
  def traverse_association?(association)
63
76
  return false if association.options[:readonly]
64
77
  return false if association.macro == :belongs_to
78
+ return false unless in_namespace?(association.klass.to_s)
65
79
 
66
80
  true
67
81
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveShepherd
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
@@ -296,6 +296,17 @@ class IntegrationTest < MiniTest::Unit::TestCase
296
296
  assert_equal :mango, @project.fruit
297
297
  end
298
298
 
299
+ def test_changes_to_one_aggregate_do_not_include_associated_aggregate
300
+ build_persisted_state
301
+
302
+ @owner = User.create! name: 'Joe Schmoe'
303
+ @project.owner = @owner
304
+ @project.save!
305
+ @owner.reload
306
+
307
+ refute @owner.aggregate_state.has_key?(:projects)
308
+ end
309
+
299
310
  private
300
311
 
301
312
  # Test 'changes' behavior with this common background
@@ -39,7 +39,12 @@ ActiveRecord::Migration.create_table :project_todo_assignments, force: true do |
39
39
  end
40
40
 
41
41
 
42
- User = Class.new(ActiveRecord::Base)
42
+ class User < ActiveRecord::Base
43
+ act_as_aggregate_root!
44
+
45
+ has_many :projects, inverse_of: :owner, dependent: :destroy, autosave: true,
46
+ validate: true, foreign_key: :owner_id
47
+ end
43
48
 
44
49
  class Comment < ActiveRecord::Base
45
50
  belongs_to :commentable, polymorphic: true, counter_cache: true
@@ -49,7 +54,7 @@ end
49
54
  class Project < ActiveRecord::Base
50
55
  act_as_aggregate_root!
51
56
 
52
- belongs_to :owner, class_name: "User"
57
+ belongs_to :owner, class_name: "User", inverse_of: :projects, touch: true
53
58
 
54
59
  has_one :detail, inverse_of: :project, dependent: :destroy, autosave: true
55
60
 
@@ -1,4 +1,27 @@
1
1
  require 'test_helper'
2
2
 
3
+ class MyKlass
4
+ SubKlass = Class.new
5
+ end
6
+
3
7
  class AggregateTest < MiniTest::Unit::TestCase
8
+ def setup
9
+ @aggregate = ActiveShepherd::Aggregate.new MyKlass.new
10
+ end
11
+
12
+ def test_in_namespace_returns_true_only_if_associated_klass_in_namespace
13
+ refute @aggregate.in_namespace?('MyKlass')
14
+ assert @aggregate.in_namespace?('MyKlass::SubKlass')
15
+ refute @aggregate.in_namespace?('MyKlass::SubKlass::SubSubKlass')
16
+ assert @aggregate.in_namespace?('MyKlass::Foo')
17
+ refute @aggregate.in_namespace?('Foo')
18
+
19
+ @aggregate = ActiveShepherd::Aggregate.new MyKlass::SubKlass.new
20
+ refute @aggregate.in_namespace?('MyKlass')
21
+ refute @aggregate.in_namespace?('MyKlass::SubKlass')
22
+ assert @aggregate.in_namespace?('MyKlass::SubKlass::SubSubKlass')
23
+ assert @aggregate.in_namespace?('MyKlass::Foo')
24
+ assert @aggregate.in_namespace?('MyKlass::SubSubKlass')
25
+ refute @aggregate.in_namespace?('Foo')
26
+ end
4
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeshepherd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl