active_mocker 1.7.beta2 → 1.7.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0975aed9ead531daac453611e42d222199073bd
4
- data.tar.gz: abffc672d856ccfde039f23bd118695a3448961f
3
+ metadata.gz: 568d05ab028a0dd5e561ec9933bd905922671944
4
+ data.tar.gz: 432288a414d9024b74e16631f3727544431dc2c0
5
5
  SHA512:
6
- metadata.gz: e488d0a90b6058678ba60d1e94c8212ac7c5723c1fa218e6c2a333107020842e975027b7314d3eb46deec41e0a533787e87ae119fced6da38e73e6bca6ddb453
7
- data.tar.gz: 2eb69e280988d909e648c1a18a22017205a57b97b172b3c28a8e98ae0c762bc8c6ad6121bb5e9e8b470c9d158e65171de37c1de9cccbb99ef89941ba78e55460
6
+ metadata.gz: 1b5b5f4833d9d294e872c8c3087eb1d2752ecc5fad1cf98a25a9b380e546f68ecd9e46100fc87b16048783913b4eb63d727aa3a1a992b2808033f68693a3a2c7
7
+ data.tar.gz: 6d47573531aa806f71e1cc37cb2886ede715aafdb6f3c4b1f0614711bcb8ad0bbbec533b46ffb22867357466ce4a9e8cef589828c557ea81ae3ce910e63c227e
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
+ ## 1.7.beta3 - 2-14-09-25
4
+
5
+ ### Fix
6
+ - Last beta introduced a breaking regression where after assigning some associations they could not be read. Solution was to never access @associations directly inside mock.
7
+
3
8
  ## 1.7.beta2 - 2-14-09-18
4
9
 
5
10
  ### Fix
@@ -282,8 +282,8 @@ class Base
282
282
  end
283
283
 
284
284
  # @api private
285
- def read_association(attr)
286
- @associations[attr.to_sym]
285
+ def read_association(attr, assign_if_value_nil=nil)
286
+ @associations[attr.to_sym] ||= assign_if_value_nil
287
287
  end
288
288
 
289
289
  # @api private
@@ -54,10 +54,10 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
54
54
  end
55
55
 
56
56
  def <%= meth.name %>=(val)
57
- <% association = belongs_to_foreign_key(meth.name) -%>
57
+ <% association = belongs_to_foreign_key(meth.name) -%>
58
58
  write_attribute(:<%= meth.name %>, val)
59
59
  <% if association -%>
60
- association = classes('<%= association.class_name %>').try(:find_by, id: <%= meth.name %>)
60
+ association = classes('<%= association.class_name %>').try(:find_by, id: <%= meth.name %>)
61
61
  write_association(:<%= association.name %>,association) unless association.nil?
62
62
  <% end -%>
63
63
  end
@@ -69,11 +69,11 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
69
69
  <%= '# belongs_to' unless belongs_to.empty? -%>
70
70
  <% belongs_to.each do |meth| %>
71
71
  def <%= meth.name %>
72
- @associations[:<%= meth.name %>]
72
+ read_association(:<%= meth.name %>)
73
73
  end
74
74
 
75
75
  def <%= meth.name %>=(val)
76
- @associations[:<%= meth.name %>] = val
76
+ write_association(:<%= meth.name %>, val)
77
77
  ActiveMocker::Mock::BelongsTo.new(val, child_self: self, foreign_key: :<%= meth.foreign_key %>, foreign_id: val.try(:id)).item
78
78
  end
79
79
 
@@ -101,8 +101,8 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
101
101
  end
102
102
 
103
103
  def <%= meth.name %>=(val)
104
- @associations[:<%= meth.name %>] = val
105
- ActiveMocker::Mock::HasOne.new(val, child_self: self, foreign_key: '<%= meth.foreign_key %>', foreign_id: @attributes['id']).item
104
+ write_association(:<%= meth.name %>, val)
105
+ ActiveMocker::Mock::HasOne.new(val, child_self: self, foreign_key: '<%= meth.foreign_key %>', foreign_id: self.id).item
106
106
  end
107
107
 
108
108
  def build_<%= meth.name %>(attributes={}, &block)
@@ -124,21 +124,21 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
124
124
  <%= '# has_many' unless has_many.empty? -%>
125
125
  <% has_many.each do |meth| %>
126
126
  def <%= meth.name %>
127
- @associations[:<%= meth.name %>] ||= ActiveMocker::Mock::HasMany.new([],foreign_key: '<%= meth.foreign_key %>', foreign_id: @attributes['id'], relation_class: classes('<%= meth.class_name %>'), source: '<%= meth.source %>')
127
+ read_association(:<%= meth.name %>, ActiveMocker::Mock::HasMany.new([],foreign_key: '<%= meth.foreign_key %>', foreign_id: self.id, relation_class: classes('<%= meth.class_name %>'), source: '<%= meth.source %>'))
128
128
  end
129
129
 
130
130
  def <%= meth.name %>=(val)
131
- @associations[:<%= meth.name %>] ||= ActiveMocker::Mock::HasMany.new(val, foreign_key: '<%= meth.foreign_key %>', foreign_id: @attributes['id'], relation_class: classes('<%= meth.class_name %>'), source: '<%= meth.source %>')
131
+ write_association(:<%= meth.name %>, ActiveMocker::Mock::HasMany.new(val, foreign_key: '<%= meth.foreign_key %>', foreign_id: self.id, relation_class: classes('<%= meth.class_name %>'), source: '<%= meth.source %>'))
132
132
  end
133
133
  <% end -%>
134
134
  <%= '# has_and_belongs_to_many' unless has_and_belongs_to_many.empty? -%>
135
135
  <% has_and_belongs_to_many.each do |meth| %>
136
136
  def <%= meth.name %>
137
- @associations[:<%= meth.name %>] ||= ActiveMocker::Mock::HasAndBelongsToMany.new([])
137
+ read_association(:<%= meth.name %>, ActiveMocker::Mock::HasAndBelongsToMany.new([]))
138
138
  end
139
139
 
140
140
  def <%= meth.name %>=(val)
141
- @associations[:<%= meth.name %>] = ActiveMocker::Mock::HasAndBelongsToMany.new(val)
141
+ write_association(:<%= meth.name %>, ActiveMocker::Mock::HasAndBelongsToMany.new(val))
142
142
  end
143
143
  <% end -%>
144
144
 
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.7.beta2"
2
+ VERSION = "1.7.beta3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_mocker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.beta2
4
+ version: 1.7.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport