activeshepherd 0.8.3 → 0.8.4

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: 153175687781797f0c540d8d0f3dfb197fdf5614
4
- data.tar.gz: b9313dacab98cc1705485bedc41681edd150b337
3
+ metadata.gz: 99198041d4010d96c14b417691a345b9488e4cef
4
+ data.tar.gz: 71e6095aff2faa19f06750e4cd8cdc1eb37d2880
5
5
  SHA512:
6
- metadata.gz: c2fd7733faa80b4a9bddf7e6eecac5a2739774e9c157fbbe06621f3960e54143803aab9ec88826e717c83741cb281231d1151104a1fc4f6db7f2e44e318fb47f
7
- data.tar.gz: b4a4fc0c6d5104a9c2d5746532ac3bf88e241040d7d27e68e4a5814b6faa3c0bec639a469a8b341b972b97d0677a8e626a0950585529fd61635a2bcf09e45f2b
6
+ metadata.gz: ac3736238e51bfd0868b2afda8495ea524b691230a00f10209cdc86eb8fafd491c375231615d9f273014b87050726e466b4ac38f62c0e0dd6155f99c12e159c8
7
+ data.tar.gz: fff6353d44206d5fc680e94ea7ccfde186e78b396a5eb1a22b68b19e763ef342b1fd90353c67dc71d2721a193c08289bbf842612eee3fd60739e6a010463282f
@@ -21,11 +21,9 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "activerecord", ">= 2.3.17"
22
22
  gem.add_dependency "activesupport", ">= 2.3.17"
23
23
 
24
- gem.add_development_dependency "activerecord", "4.0.0.beta1"
25
- gem.add_development_dependency "guard"
26
- gem.add_development_dependency "guard-minitest"
24
+ gem.add_development_dependency "activerecord", "~> 4.0.2"
27
25
  gem.add_development_dependency "hashie"
28
- gem.add_development_dependency "minitest-reporters"
26
+ gem.add_development_dependency "minitest"
29
27
  gem.add_development_dependency "pry"
30
28
  gem.add_development_dependency "pry-debugger"
31
29
  gem.add_development_dependency "rake"
@@ -50,9 +50,9 @@ private
50
50
 
51
51
  def associations
52
52
  @associations ||= begin
53
- all_associations = model.class.reflect_on_all_associations
54
53
  ostruct = OpenStruct.new untraversable: {}, traversable: {}
55
- all_associations.each_with_object(ostruct) do |association_reflection, ostruct|
54
+ associations_by_table.each_with_object(ostruct) do |(table, associations), ostruct|
55
+ association_reflection = preferred_association_from_set associations
56
56
  if traverse_association?(association_reflection)
57
57
  key = :traversable
58
58
  else
@@ -63,6 +63,24 @@ private
63
63
  end
64
64
  end
65
65
 
66
+ def associations_by_table
67
+ @associations_by_table ||=
68
+ begin
69
+ by_table = Hash.new { |h,k| h[k] = Array.new }
70
+ model.class.reflect_on_all_associations.each do |association_reflection, hash|
71
+ next unless association_reflection.active_record == model.class
72
+ if traverse_association? association_reflection
73
+ by_table[association_reflection.table_name] << association_reflection
74
+ end
75
+ end
76
+ by_table
77
+ end
78
+ end
79
+
80
+ def preferred_association_from_set(associations)
81
+ associations.detect { |a| a.macro == :has_many } || associations.first
82
+ end
83
+
66
84
  def run_through_serializer(attribute_name, value, method)
67
85
  serializer = model.class.serialized_attributes[attribute_name.to_s]
68
86
  if serializer
@@ -76,6 +94,7 @@ private
76
94
  return false if association.options[:readonly]
77
95
  return false if association.macro == :belongs_to
78
96
  return false unless in_namespace?(association.klass.to_s)
97
+ return false if association.is_a?(ActiveRecord::Reflection::ThroughReflection)
79
98
 
80
99
  true
81
100
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveShepherd
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class IntegrationTest < MiniTest::Unit::TestCase
3
+ class IntegrationTest < Minitest::Test
4
4
  def setup
5
5
  Project.destroy_all
6
6
 
@@ -118,9 +118,9 @@ class IntegrationTest < MiniTest::Unit::TestCase
118
118
  end
119
119
 
120
120
  def test_does_not_walk_associations_to_other_entities
121
- @project.aggregate_state = { owner: { name: "Joe Schmoe" } }
122
-
123
- refute_equal "Joe Schmoe", @project.owner.try(:name)
121
+ assert_raises ActiveShepherd::AggregateMismatchError do
122
+ @project.aggregate_state = { owner: { name: "Joe Schmoe" } }
123
+ end
124
124
  end
125
125
 
126
126
  =begin
@@ -1,5 +1,6 @@
1
1
  ActiveRecord::Migration.create_table :users, force: true do |t|
2
2
  t.string :name
3
+ t.belongs_to :favorite_project
3
4
  end
4
5
 
5
6
  ActiveRecord::Migration.create_table :comments, force: true do |t|
@@ -44,6 +45,7 @@ class User < ActiveRecord::Base
44
45
 
45
46
  has_many :projects, inverse_of: :owner, dependent: :destroy, autosave: true,
46
47
  validate: true, foreign_key: :owner_id
48
+ belongs_to :favorite_project, class_name: "Project"
47
49
  end
48
50
 
49
51
  class Comment < ActiveRecord::Base
@@ -55,6 +57,8 @@ class Project < ActiveRecord::Base
55
57
  act_as_aggregate_root!
56
58
 
57
59
  belongs_to :owner, class_name: "User", inverse_of: :projects, touch: true
60
+ has_many :watchers, inverse_of: :favorite_project, class_name: "User",
61
+ foreign_key: :favorite_project_id
58
62
 
59
63
  has_one :detail, inverse_of: :project, dependent: :destroy, autosave: true
60
64
 
@@ -7,13 +7,8 @@ require 'pry'
7
7
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
8
  require 'active_shepherd'
9
9
 
10
- require 'minitest/mock'
11
- require 'minitest/reporters'
12
-
13
10
  require 'minitest/autorun'
14
11
 
15
- MiniTest::Reporters.use! MiniTest::Reporters::DefaultReporter.new
16
-
17
12
  ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
18
13
 
19
14
  ActiveShepherd.enable!(ActiveRecord::Base)
@@ -4,12 +4,14 @@ class MyKlass
4
4
  SubKlass = Class.new
5
5
  end
6
6
 
7
- class AggregateTest < MiniTest::Unit::TestCase
7
+ class AggregateTest < Minitest::Test
8
8
  def setup
9
- @aggregate = ActiveShepherd::Aggregate.new MyKlass.new
9
+ @aggregate = ActiveShepherd::Aggregate.new Project.new
10
10
  end
11
11
 
12
12
  def test_in_namespace_returns_true_only_if_associated_klass_in_namespace
13
+ @aggregate = ActiveShepherd::Aggregate.new MyKlass.new
14
+
13
15
  refute @aggregate.in_namespace?('MyKlass')
14
16
  assert @aggregate.in_namespace?('MyKlass::SubKlass')
15
17
  refute @aggregate.in_namespace?('MyKlass::SubKlass::SubSubKlass')
@@ -24,4 +26,26 @@ class AggregateTest < MiniTest::Unit::TestCase
24
26
  assert @aggregate.in_namespace?('MyKlass::SubSubKlass')
25
27
  refute @aggregate.in_namespace?('Foo')
26
28
  end
29
+
30
+ def test_traversable_associations_excludes_classes_outside_namespace
31
+ refute_includes @aggregate.traversable_associations.keys, :watchers
32
+ end
33
+
34
+ def test_traversable_associations_ignores_redundant_associations
35
+ refute_includes @aggregate.traversable_associations.keys, :recent_todo_list
36
+ end
37
+
38
+ def test_traversable_associations_returns_traversable_associations
39
+ assert_includes @aggregate.traversable_associations.keys, :detail
40
+ assert_includes @aggregate.traversable_associations.keys, :todo_lists
41
+ end
42
+
43
+ def test_traversable_associations_ignores_base_class
44
+ @aggregate = ActiveShepherd::Aggregate.new Project::Comment.new
45
+ refute_includes @aggregate.traversable_associations.keys, :commentable
46
+ end
47
+
48
+ def test_traversable_associations_ignores_has_many_through
49
+ refute_includes @aggregate.traversable_associations.keys, :todos
50
+ end
27
51
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ApplyChangesTest < MiniTest::Unit::TestCase
3
+ class ApplyChangesTest < Minitest::Test
4
4
  def setup
5
5
  @aggregate = OpenStruct.new(
6
6
  raw_attributes: {},
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ChangesValidatorTest < MiniTest::Unit::TestCase
3
+ class ChangesValidatorTest < Minitest::Test
4
4
  def test_deep_reverse_returns_self
5
5
  skip
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ClassValidatorTest < MiniTest::Unit::TestCase
3
+ class ClassValidatorTest < Minitest::Test
4
4
  def test_model_must_autosave_associations
5
5
  skip
6
6
  end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class TraversalTest < Minitest::Test
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeshepherd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ntl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-27 00:00:00.000000000 Z
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -42,44 +42,16 @@ dependencies:
42
42
  name: activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.0.beta1
47
+ version: 4.0.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.0.beta1
55
- - !ruby/object:Gem::Dependency
56
- name: guard
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-minitest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
54
+ version: 4.0.2
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: hashie
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: minitest-reporters
70
+ name: minitest
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - '>='
@@ -220,6 +192,7 @@ files:
220
192
  - test/unit/apply_changes_test.rb
221
193
  - test/unit/changes_validator_test.rb
222
194
  - test/unit/class_validator_test.rb
195
+ - test/unit/traversal_test.rb
223
196
  homepage: http://github.com/ntl/activeshepherd
224
197
  licenses:
225
198
  - MIT
@@ -254,4 +227,5 @@ test_files:
254
227
  - test/unit/apply_changes_test.rb
255
228
  - test/unit/changes_validator_test.rb
256
229
  - test/unit/class_validator_test.rb
230
+ - test/unit/traversal_test.rb
257
231
  has_rdoc: