active_mocker 2.3.0 → 2.3.1

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: b6857ef7a6d6e842ef53b64fc87f08f8b7e36c11
4
- data.tar.gz: 81e5e8273ee2302efae6bf5d2610a77ae9d6704e
3
+ metadata.gz: b786f26685352ec1315bf5b715c7b2ffdcd37df6
4
+ data.tar.gz: f70eee54d0a03d5f4fe13a1a5aa077dd11de19da
5
5
  SHA512:
6
- metadata.gz: 441d757202f71f10019f96d4710143d872d97a8a58341e884448e398313a0085de4202745dd535312c0946643a67ef2bf2ffc1b545a0cd532e35f388bd431bdd
7
- data.tar.gz: efc1a21ff7fb7641c7635196efd4a9e325a919d87b26c6f16695512d7915897a7949b7bd9f58c1dc6ee76ff1997519a3db6ccf4bc5053fc6abbd01a3799a187e
6
+ metadata.gz: b1566d93d8b03eb55856f62e03275da366218a40929d04be9c95140ea7791c6f71fe2bc83fd8bfbed2bfdbf6e19d34f96898c5e9be7567d965c3739b7265ef9f
7
+ data.tar.gz: ca35c36eed333a2f64777241a968bfd19c937b6914154ee8d6743f1640c40344992afdcaa2dbea67bb26a165ceee976b41400a679773fcfc96288ad6a925949d
@@ -1,6 +1,13 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 2.3.1 - 2016-09-26
5
+ ### Fix
6
+ - `create_<association>` failed to set the foreign key.
7
+
8
+ ### Enhancement
9
+ - Specific ActiveMocker exceptions now all inherit from `ActiveMocker::BaseError`
10
+
4
11
  ## 2.3.0 - 2016-08-29
5
12
  ### Feature
6
13
  - Added `#first_or_create`, `#first_or_create!`, and `#first_or_initialize`
@@ -105,8 +105,11 @@ module ActiveMocker
105
105
  @@built_types[type] ||= Virtus::Attribute.build(type)
106
106
  end
107
107
 
108
- def classes(klass)
109
- ActiveMocker::LoadedMocks.find(klass)
108
+ def classes(klass, fail_hard=false)
109
+ ActiveMocker::LoadedMocks.find(klass).tap do |found_class|
110
+ raise MockNotLoaded, "The ActiveMocker version of #{klass} is not required." if fail_hard && !found_class
111
+ found_class
112
+ end
110
113
  end
111
114
 
112
115
  # @param [Array<ActiveMocker::Base>] collection, an array of mock instances
@@ -152,8 +155,8 @@ module ActiveMocker
152
155
 
153
156
  private :call_mock_method
154
157
 
155
- def classes(klass)
156
- self.class.send(:classes, klass)
158
+ def classes(klass, fail_hard = false)
159
+ self.class.send(:classes, klass, fail_hard)
157
160
  end
158
161
 
159
162
  private :classes
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveMocker
3
- class RecordNotFound < StandardError
3
+ class BaseError < StandardError
4
+ end
5
+ class RecordNotFound < BaseError
4
6
  end
5
7
 
6
8
  module Mock
@@ -8,7 +10,7 @@ module ActiveMocker
8
10
  RecordNotFound = ActiveMocker::RecordNotFound
9
11
  end
10
12
 
11
- class IdError < StandardError
13
+ class IdError < BaseError
12
14
  end
13
15
 
14
16
  # Raised when unknown attributes are supplied via mass assignment.
@@ -22,15 +24,18 @@ module ActiveMocker
22
24
  end
23
25
  end
24
26
 
25
- class UpdateMocksError < Exception
27
+ class UpdateMocksError < BaseError
26
28
  def initialize(name, mock_version, gem_version)
27
29
  super("#{name} was built with #{mock_version} but the gem version is #{gem_version}. Run `rake active_mocker:build` to update.")
28
30
  end
29
31
  end
30
32
 
31
- class NotImplementedError < Exception
33
+ class NotImplementedError < BaseError
34
+ end
35
+
36
+ class Error < BaseError
32
37
  end
33
38
 
34
- class Error < Exception
39
+ class MockNotLoaded < BaseError
35
40
  end
36
41
  end
@@ -15,16 +15,14 @@ read_association(:<%= meth.name %>) || write_association(:<%= meth.name %>, clas
15
15
  def build_<%= meth.name %>(attributes={}, &block)
16
16
  <% association = relation_find(:name, meth.name).first -%>
17
17
  <% if association -%>
18
- association = classes('<%= association.class_name %>').try(:new, attributes, &block)
19
- write_association(:<%= meth.name %>, association) unless association.nil?
18
+ self.<%= meth.name %> = classes('<%= association.class_name %>', true).new(attributes, &block)
20
19
  <% end -%>
21
20
  end
22
21
 
23
22
  def create_<%= meth.name %>(attributes={}, &block)
24
23
  <% association = relation_find(:name, meth.name).first -%>
25
24
  <% if association -%>
26
- association = classes('<%= association.class_name %>').try(:create,attributes, &block)
27
- write_association(:<%= meth.name %>, association) unless association.nil?
25
+ self.<%= meth.name %> = classes('<%= association.class_name %>', true).create(attributes, &block)
28
26
  <% end -%>
29
27
  end
30
28
  alias_method :create_<%= meth.name %>!, :create_<%= meth.name %>
@@ -45,14 +43,14 @@ end
45
43
  def build_<%= meth.name %>(attributes={}, &block)
46
44
  <% association = relation_find(:name, meth.name).first -%>
47
45
  <% if association -%>
48
- write_association(:<%= meth.name %>, classes('<%= association.class_name %>').new(attributes, &block)) if classes('<%= association.class_name %>')
46
+ self.<%= meth.name %>= classes('<%= association.class_name %>', true).new(attributes, &block)
49
47
  <% end -%>
50
48
  end
51
49
 
52
50
  def create_<%= meth.name %>(attributes={}, &block)
53
51
  <% association = relation_find(:name, meth.name).first -%>
54
52
  <% if association -%>
55
- write_association(:<%= meth.name %>, classes('<%= association.class_name %>').new(attributes, &block)) if classes('<%= association.class_name %>')
53
+ self.<%= meth.name %>= classes('<%= association.class_name %>', true).new(attributes, &block)
56
54
  <% end -%>
57
55
  end
58
56
  alias_method :create_<%= meth.name %>!, :create_<%= meth.name %>
@@ -79,4 +77,4 @@ end
79
77
  def <%= meth.name %>=(val)
80
78
  write_association(:<%= meth.name %>, ActiveMocker::HasAndBelongsToMany.new(val))
81
79
  end
82
- <% end -%>
80
+ <% end -%>
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveMocker
3
- VERSION = "2.3.0"
3
+ VERSION = "2.3.1"
4
4
  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: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport