active_mocker 2.1.3 → 2.2.0

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +5 -0
  4. data/lib/active_mocker.rb +7 -6
  5. data/lib/active_mocker/config.rb +6 -8
  6. data/lib/active_mocker/deprecated_components/mock_abilities.rb +6 -10
  7. data/lib/active_mocker/deprecated_components/rspec.rb +2 -1
  8. data/lib/active_mocker/display_errors.rb +3 -2
  9. data/lib/active_mocker/error_object.rb +13 -13
  10. data/lib/active_mocker/file_path_to_ruby_class.rb +2 -3
  11. data/lib/active_mocker/file_writer.rb +125 -0
  12. data/lib/active_mocker/generate.rb +56 -71
  13. data/lib/active_mocker/hash_new_style.rb +2 -1
  14. data/lib/active_mocker/loaded_mocks.rb +9 -11
  15. data/lib/active_mocker/mock.rb +28 -26
  16. data/lib/active_mocker/mock/alias_attribute.rb +19 -0
  17. data/lib/active_mocker/mock/association.rb +2 -1
  18. data/lib/active_mocker/mock/base.rb +22 -20
  19. data/lib/active_mocker/mock/belongs_to.rb +1 -1
  20. data/lib/active_mocker/mock/collection.rb +6 -6
  21. data/lib/active_mocker/mock/do_nothing_active_record_methods.rb +4 -7
  22. data/lib/active_mocker/mock/exceptions.rb +1 -4
  23. data/lib/active_mocker/mock/has_and_belongs_to_many.rb +2 -1
  24. data/lib/active_mocker/mock/has_many.rb +6 -7
  25. data/lib/active_mocker/mock/has_one.rb +2 -2
  26. data/lib/active_mocker/mock/hash_process.rb +2 -2
  27. data/lib/active_mocker/mock/mock_relation.rb +1 -0
  28. data/lib/active_mocker/mock/object_inspect.rb +2 -2
  29. data/lib/active_mocker/mock/queries.rb +12 -16
  30. data/lib/active_mocker/mock/records.rb +3 -3
  31. data/lib/active_mocker/mock/relation.rb +5 -5
  32. data/lib/active_mocker/mock/single_relation.rb +2 -4
  33. data/lib/active_mocker/mock/template_methods.rb +3 -5
  34. data/lib/active_mocker/mock_creator.rb +78 -22
  35. data/lib/active_mocker/mock_template.erb +1 -0
  36. data/lib/active_mocker/mock_template/_recreate_class_method_calls.erb +12 -0
  37. data/lib/active_mocker/null_progress.rb +2 -2
  38. data/lib/active_mocker/parent_class.rb +4 -2
  39. data/lib/active_mocker/progress.rb +6 -8
  40. data/lib/active_mocker/public_methods.rb +3 -2
  41. data/lib/active_mocker/railtie.rb +3 -3
  42. data/lib/active_mocker/rspec.rb +2 -1
  43. data/lib/active_mocker/rspec_helper.rb +4 -3
  44. data/lib/active_mocker/task.rake +9 -10
  45. data/lib/active_mocker/template_creator.rb +5 -5
  46. data/lib/active_mocker/version.rb +2 -1
  47. metadata +25 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b140042c4be2000d8ff69f0c61498876a2d2b4e5
4
- data.tar.gz: 70ea49b50c9ccdb1faf340b2392a3c3a65ecff75
3
+ metadata.gz: 05720b7a53a8a8d14dacf57d5ba1d92be772ff13
4
+ data.tar.gz: 9a2db70acca737f482b0b0d73ab13cf2c7e49595
5
5
  SHA512:
6
- metadata.gz: 3eac64b9a66fa2a107221e59a7ba2285e273f29bd90b5df6d358669e514ea0ed2b0631d4402dc575c8ced6098b0f70f8abdc390b3c708b97f3beb50b37f4aa77
7
- data.tar.gz: 6bda4b0492259a07978df406f431e1f39017d6440c12da700a513263eadc1c31428df3f8a8b63c4892cc06c207ccc1b7299e03484ea0db7b3baaecaa893040d6
6
+ metadata.gz: 0296c4a1536fd52d860b604877191ba75102221095546685dfdef441860f361a6b71352b7f74eb21a5dd487d33913575363986e8f9b8caa469a78a80f43f6126
7
+ data.tar.gz: 478ec70d8c0fa0cb8d439ab86ab9f6920f0b098b40a1887435cbf96bb1082b04a5d76f2654fa3b10ae336523f46dc75ce1720811d65c8f9b65c3123c9eb2cd8d
@@ -1,6 +1,19 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## 2.2.0 - 2016-05-03
5
+ ### Feature
6
+ - Add `ActiveMocker::Mock#slice`
7
+ - Import alias_attribute usage to mock - With supporting methods `attribute_alias?(name)` and `attribute_alias(name)`
8
+
9
+ ### Fix
10
+ - When an include/extended module is not locally defined, but defined in the same namespace as the mock it was not correctly namespaced
11
+ - Fix issue NoMethodError in Rails 5.beta when introspection activerecord model.
12
+
13
+ ## Enhancement
14
+ - Ignore all non ActiveRecord::Base subclasses
15
+ - Make rake dependency less strict `>= 10.0`
16
+
4
17
  ## 2.1.3 - 2016-03-21
5
18
  ### Fix
6
19
  - Issue where namespaced mocks would not be auto stubbed.
data/README.md CHANGED
@@ -288,6 +288,8 @@ See [Documentation](http://rdoc.info/github/zeisler/active_mocker/master/ActiveM
288
288
  * column_names/attribute_names
289
289
  * delete_all/destroy_all
290
290
  * table_name
291
+ * slice
292
+ * alias_attributes
291
293
 
292
294
  **Query Methods** - [docs](http://rdoc.info/github/zeisler/active_mocker/master/ActiveMocker/Mock/Queries)
293
295
 
@@ -340,6 +342,9 @@ See [Documentation](http://rdoc.info/github/zeisler/active_mocker/master/ActiveM
340
342
  * attribute_names
341
343
  * attribute_present?
342
344
  * has_attribute?
345
+ * slice
346
+ * attribute_alias?
347
+ * alias_attributes
343
348
 
344
349
  **has_one/belongs_to/has_many**
345
350
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # _ _ __ __ _
2
3
  # /\ | | (_) | \/ | | |
3
4
  # / \ ___| |_ ___ _____| \ / | ___ ___| | _____ _ __
@@ -8,12 +9,12 @@
8
9
  # By Dustin Zeisler
9
10
 
10
11
  require "rubygems"
11
- require 'active_mocker/version'
12
- require 'active_mocker/railtie' if defined?(Rails)
13
- require 'forwardable'
14
- require 'active_support/all'
15
- require 'active_mocker/public_methods'
16
- require 'active_mocker/config'
12
+ require "active_mocker/version"
13
+ require "active_mocker/railtie" if defined?(Rails)
14
+ require "forwardable"
15
+ require "active_support/all"
16
+ require "active_mocker/public_methods"
17
+ require "active_mocker/config"
17
18
  require "reverse_parameters"
18
19
  require "active_record_schema_scrapper"
19
20
  require "dissociated_introspection"
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveMocker
2
3
  class Config
3
4
  class << self
4
-
5
5
  attr_accessor :model_dir,
6
6
  :mock_dir,
7
7
  :single_model_path,
@@ -10,9 +10,7 @@ module ActiveMocker
10
10
  :disable_modules_and_constants,
11
11
  :mock_append_name
12
12
 
13
- def model_base_classes=(val)
14
- @model_base_classes = val
15
- end
13
+ attr_writer :model_base_classes
16
14
 
17
15
  # @see ActiveMocker#configure
18
16
  def set
@@ -27,7 +25,7 @@ module ActiveMocker
27
25
  @model_dir = nil unless @model_dir
28
26
  @mock_dir = nil unless @mock_dir
29
27
  @mock_append_name = "Mock"
30
- rails_defaults if Object.const_defined?('Rails')
28
+ rails_defaults if Object.const_defined?("Rails")
31
29
  end
32
30
 
33
31
  def reset_all
@@ -37,13 +35,13 @@ module ActiveMocker
37
35
  :single_model_path,
38
36
  :progress_bar,
39
37
  :error_verbosity,
40
- :mock_append_name
38
+ :mock_append_name,
41
39
  ].each { |ivar| instance_variable_set("@#{ivar}", nil) }
42
40
  end
43
41
 
44
42
  def rails_defaults
45
- @model_dir = File.join(Rails.root, 'app/models') unless @model_dir
46
- @mock_dir = File.join(Rails.root, 'spec/mocks') unless @mock_dir
43
+ @model_dir = File.join(Rails.root, "app/models") unless @model_dir
44
+ @mock_dir = File.join(Rails.root, "spec/mocks") unless @mock_dir
47
45
  end
48
46
 
49
47
  def progress_class
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveMocker
2
3
  # @deprecated to keep using until removal, require this file.
3
4
  module MockAbilities
4
5
  module InstanceAndClassMethods
5
-
6
- def mock_instance_method(method, exe_bind=false, &block)
6
+ def mock_instance_method(method, exe_bind = false, &block)
7
7
  mockable_instance_methods[method.to_sym] = MockMethod.new(block, exe_bind)
8
8
  end
9
9
 
10
- alias_method :stub_instance_method, :mock_instance_method
10
+ alias stub_instance_method mock_instance_method
11
11
 
12
12
  def clear_mocked_methods
13
13
  mockable_instance_methods.clear
@@ -39,7 +39,6 @@ module ActiveMocker
39
39
  return instance_exec(method.arguments, &method.block) if method.exe_bind
40
40
  method.block.call(*method.arguments)
41
41
  end
42
-
43
42
  end
44
43
 
45
44
  def self.included(base)
@@ -53,28 +52,26 @@ module ActiveMocker
53
52
  end
54
53
 
55
54
  module ClassMethods
56
-
57
55
  include InstanceAndClassMethods
58
56
 
59
57
  def mockable_class_methods
60
58
  @mockable_class_methods ||= {}
61
59
  end
62
60
 
63
- def mock_class_method(method, exe_bind=false, &block)
61
+ def mock_class_method(method, exe_bind = false, &block)
64
62
  mockable_class_methods[method.to_sym] = MockMethod.new(block, exe_bind)
65
63
  end
66
64
 
67
- alias_method :stub_class_method, :mock_class_method
65
+ alias stub_class_method mock_class_method
68
66
 
69
67
  def call_mock_method(method:, caller:, arguments: [])
70
68
  mock_method = mockable_class_methods[method.to_sym]
71
- is_implemented(mock_method, method, '::', caller)
69
+ is_implemented(mock_method, method, "::", caller)
72
70
  mock_method.arguments = arguments
73
71
  execute_block(mock_method)
74
72
  end
75
73
 
76
74
  private :call_mock_method
77
-
78
75
  end
79
76
 
80
77
  include InstanceAndClassMethods
@@ -94,7 +91,6 @@ module ActiveMocker
94
91
  end
95
92
 
96
93
  class MockMethod
97
-
98
94
  attr_accessor :block, :arguments, :exe_bind
99
95
 
100
96
  def initialize(block, exe_bind)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "active_mocker/rspec"
2
3
 
3
4
  module ActiveMocker
@@ -9,4 +10,4 @@ module ActiveMocker
9
10
  active_mocker.mocks.find(*args)
10
11
  end
11
12
  end
12
- end
13
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveMocker
2
3
  class DisplayErrors
3
4
  attr_reader :errors, :model_count, :out
@@ -29,7 +30,7 @@ module ActiveMocker
29
30
 
30
31
  def display_errors
31
32
  uniq_errors.each do |e|
32
- next if e.level == :debug unless ENV["DEBUG"]
33
+ next unless ENV["DEBUG"] || !(e.level == :debug)
33
34
  if ActiveMocker::Config.error_verbosity == 3
34
35
  out.puts "#{e.class_name} has the following errors:"
35
36
  out.puts e.message.colorize(e.level_color)
@@ -62,7 +63,7 @@ module ActiveMocker
62
63
 
63
64
  def failure_count_message
64
65
  if ActiveMocker::Config.error_verbosity > 0 && (success_count < model_count || uniq_errors.count > 0)
65
- out.puts "#{ model_count - success_count } mock(s) out of #{model_count} failed."
66
+ out.puts "#{model_count - success_count} mock(s) out of #{model_count} failed."
66
67
  end
67
68
  end
68
69
  end
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveMocker
2
3
  class ErrorObject
3
-
4
4
  attr_reader :message, :level, :original_error, :type, :class_name
5
5
 
6
6
  def initialize(level: :warn, message:, class_name:, type:, original_error: nil)
@@ -13,17 +13,17 @@ module ActiveMocker
13
13
 
14
14
  def self.build_from(object: nil, exception: nil, class_name: nil, type: nil)
15
15
  if object
16
- args = [:message, :original_error, :level, :type, :class_name].each_with_object({}) do |meth, hash|
16
+ args = [:message, :original_error, :level, :type, :class_name].each_with_object({}) do |meth, hash|
17
17
  hash[meth] = object.public_send(meth) if object.respond_to? meth
18
18
  end
19
19
  args[:type] = type unless type.nil?
20
20
  args[:class_name] = class_name unless class_name.nil?
21
- return self.new(args)
21
+ return new(args)
22
22
  elsif exception && class_name
23
- return self.new(message: exception.message,
24
- class_name: class_name,
25
- original_error: exception,
26
- type: type ? type : :standard_error)
23
+ return new(message: exception.message,
24
+ class_name: class_name,
25
+ original_error: exception,
26
+ type: type ? type : :standard_error)
27
27
  end
28
28
  raise ArgumentError
29
29
  end
@@ -34,12 +34,12 @@ module ActiveMocker
34
34
 
35
35
  def level_color
36
36
  case level
37
- when :standard_error, :fatal, :error
38
- :red
39
- when :warn
40
- :yellow
41
- when :info
42
- :default
37
+ when :standard_error, :fatal, :error
38
+ :red
39
+ when :warn
40
+ :yellow
41
+ when :info
42
+ :default
43
43
  end
44
44
  end
45
45
  end
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveMocker
2
3
  class FilePathToRubyClass
3
-
4
4
  attr_reader :class_path, :base_path
5
5
 
6
6
  def initialize(base_path:, class_path:)
@@ -9,8 +9,7 @@ module ActiveMocker
9
9
  end
10
10
 
11
11
  def to_s
12
- File.basename((class_path.gsub(base_path + "/", "")).split("/").map(&:camelize).join("::"), '.rb')
12
+ File.basename(class_path.gsub(base_path + "/", "").split("/").map(&:camelize).join("::"), ".rb")
13
13
  end
14
-
15
14
  end
16
15
  end
@@ -0,0 +1,125 @@
1
+ module ActiveMocker
2
+ class FileWriter
3
+ include Virtus.model
4
+ delegate :name, to: :model, prefix: true
5
+
6
+ attribute :model, Object
7
+ attribute :file, String
8
+ attribute :display_errors
9
+ attribute :config
10
+ attribute :model_names, Array
11
+
12
+ def write!
13
+ assure_dir_path_exists!
14
+
15
+ safe_write { |f| process!(f) }
16
+ end
17
+
18
+ private
19
+
20
+ def process!(file_out)
21
+ result = create_mock(file_out, model)
22
+ status = collect_errors(result.errors)
23
+
24
+ ok = result.completed? && status.successful?
25
+ return unless ok
26
+
27
+ display_errors.success_count += 1
28
+ end
29
+
30
+ def safe_write
31
+ File.open(mock_file_path, "w") do |file_out|
32
+ begin
33
+ yield file_out
34
+ rescue StandardError => e
35
+ rescue_clean_up(e, file_out)
36
+ end
37
+ end
38
+ end
39
+
40
+ def rescue_clean_up(e, file_out)
41
+ display_errors.failed_models << model_name
42
+ file_out.close unless file_out.closed?
43
+ File.delete(file_out.path) if File.exist?(file_out.path)
44
+ display_errors.wrap_an_exception(e, model_name)
45
+ end
46
+
47
+ def scrapper
48
+ @scrapper ||= ActiveRecordSchemaScrapper.new(model: model)
49
+ end
50
+
51
+ def mock_file_path
52
+ File.join(Config.mock_dir, mock_file_name)
53
+ end
54
+
55
+ def mock_file_name
56
+ "#{model_name.underscore}_#{config.mock_append_name.underscore}.rb"
57
+ end
58
+
59
+ def assure_dir_path_exists!
60
+ unless File.exist?(File.dirname(mock_file_path))
61
+ FileUtils.mkdir_p(File.dirname(mock_file_path))
62
+ end
63
+ end
64
+
65
+ def create_mock(file_out, model)
66
+ MockCreator.new(file: File.open(file),
67
+ file_out: file_out,
68
+ schema_scrapper: scrapper,
69
+ klasses_to_be_mocked: model_names,
70
+ enabled_partials: enabled_partials,
71
+ mock_append_name: config.mock_append_name,
72
+ active_record_model: model).create
73
+ end
74
+
75
+ OtherErrors = Struct.new(:successful?)
76
+
77
+ def collect_errors(create_mock_errors)
78
+ add_errors!
79
+
80
+ if create_mock_errors.present? || schema.attribute_errors?
81
+ display_errors.failed_models << model_name
82
+ File.delete(mock_file_path) if File.exist?(mock_file_path)
83
+ display_errors.add(create_mock_errors)
84
+ OtherErrors.new(false)
85
+ else
86
+ OtherErrors.new(true)
87
+ end
88
+ end
89
+
90
+ def add_errors!
91
+ add_error(schema.association_errors, :associations)
92
+ add_error(schema.attribute_errors, :attributes)
93
+ end
94
+
95
+ def add_error(error, type)
96
+ display_errors.wrap_errors(error, model_name, type: type)
97
+ end
98
+
99
+ def enabled_partials
100
+ if config.disable_modules_and_constants
101
+ MockCreator.enabled_partials_default - [*:modules_constants]
102
+ else
103
+ MockCreator.enabled_partials_default
104
+ end
105
+ end
106
+
107
+ def schema
108
+ @schema ||= Schema.new(ActiveRecordSchemaScrapper.new(model: model))
109
+ end
110
+
111
+ class Schema < SimpleDelegator
112
+ def attribute_errors?
113
+ attribute_errors.any? { |e| e.level == :error }
114
+ end
115
+
116
+ def association_errors
117
+ associations.errors
118
+ end
119
+
120
+ def attribute_errors
121
+ attributes.errors
122
+ end
123
+ end
124
+ end
125
+ end
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative "file_writer"
3
+
1
4
  module ActiveMocker
2
5
  class Generate
3
-
4
6
  def initialize
5
- raise ArgumentError, "mock_dir is missing a valued value!" if config.mock_dir.nil? || config.mock_dir.empty?
7
+ check_directory!(:mock_dir)
6
8
  create_mock_dir
7
- raise ArgumentError, "model_dir is missing a valued value!" if config.model_dir.nil? || config.model_dir.empty? || !Dir.exists?(config.model_dir)
9
+ check_directory!(:model_dir)
10
+ raise_missing_arg(:model_dir) unless Dir.exist?(config.model_dir)
11
+
8
12
  @display_errors = DisplayErrors.new(models_paths.count)
9
13
  end
10
14
 
@@ -12,92 +16,81 @@ module ActiveMocker
12
16
  def call
13
17
  clean_up
14
18
  progress_init
15
- models_paths.each do |file|
16
- model_name = model_name(file)
17
- model = get_model_const(model_name)
18
- mock_file_name = "#{model_name.underscore}_#{config.mock_append_name.underscore}.rb"
19
- mock_file_path = File.join(Config.mock_dir, mock_file_name)
20
- assure_dir_path_exists(mock_file_path)
21
- schema_scrapper = ActiveRecordSchemaScrapper.new(model: model)
22
- File.open(mock_file_path, 'w') do |file_out|
23
- begin
24
- result = create_mock(file, file_out, schema_scrapper)
25
- status = collect_errors(mock_file_path, result.errors, schema_scrapper, model_name)
26
- display_errors.success_count += 1 if result.completed? && status.successful?
27
- rescue => e
28
- rescue_clean_up(e, file_out, model_name)
29
- end
30
- end
19
+
20
+ active_record_models_with_files.each do |model, file|
21
+ write_file(model, file)
22
+
31
23
  progress.increment
32
24
  end
25
+
33
26
  display_errors.display_errors
34
27
  self
35
28
  end
36
29
 
37
- def get_model_const(model_name)
38
- model_name.constantize
39
- rescue StandardError, LoadError => e
40
- display_errors.wrap_an_exception(e, model_name)
30
+ def active_record_models
31
+ @active_record_models ||= active_record_models_with_files.map(&:first)
41
32
  end
42
33
 
43
34
  private
44
35
 
45
- attr_reader :display_errors
46
-
47
- def create_mock(file, file_out, schema_scrapper)
48
- MockCreator.new(file: File.open(file),
49
- file_out: file_out,
50
- schema_scrapper: schema_scrapper,
51
- klasses_to_be_mocked: model_names,
52
- enabled_partials: enabled_partials,
53
- mock_append_name: config.mock_append_name).create
54
- end
55
-
56
- OtherErrors = Struct.new(:successful?)
57
- def collect_errors(mock_file_path, create_mock_errors, schema_scrapper, model_name)
58
- display_errors.wrap_errors(schema_scrapper.associations.errors, model_name, type: :associations)
59
- display_errors.wrap_errors(schema_scrapper.attributes.errors, model_name, type: :attributes)
60
- if create_mock_errors.present? || schema_scrapper.attributes.errors.any? { |e| e.level == :error }
61
- display_errors.failed_models << model_name
62
- File.delete(mock_file_path) if File.exists?(mock_file_path)
63
- display_errors.add(create_mock_errors)
64
- OtherErrors.new(false)
65
- else
66
- OtherErrors.new(true)
36
+ attr_reader :display_errors, :progress
37
+
38
+ def check_directory!(type)
39
+ value = config.send(type)
40
+
41
+ if value.nil? || value.empty?
42
+ raise_missing_arg(type)
67
43
  end
68
44
  end
69
45
 
70
- def rescue_clean_up(e, file_out, model_name)
71
- display_errors.failed_models << model_name
72
- file_out.close unless file_out.closed?
73
- File.delete(file_out.path) if File.exists?(file_out.path)
74
- display_errors.wrap_an_exception(e, model_name)
46
+ def raise_missing_arg(type)
47
+ raise ArgumentError, "#{type} is missing a valued value!"
75
48
  end
76
49
 
77
- def model_name(file)
78
- FilePathToRubyClass.new(base_path: config.model_dir, class_path: file).to_s
50
+ def write_file(model, file)
51
+ writer = FileWriter.new(
52
+ model: model,
53
+ file: file,
54
+ display_errors: display_errors,
55
+ config: config,
56
+ model_names: model_names)
57
+
58
+ writer.write!
79
59
  end
80
60
 
81
- def model_names
82
- @model_names ||= models_paths.map { |p| model_name(p) }
61
+ def progress_init
62
+ @progress = config.progress_class.create(active_record_models.count)
83
63
  end
84
64
 
85
- def progress
86
- @progress
65
+ def model_names
66
+ @model_names ||= active_record_models.map(&:name)
87
67
  end
88
68
 
89
- def progress_init
90
- @progress = config.progress_class.create(models_paths.count)
69
+ def active_record_models_with_files
70
+ @active_record_models_with_files ||= models_paths.map do |file|
71
+ model = constant_from(model_name_from(file))
72
+ [model, file] if model
73
+ end.compact
91
74
  end
92
75
 
93
76
  def models_paths
94
77
  @models_paths ||= Dir.glob(config.single_model_path || File.join(config.model_dir, "**/*.rb"))
95
78
  end
96
79
 
97
- def assure_dir_path_exists(file)
98
- unless File.exists?(File.dirname(file))
99
- FileUtils::mkdir_p(File.dirname(file))
100
- end
80
+ def constant_from(model_name)
81
+ constant = model_name.constantize
82
+ return unless constant.ancestors.include?(ActiveRecord::Base)
83
+ constant
84
+ rescue NameError, LoadError => e
85
+ display_errors.wrap_an_exception(e, model_name)
86
+ nil
87
+ end
88
+
89
+ def model_name_from(file)
90
+ FilePathToRubyClass.new(
91
+ base_path: config.model_dir,
92
+ class_path: file
93
+ ).to_s
101
94
  end
102
95
 
103
96
  def config
@@ -105,15 +98,7 @@ module ActiveMocker
105
98
  end
106
99
 
107
100
  def create_mock_dir
108
- FileUtils::mkdir_p(config.mock_dir) unless Dir.exists?(config.mock_dir)
109
- end
110
-
111
- def enabled_partials
112
- if config.disable_modules_and_constants
113
- MockCreator.enabled_partials_default - [*:modules_constants]
114
- else
115
- MockCreator.enabled_partials_default
116
- end
101
+ FileUtils.mkdir_p(config.mock_dir) unless Dir.exist?(config.mock_dir)
117
102
  end
118
103
 
119
104
  def clean_up