active_mocker 1.7.beta1 → 1.7.beta2

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: 28e91fcc9b5c93645841ebd051ba5285963cd47c
4
- data.tar.gz: 698a036a310a979192d60904535d07422c5d0aef
3
+ metadata.gz: e0975aed9ead531daac453611e42d222199073bd
4
+ data.tar.gz: abffc672d856ccfde039f23bd118695a3448961f
5
5
  SHA512:
6
- metadata.gz: 3e7933644a582361d63c37fc8161e8ac3d74d91568a1195a29b408ce6d0ffe633b40327088ae19873440bd0432d39dbbd563179fe91cb0e467ab65600ca3ae5c
7
- data.tar.gz: 77e8d430cc60a459822f5d6f20364993a5306417485ef1610de4cc5c9c4ecbeb2e8370a8859b2a548f5f8545d876cdb6f4723fe4f388128d9c3cf85fe0a01fed
6
+ metadata.gz: e488d0a90b6058678ba60d1e94c8212ac7c5723c1fa218e6c2a333107020842e975027b7314d3eb46deec41e0a533787e87ae119fced6da38e73e6bca6ddb453
7
+ data.tar.gz: 2eb69e280988d909e648c1a18a22017205a57b97b172b3c28a8e98ae0c762bc8c6ad6121bb5e9e8b470c9d158e65171de37c1de9cccbb99ef89941ba78e55460
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
+ ## 1.7.beta2 - 2-14-09-18
4
+
5
+ ### Fix
6
+ - Bug where creating record with an id could cause a duplicate id error.
7
+ - Issue whenever an ActiveRecord Model has no schema behind it.
8
+ - Issue assigning association would fail, added guard to @associations to only read and write symbols.
9
+
10
+ ## 1.7.beta1 - 2-14-09-6
11
+
12
+ ### Enhancement
13
+ - A class that Inherits a model now has the table of the parent.
14
+ - Use this option if you need to modify where the mock generation hooks into. `ActiveMocker::Config.model_base_classes = %w[ ActiveRecord::Base ]`
15
+ - When running `rake active_mocker:build` it will display the number of mocks that failed.
16
+ - Remove deprecated option `ActiveMocker.mock`
17
+ - Exceptions in mock generation no longer halt the rest of the mocks from generating.
18
+ - Add explicit message of what to do when a method is unimplemented.
19
+ - Will create own log file `log/active_mocker.log` it will be cleared on each generation.
20
+ - Attributes, associations, and scopes will now inherit from their parent class.
21
+ - Initialization of an abstract class will raise an error.
22
+ - Remove Experimental feature reload
23
+ - Remove experimental flag for set foreign_key on collection for has_many, belongs_to, and has_one.
24
+ - `record._create_caller_locations` for debugging obj’s creation location.
25
+
26
+ ### Fix
27
+ - Issue where using table names as the model file would replace a parent class with a child class that had the same table.
28
+
3
29
  ## 1.6.3 - 2014-08-14
4
30
 
5
31
  ### Fix
data/README.md CHANGED
@@ -9,11 +9,6 @@ ActiveMocker creates mocks classes from ActiveRecord models. Allowing your test
9
9
 
10
10
  Examples from a real apps
11
11
 
12
- Finished in 0.54599 seconds
13
- 190 examples, 0 failures
14
-
15
- ------
16
-
17
12
  Finished in 1 seconds
18
13
  374 examples, 0 failures
19
14
 
@@ -13,6 +13,7 @@ require 'active_mocker/mock/queries'
13
13
  require 'active_mocker/mock/relation'
14
14
  require 'active_mocker/mock/association'
15
15
  require 'active_mocker/mock/has_many'
16
+ require 'active_mocker/mock/single_relation'
16
17
  require 'active_mocker/mock/has_one'
17
18
  require 'active_mocker/mock/has_and_belongs_to_many'
18
19
  require 'active_mocker/mock/belongs_to'
@@ -39,7 +39,7 @@ class Base
39
39
  if attributes.is_a?(Array)
40
40
  attributes.collect { |attr| create(attr, &block) }
41
41
  else
42
- record = new
42
+ record = new(id: attributes[:id] || attributes['id'])
43
43
  record.save
44
44
  record.assign_attributes(attributes, &block)
45
45
  record._create_caller_locations = caller_locations
@@ -283,12 +283,12 @@ class Base
283
283
 
284
284
  # @api private
285
285
  def read_association(attr)
286
- @associations[attr]
286
+ @associations[attr.to_sym]
287
287
  end
288
288
 
289
289
  # @api private
290
290
  def write_association(attr, value)
291
- @associations[attr] = value
291
+ @associations[attr.to_sym] = value
292
292
  end
293
293
 
294
294
  protected :read_attribute, :write_attribute, :read_association, :write_association
@@ -1,18 +1,13 @@
1
1
  module ActiveMocker
2
2
  module Mock
3
3
 
4
- class BelongsTo
4
+ class BelongsTo < SingleRelation
5
5
 
6
6
  attr_reader :item
7
7
 
8
8
  def initialize(item, child_self:, foreign_key:, foreign_id:)
9
- @item = item
10
9
  child_self.send(:write_attribute, foreign_key, foreign_id) if item.try(:persisted?)
11
-
12
- has_many = child_self.class.send('mocked_class').tableize
13
- has_one = child_self.class.send('mocked_class').tableize.singularize
14
- item.send(has_many) << child_self if item.respond_to?("#{has_many}=") && !item.send(has_many).include?(child_self)
15
- item.send(:write_association, has_one, child_self) if item.respond_to?("#{has_one}=")
10
+ super
16
11
  end
17
12
 
18
13
  end
@@ -1,17 +1,13 @@
1
1
  module ActiveMocker
2
2
  module Mock
3
3
 
4
- class HasOne
4
+ class HasOne < SingleRelation
5
5
 
6
6
  attr_reader :item
7
7
 
8
8
  def initialize(item, child_self:, foreign_key:, foreign_id:)
9
- @item = item
10
9
  item.send(:write_attribute, foreign_key, foreign_id) if item.respond_to?("#{foreign_key}=") && !foreign_id.nil?
11
- has_many = child_self.class.send('mocked_class').tableize
12
- has_one = child_self.class.send('mocked_class').tableize.singularize
13
- item.send(has_many) << child_self if item.respond_to?("#{has_many}=") && !item.send(has_many).include?(child_self)
14
- item.send(:write_association, has_one, child_self) if item.respond_to?("#{has_one}=")
10
+ super
15
11
  end
16
12
 
17
13
  end
@@ -0,0 +1,24 @@
1
+ module ActiveMocker
2
+ module Mock
3
+
4
+ class SingleRelation
5
+
6
+ attr_reader :item
7
+
8
+ def initialize(item, child_self:, foreign_key:, foreign_id:)
9
+ @item = item
10
+ assign_associations(child_self, item)
11
+ end
12
+
13
+ def assign_associations(child_self, item)
14
+ has_many = child_self.class.send('mocked_class').tableize
15
+ has_one = child_self.class.send('mocked_class').tableize.singularize
16
+ item.send(has_many) << child_self if item.respond_to?("#{has_many}=") && !item.send(has_many).include?(child_self)
17
+ item.send(:write_association, has_one, child_self) if item.respond_to?("#{has_one}=")
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+
@@ -97,11 +97,11 @@ class <%= class_name + @mock_append_name %> < <%= parent_class %>
97
97
  <%= '# has_one' unless has_one.empty? -%>
98
98
  <% has_one.each do |meth| %>
99
99
  def <%= meth.name %>
100
- read_association('<%= meth.name %>')
100
+ read_association(:<%= meth.name %>)
101
101
  end
102
102
 
103
103
  def <%= meth.name %>=(val)
104
- @associations['<%= meth.name %>'] = val
104
+ @associations[:<%= meth.name %>] = val
105
105
  ActiveMocker::Mock::HasOne.new(val, child_self: self, foreign_key: '<%= meth.foreign_key %>', foreign_id: @attributes['id']).item
106
106
  end
107
107
 
@@ -1,3 +1,3 @@
1
1
  module ActiveMocker
2
- VERSION = "1.7.beta1"
2
+ VERSION = "1.7.beta2"
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.beta1
4
+ version: 1.7.beta2
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-06 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -312,6 +312,7 @@ files:
312
312
  - lib/active_mocker/mock/queries.rb
313
313
  - lib/active_mocker/mock/records.rb
314
314
  - lib/active_mocker/mock/relation.rb
315
+ - lib/active_mocker/mock/single_relation.rb
315
316
  - lib/active_mocker/mock/template_methods.rb
316
317
  - lib/active_mocker/mock_template.erb
317
318
  - lib/active_mocker/model_reader.rb