shoulda_matchmakers 0.1.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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +21 -0
  4. data/lib/controller/action_controller/action_controller_controller_sm_model.rb +53 -0
  5. data/lib/controller/action_controller/action_controller_controller_sm_model_helper.rb +73 -0
  6. data/lib/controller/action_controller/matchmakers/callbacks.rb +56 -0
  7. data/lib/controller/action_controller/matchmakers/filter_param.rb +69 -0
  8. data/lib/controller/action_controller/matchmakers/permit.rb +510 -0
  9. data/lib/controller/action_controller/matchmakers/redirect_to.rb +126 -0
  10. data/lib/controller/action_controller/matchmakers/render_template.rb +198 -0
  11. data/lib/controller/action_controller/matchmakers/render_with_layout.rb +72 -0
  12. data/lib/controller/action_controller/matchmakers/rescue_from.rb +96 -0
  13. data/lib/controller/action_controller/matchmakers/respond_with.rb +71 -0
  14. data/lib/controller/action_controller/matchmakers/route.rb +586 -0
  15. data/lib/controller/action_controller/matchmakers/set_flash.rb +136 -0
  16. data/lib/controller/action_controller/matchmakers/set_session.rb +115 -0
  17. data/lib/controller/action_controller/permitted_params_definition.rb +60 -0
  18. data/lib/generators/shoulda_matchmakers/controller_matcher_generator.rb +87 -0
  19. data/lib/generators/shoulda_matchmakers/controller_matcher_generator_helper.rb +92 -0
  20. data/lib/generators/shoulda_matchmakers/factory_generator.rb +86 -0
  21. data/lib/generators/shoulda_matchmakers/install_generator.rb +10 -0
  22. data/lib/generators/shoulda_matchmakers/model_matcher_generator.rb +87 -0
  23. data/lib/generators/shoulda_matchmakers/model_matcher_generator_helper.rb +107 -0
  24. data/lib/model/active_record/active_record_model_sm_model.rb +50 -0
  25. data/lib/model/active_record/active_record_model_sm_model_helper.rb +206 -0
  26. data/lib/model/active_record/factory_sm_model.rb +28 -0
  27. data/lib/model/active_record/factory_sm_model_helper.rb +124 -0
  28. data/lib/model/active_record/matchmakers/accept_nested_attributes_for.rb +66 -0
  29. data/lib/model/active_record/matchmakers/allow_value.rb +137 -0
  30. data/lib/model/active_record/matchmakers/associations.rb +52 -0
  31. data/lib/model/active_record/matchmakers/define_enum_for.rb +53 -0
  32. data/lib/model/active_record/matchmakers/delegate_method.rb +101 -0
  33. data/lib/model/active_record/matchmakers/have_db_column.rb +33 -0
  34. data/lib/model/active_record/matchmakers/have_db_index.rb +39 -0
  35. data/lib/model/active_record/matchmakers/have_readonly_attribute.rb +32 -0
  36. data/lib/model/active_record/matchmakers/have_secure_password.rb +32 -0
  37. data/lib/model/active_record/matchmakers/serialize.rb +67 -0
  38. data/lib/model/active_record/matchmakers/validations.rb +169 -0
  39. data/lib/model/active_record/options_definition.rb +160 -0
  40. data/lib/shoulda_matchmakers.rb +48 -0
  41. data/lib/shoulda_matchmakers/version.rb +3 -0
  42. data/lib/support/command_line_interface.rb +100 -0
  43. data/lib/support/controller_generator.rb +198 -0
  44. data/lib/support/indefinite_article.rb +70 -0
  45. data/lib/support/to_discard/belong_to.rb +94 -0
  46. data/lib/support/to_discard/have_and_belong_to_many.rb +83 -0
  47. data/lib/support/to_discard/have_many.rb +96 -0
  48. data/lib/support/to_discard/have_one.rb +98 -0
  49. data/lib/support/to_discard/permit_refactor.rb +270 -0
  50. data/lib/support/to_discard/render_template_new.rb +204 -0
  51. data/lib/support/to_discard/render_template_reconstruction.rb +188 -0
  52. data/lib/support/to_discard/use_around_action.rb +20 -0
  53. data/lib/support/to_discard/use_before_action.rb +20 -0
  54. data/lib/support/to_discard/validate_absence_of.rb +16 -0
  55. data/lib/support/to_discard/validate_acceptance_of.rb +16 -0
  56. data/lib/support/to_discard/validate_confirmation_of.rb +16 -0
  57. data/lib/support/to_discard/validate_exclusion_of.rb +145 -0
  58. data/lib/support/to_discard/validate_inclusion_of.rb +94 -0
  59. data/lib/support/to_discard/validate_length_of.rb +16 -0
  60. data/lib/support/to_discard/validate_numericality_of.rb +16 -0
  61. data/lib/support/to_discard/validate_presence_of.rb +16 -0
  62. data/lib/support/to_discard/validate_uniqueness_of.rb +16 -0
  63. data/lib/support/to_discard/validation_old.rb +37 -0
  64. data/lib/support/to_discard/validations.rb +41 -0
  65. data/lib/support/to_discard/validations_conditional.rb +146 -0
  66. data/lib/support/trace_debug_lines.txt +319 -0
  67. data/lib/support/util.rb +15 -0
  68. data/lib/templates/controller/action_controller/controller_spec_template.haml +146 -0
  69. data/lib/templates/factory/active_record/factory_template.haml +13 -0
  70. data/lib/templates/model/active_record/model_spec_template.haml +233 -0
  71. data/lib/templates/shoulda_matchmakers.rb +112 -0
  72. metadata +263 -0
@@ -0,0 +1,160 @@
1
+ module ShouldaMatchmakers
2
+ module Model
3
+ module ActiveRecord
4
+ class OptionsDefinition
5
+
6
+
7
+
8
+ ### Attribute Accessors ###
9
+ attr_accessor :options_hash
10
+
11
+ def initialize
12
+ @options_hash = {
13
+ allow_blank: "allow_blank",
14
+ allow_destroy: "allow_destroy({ option_value })",
15
+ allow_nil: "allow_nil",
16
+ autosave: "autosave({ option_value })",
17
+ case_sensitive: "case_insensitive",
18
+ class_name: "class_name('{ option_value }')",
19
+ counter_cache: "counter_cache({ option_value })",
20
+ dependent: "dependent(:{ option_value })",
21
+ dependent_boolean: "dependent({ option_value })",
22
+ equal_to: "is_equal_to({ option_value })",
23
+ even: "even",
24
+ foreign_key: "with_foreign_key('{ option_value }')",
25
+ greater_than: "is_greater_than({ option_value })",
26
+ greater_than_or_equal_to: "is_greater_than_or_equal_to({ option_value })",
27
+ in: "is_at_least({ option_value.first.to_s }).\n is_at_most({ option_value.last.to_s })",
28
+ in_array: "in_array({ option_value })",
29
+ in_range: "in_range({ option_value })",
30
+ inverse_of: "inverse_of(:{ option_value })",
31
+ is: "is_equal_to({ option_value.to_s })",
32
+ join_table: "join_table('{ option_value }')",
33
+ less_than: "is_less_than({ option_value })",
34
+ less_than_or_equal_to: "is_less_than_or_equal_to({ option_value })",
35
+ limit: "limit({ option_value })",
36
+ maximum: "is_at_most({ option_value.to_s })",
37
+ message_double_quotes: "with_message(\"{ option_value }\")",
38
+ message_single_quotes: "with_message('{ option_value }')",
39
+ minimum: "is_at_least({ option_value.to_s })",
40
+ odd: "odd",
41
+ on: "on(:{ option_value })",
42
+ only_integer: "only_integer",
43
+ order_double_quotes: "order(\"{ option_value }\")",
44
+ order_single_quotes: "order('{ option_value }')",
45
+ primary_key: "with_primary_key('{ option_value }')",
46
+ scope: "scoped_to({ option_value })",
47
+ source: "source(:{ option_value })",
48
+ through: "through(:{ option_value })",
49
+ too_long_double_quotes: "with_long_message(\"{ option_value }\")",
50
+ too_long_single_quotes: "with_long_message('{ option_value }')",
51
+ too_short_double_quotes: "with_short_message(\"{ option_value }\")",
52
+ too_short_single_quotes: "with_short_message('{ option_value }')",
53
+ touch: "touch({ option_value })",
54
+ update_only: "update_only({ option_value })",
55
+ validate: "validate({ option_value })"
56
+ }
57
+ end
58
+
59
+ # else
60
+ # # IMPLEMENTATION TODO: Possibly handle this case option as an error or modify evaluation of option above upon return from call
61
+ # ""
62
+
63
+ # ALLOW VALUE
64
+ # IMPLEMENTATION TODO: Determine if Shoulda Matchers recognizes the 'multiline' option
65
+ # when :multiline
66
+ # "multiline(#{ option_value })"
67
+
68
+ # VALIDATE ACCEPTANCE OF
69
+ # IMPLEMENTATION TODO: Determine if Shoulda Matchers recognizes the 'accept' option
70
+ # when :accept
71
+ # "accept('#{ option_value }')"
72
+
73
+ # VALIDATE EXCLUSION OF
74
+ # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
75
+ # when :allow_blank
76
+ # "allow_blank"
77
+ # IMPLEMENTATION TODO: Determine if 'allow_nil' is a valid option
78
+ # when :allow_nil
79
+ # "allow_nil"
80
+
81
+ # VALIDATE INCLUSION OF
82
+ # IMPLEMENTATION TODO: Determine if it is possible to implement 'with_low_message' and 'with_high_message'
83
+ # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
84
+ # when :allow_blank
85
+ # "allow_blank"
86
+ # IMPLEMENTATION TODO: Determine if 'allow_nil' is a valid option
87
+ # when :allow_nil
88
+ # "allow_nil"
89
+
90
+ # VALIDATE LENGTH OF
91
+ # IMPLEMENTATION TODO: Determine if it is possible to implement 'tokenizer'
92
+ # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
93
+ # when :allow_blank
94
+ # "allow_blank"
95
+ # IMPLEMENTATION TODO: Determine if 'allow_nil' is a valid option
96
+ # when :allow_nil
97
+ # "allow_nil"
98
+ # IMPLEMENTATION TODO: Determine if Shoulda Matchers recognizes the 'wrong_length' option
99
+ # if option_value.include? '"'
100
+ # "wrong_length('#{ option_value }')"
101
+ # else
102
+ # "wrong_length(\"#{ option_value }\")"
103
+ # end
104
+
105
+ # VALIDATE NUMERICALITY OF
106
+ # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
107
+ # when :allow_blank
108
+ # "allow_blank"
109
+ # IMPLEMENTATION TODO: Determine if Shoulda Matchers recognizes the 'other_than' option
110
+ # when :other_than
111
+ # "other_than(:#{ option_value })"
112
+
113
+ # BELONG TO
114
+ # IMPLEMENTATION TODO: Determine if it is possible to implement 'conditions'
115
+ # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
116
+ # when :order
117
+ # if option_value.include? '"'
118
+ # "order('#{ option_value }')"
119
+ # else
120
+ # "order(\"#{ option_value }\")"
121
+ # end
122
+
123
+ # HAVE AND BELONG TO MANY
124
+ # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
125
+ # when :order
126
+ # if option_value.include? '"'
127
+ # "order('#{ option_value }')"
128
+ # else
129
+ # "order(\"#{ option_value }\")"
130
+ # end
131
+
132
+ # HAVE MANY
133
+ # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
134
+ # when :order
135
+ # if option_value.include? '"'
136
+ # "order('#{ option_value }')"
137
+ # else
138
+ # "order(\"#{ option_value }\")"
139
+ # end
140
+
141
+ # HAVE ONE
142
+ # IMPLEMENTATION TODO: Determine if Shoulda Matchers recognizes the 'inverse_of' option for 'have_one'
143
+ # when :inverse_of
144
+ # "inverse_of(:#{ option_value })"
145
+ # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
146
+ # when :order
147
+ # if option_value.include? '"'
148
+ # "order('#{ option_value }')"
149
+ # else
150
+ # "order(\"#{ option_value }\")"
151
+ # end
152
+
153
+ # VALIDATE UNIQUENESS OF
154
+ # IMPLEMENTATION TODO: Determine if it is possible to implement 'ignoring_case_sensitivity'
155
+
156
+
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,48 @@
1
+ module ShouldaMatchmakers
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration) if block_given?
9
+ end
10
+
11
+ class Configuration
12
+
13
+ attr_accessor :active_record_class_names_included,
14
+ :active_record_class_names_excluded,
15
+ :active_record_model_tests_path,
16
+
17
+ :action_controller_controller_names_included,
18
+ :action_controller_controller_names_excluded,
19
+ :action_controller_controller_tests_path,
20
+
21
+ :active_record_model_class_names_for_factories_included,
22
+ :active_record_model_class_names_for_factories_excluded,
23
+ :active_record_model_factories_path,
24
+
25
+ :include_enums,
26
+ :preferred_generated_code_line_length
27
+
28
+ def initialize
29
+
30
+ @active_record_class_names_included = %w()
31
+ @active_record_class_names_excluded = %w()
32
+ @active_record_model_tests_path = 'spec/shoulda_matchmakers/models/active_record'
33
+
34
+ @action_controller_controller_names_included = %w()
35
+ @action_controller_controller_names_excluded = %w()
36
+ @action_controller_controller_tests_path = 'spec/shoulda_matchmakers/controllers/action_controller'
37
+
38
+ @active_record_model_class_names_for_factories_included = %w()
39
+ @active_record_model_class_names_for_factories_excluded = %w()
40
+ @active_record_model_factories_path = 'spec/shoulda_matchmakers/factories/active_record'
41
+
42
+ @include_enums = true
43
+ @preferred_generated_code_line_length = 120
44
+
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module ShouldaMatchmakers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,100 @@
1
+ require 'slop'
2
+ require 'json'
3
+
4
+ class CLI
5
+
6
+ # set up defaults in its own method
7
+ def cli_flags
8
+ options = Slop::Options.new
9
+ options.banner = "usage: RAILS_ENV=test rails generate shoulda_matchmakers:model [options] ...\n" +
10
+ " RAILS_ENV=test rails generate shoulda_matchmakers:controller [options] ...\n" +
11
+ " RAILS_ENV=test rails generate shoulda_matchmakers:factory [options] ..."
12
+
13
+ options.separator ""
14
+ options.separator "Options (in order of precedence):"
15
+
16
+ options.null "-ci", "--config_included", "Lists models/controllers included in the shoulda_matchmakers configuration file"
17
+
18
+ options.array "-i []", "--include []", "User entered array of names of models/controllers for which to generate matchmakers\n" +
19
+ " All models in apps/models and controllers in apps/controllers are\nincluded by default.\n" +
20
+ " (When this option is used, the '_included' and '_excluded' settings\nin the configuration file are ignored.)",
21
+ delimiter: ','
22
+
23
+ options.array "-ii []", "--include_plus []", "User entered array of names of models/controllers to include after\nconfiguration file inclusions/exclusions have been applied.",
24
+ delimiter: ','
25
+
26
+ options.null "-ce", "--config_excluded", "List of models/controllers excluded in the shoulda_matchmakers configuration file"
27
+
28
+ options.array "-e []", "--exclude []", " User entered array of names of models/controllers for which to\nnot generate matchmakers\n" +
29
+ " No models/controllers in apps/models and apps/controllers are\nexcluded by default.\n" +
30
+ " (If this option is used, the '_included' and '_excluded' settings\nin the configuration file are ignored.\n" +
31
+ " If the 'include' option is used, this option is ignored.)",
32
+ delimiter: ','
33
+
34
+ options.array "-ee []", "--exclude_plus []", "User entered array of names of models/controllers to exclude after\nconfiguration file inclusions/exclusions have been applied.",
35
+ delimiter: ','
36
+
37
+ options.null "-h", "--help", "Displays this list of options"
38
+
39
+ options
40
+ end
41
+
42
+ def parse_arguments(command_line_options, parser)
43
+ begin
44
+ # slop has the advantage over optparse that it can do strings and not just ARGV
45
+ result = parser.parse command_line_options
46
+ result.to_hash
47
+
48
+ # Very important to not bury this begin/rescue logic in another method
49
+ # otherwise it will be difficult to check to see if -h or --help was passed
50
+ # in this case -h acts as an unknown option as long as we don't define it
51
+ # in cli_flags.
52
+ rescue Slop::UnknownOption
53
+ # print help
54
+ puts cli_flags
55
+ exit
56
+ # If, for your program, you can't exit here, then reraise Slop::UnknownOption
57
+ # raise a custom exception, push the rescue up to main or track that "help was invoked"
58
+ end
59
+ end
60
+
61
+ def flags
62
+ [:ce, :ci, :e, :ee, :h, :i, :ii]
63
+ end
64
+
65
+ def set?(arguments, flag)
66
+ !arguments.fetch(flag).nil?
67
+ end
68
+
69
+ # main style entry point
70
+ def main(command_line_options=ARGV)
71
+ parser = Slop::Parser.new cli_flags
72
+ arguments = parse_arguments(command_line_options, parser)
73
+
74
+ if arguments.key?(:ce) || arguments.key?(:ci) || arguments.key?(:h)
75
+ if arguments.key?(:ci)
76
+
77
+ end
78
+ if arguments.key?(:ce)
79
+
80
+ end
81
+ if arguments.key?(:h)
82
+ puts cli_flags
83
+ end
84
+ exit
85
+ end
86
+
87
+ elsif set?(arguments, :port)
88
+ puts portquiz arguments[:port]
89
+ elsif set?(arguments, :down)
90
+ puts is_it_up arguments[:down]
91
+ end
92
+ end
93
+
94
+
95
+
96
+ end
97
+
98
+ # this kind of sucks, you shouldn't ever change your code to accomodate tests
99
+ # but this is a main
100
+ # CLI.new.main if !defined?(RSpec)
@@ -0,0 +1,198 @@
1
+ require 'controller/action_controller/action_controller_controller'
2
+
3
+ module ShouldaMatchmakers
4
+ class ControllerGenerator < Rails::Generators::Base
5
+
6
+ source_root(File.expand_path(File.dirname(__FILE__)))
7
+
8
+ class_option :include, type: :array,
9
+ require: false,
10
+ aliases: '-i',
11
+ default: [],
12
+ desc: "Allows user to enter a space-delimited list of controller names for which to generate matchmakers\n" +
13
+ " All controllers that are descendants of ActionController::Base are included by default.\n" +
14
+ " Example: -i DriversController LicensesController Vehicle::CarsController Vehicle::BusesController\n\n" +
15
+ " When this option is used, the '_included' and '_excluded' settings in the\n" +
16
+ " '~/config/initializers/shoulda_matchmakers.rb' configuration file are ignored.\n\n\n"
17
+
18
+ class_option :exclude, type: :array,
19
+ require: false,
20
+ aliases: '-e',
21
+ default: [],
22
+ desc: "Allows user to enter a space-delimited list of controller names for which to not generate matchmakers\n" +
23
+ " No controllers that are descendants of ActionController::Base are excluded by default.\n" +
24
+ " Example: -e DriversController Vehicle::CarsController\n\n" +
25
+ " When this option is used, the '_included' and '_excluded' settings in the\n" +
26
+ " '~/config/initializers/shoulda_matchmakers.rb' configuration file are ignored.\n\n\n"
27
+
28
+ class_option :include_with_config, type: :array,
29
+ require: false,
30
+ aliases: '-I',
31
+ default: [],
32
+ desc: "Same as '-i/-include', except that configuration file inclusions/exclusions\n" +
33
+ " are not ignored. Configuration file inclusions/exclusions are applied first\n" +
34
+ " then the controllers in the arguments list of this option are applied.\n\n\n"
35
+
36
+ class_option :exclude_with_config, type: :array,
37
+ require: false,
38
+ aliases: '-E',
39
+ default: [],
40
+ desc: "Same as '-e/-exclude', except that configuration file inclusions/exclusions\n" +
41
+ " are not ignored. Configuration file inclusions/exclusions are applied first\n" +
42
+ " then the controllers in the arguments list of this option are applied.\n\n\n"
43
+
44
+ def create_controller_matchmakers
45
+
46
+ generator_options = options.to_hash
47
+
48
+ # TRACE.debug ""
49
+ # TRACE.debug " GENERATOR OPTIONS:"
50
+ # TRACE.debug generator_options.inspect
51
+
52
+ load_application
53
+ generate_controller_matchmakers(generator_options)
54
+ end
55
+
56
+ def load_application
57
+ Rails.application.try(:eager_load!)
58
+ end
59
+
60
+ def generate_controller_matchmakers(generator_options)
61
+ app_action_controller_descendants_names = load_action_controller_controller_names
62
+ if app_action_controller_descendants_names.present?
63
+ selected_action_controller_controller_names = select_action_controller_controller_names(app_action_controller_descendants_names, generator_options)
64
+
65
+ # TRACE.debug " SELECTED ACTION CONTROLLER CONTROLLERS:"
66
+ # TRACE.debug selected_action_controller_controller_names.inspect
67
+
68
+ selected_action_controller_controller_names.each do |controller_name|
69
+ save_generate(controller_name) do
70
+ @action_controller_controller_sm_model = ::ShouldaMatchmakers::Controller::ActionController::ActionControllerController.new(controller_name)
71
+ template_filename = File.expand_path('vendor/shoulda_matchmakers/lib/templates/controller/action_controller/controller_spec_template.haml')
72
+ template = File.read(template_filename)
73
+ create_file "#{ ShouldaMatchmakers.configuration.controllers_test_path }/#{ controller_name.underscore }_spec.rb",
74
+ Haml::Engine.new(template, filename: template_filename, format: :html5).to_html(binding)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ def load_action_controller_controller_names
81
+ if defined?(::ActionController::Base)
82
+ ActionController::Base.descendants.map(&:name)
83
+ else
84
+ []
85
+ end
86
+ end
87
+
88
+ def save_generate(controller_name)
89
+ begin
90
+ yield
91
+ rescue => e
92
+ puts "Cannot create controller spec for #{ controller_name }. Reason #{ e.message }"
93
+ end
94
+ end
95
+
96
+ def select_action_controller_controller_names(app_action_controller_descendants_names, generator_options)
97
+ generator_options_include = generator_options.fetch('include')
98
+ generator_options_exclude = generator_options.fetch('exclude')
99
+ generator_options_include_with_config = generator_options.fetch('include_with_config')
100
+ generator_options_exclude_with_config = generator_options.fetch('exclude_with_config')
101
+
102
+ if generator_options_include.present?
103
+ select_controller_names_generator_option_include(app_action_controller_descendants_names, generator_options_include)
104
+ elsif generator_options_exclude.present?
105
+ select_controller_names_generator_option_exclude(app_action_controller_descendants_names, generator_options_exclude)
106
+ elsif generator_options_include_with_config.present?
107
+ select_controller_names_generator_option_include_with_config(app_action_controller_descendants_names, generator_options_include_with_config)
108
+ elsif generator_options_exclude_with_config.present?
109
+ select_controller_names_generator_option_exclude_with_config(app_action_controller_descendants_names, generator_options_exclude_with_config)
110
+ else
111
+ select_controller_names_config(app_action_controller_descendants_names)
112
+ end
113
+ end
114
+
115
+ def select_controller_names_generator_option_include(app_action_controller_descendants_names, include_controller_names)
116
+ app_action_controller_descendants_names.map(&:name).select { |app_controller_name| include_controller_names.include? app_controller_name }.uniq.sort
117
+ end
118
+
119
+ def select_controller_names_generator_option_exclude(app_action_controller_descendants_names, exclude_controller_names)
120
+ app_action_controller_descendants_names.map(&:name).reject { |app_controller_name| exclude_controller_names.include? app_controller_name }.uniq.sort
121
+ end
122
+
123
+ def select_controller_names_generator_option_include_with_config(app_action_controller_descendants_names, include_with_config_controller_names)
124
+ selected_action_controller_controller_names = select_controller_names_config(app_action_controller_descendants_names)
125
+ if selected_action_controller_controller_names.present?
126
+ (selected_action_controller_controller_names + app_action_controller_descendants_names.map.select { |app_controller_name| include_with_config_controller_names.include? app_controller_name }).uniq.sort
127
+ else
128
+ select_controller_names_generator_option_include(app_action_controller_descendants_names, include_with_config_controller_names).uniq.sort
129
+ end
130
+ end
131
+
132
+ def select_controller_names_generator_option_exclude_with_config(app_action_controller_descendants_names, exclude_with_config_controller_names)
133
+ selected_action_controller_controller_names = select_controller_names_config(app_action_controller_descendants_names)
134
+ if selected_action_controller_controller_names.present?
135
+ selected_action_controller_controller_names.map.reject { |app_controller_name| exclude_with_config_controller_names.include? app_controller_name }.uniq.sort
136
+ else
137
+ select_controller_names_generator_option_exclude(app_action_controller_descendants_names, exclude_with_config_controller_names).uniq.sort
138
+ end
139
+ end
140
+
141
+ def select_controller_names_config(app_action_controller_descendants_names)
142
+ controller_names_config_included = ShouldaMatchmakers.configuration.models_included
143
+ controller_names_config_excluded = ShouldaMatchmakers.configuration.models_excluded
144
+
145
+ # TRACE.debug ""
146
+ # TRACE.debug " CONTROLLER NAME INCLUDED - CONFIG:"
147
+ # TRACE.debug controller_names_config_included
148
+ # TRACE.debug " CONTROLLER NAME EXCLUDED - CONFIG:"
149
+ # TRACE.debug controller_names_config_excluded.inspect
150
+
151
+ if controller_names_config_included.present?
152
+
153
+ # app_action_controller_descendants_names.each do |model|
154
+ # # TRACE.debug ""
155
+ # # TRACE.debug " MODEL:"
156
+ # # TRACE.debug model.inspect
157
+ # end
158
+ selected_controller_names_config = app_action_controller_descendants_names.map.select { |app_controller_name| controller_names_config_included.include? app_controller_name }.uniq.sort
159
+
160
+ # TRACE.debug " CONFIG SELECTED CONTROLLERS:"
161
+ # TRACE.debug selected_controller_names_config.inspect
162
+
163
+ selected_controller_names_config
164
+ elsif controller_names_config_excluded.present?
165
+ selected_controller_names_config = app_action_controller_descendants_names.map.reject { |app_controller_name| controller_names_config_excluded.include? app_controller_name }.uniq.sort
166
+
167
+ # TRACE.debug " CONFIG EXCLUDED CONTROLLERS:"
168
+ # TRACE.debug selected_controller_names_config.inspect
169
+
170
+ selected_controller_names_config
171
+ else
172
+
173
+ # TRACE.debug " NO CONTROLLERS INCLUDED OR EXCLUDED:"
174
+ # TRACE.debug app_action_controller_descendants_names.map.inspect
175
+
176
+ app_action_controller_descendants_names.map.uniq.sort
177
+ end
178
+ end
179
+
180
+
181
+ # def create_regression_files
182
+ # Rails.application.eager_load!
183
+ # all_controllers = ApplicationController.descendants << ApplicationController
184
+ # all_controllers.each do |a_controller|
185
+ # a_controller.action_methods.each do |action_method|
186
+ # end
187
+ # end
188
+ # all_controllers.map(&:name).reject { |x| ShouldaMatchmakers.configuration.controllers_excluded.include? x }.each do |controller|
189
+ # @sm_model_action_controller_controller = ::ShouldaMatchmakers::Controller::ActionController::ActionControllerController.new(controller)
190
+ # template_filename = File.expand_path('vendor/shoulda_matchmakers/lib/templates/controller/action_controller/controller_spec_template.haml')
191
+ # template = File.read(template_filename)
192
+ # create_file "#{ ShouldaMatchmakers.configuration.controllers_test_path }/#{ controller.underscore }_spec.rb",
193
+ # Haml::Engine.new(template, filename: template_filename, format: :html5).to_html(binding)
194
+ # end
195
+ # end
196
+
197
+ end
198
+ end