shoulda_matchmakers 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/controller/action_controller/action_controller_controller_sm_model_helper.rb +0 -7
  3. data/lib/controller/action_controller/matchmakers/permit.rb +14 -14
  4. data/lib/controller/action_controller/matchmakers/route.rb +0 -383
  5. data/lib/model/active_record/matchmakers/have_db_index.rb +1 -1
  6. data/lib/model/active_record/matchmakers/validations.rb +0 -14
  7. data/lib/shoulda_matchmakers/version.rb +1 -1
  8. data/lib/support/controller_generator.rb +2 -54
  9. data/lib/templates/shoulda_matchmakers.rb +2 -2
  10. metadata +1 -25
  11. data/lib/support/indefinite_article.rb +0 -70
  12. data/lib/support/to_discard/belong_to.rb +0 -94
  13. data/lib/support/to_discard/have_and_belong_to_many.rb +0 -83
  14. data/lib/support/to_discard/have_many.rb +0 -96
  15. data/lib/support/to_discard/have_one.rb +0 -98
  16. data/lib/support/to_discard/permit_refactor.rb +0 -270
  17. data/lib/support/to_discard/render_template_new.rb +0 -204
  18. data/lib/support/to_discard/render_template_reconstruction.rb +0 -188
  19. data/lib/support/to_discard/use_around_action.rb +0 -20
  20. data/lib/support/to_discard/use_before_action.rb +0 -20
  21. data/lib/support/to_discard/validate_absence_of.rb +0 -16
  22. data/lib/support/to_discard/validate_acceptance_of.rb +0 -16
  23. data/lib/support/to_discard/validate_confirmation_of.rb +0 -16
  24. data/lib/support/to_discard/validate_exclusion_of.rb +0 -145
  25. data/lib/support/to_discard/validate_inclusion_of.rb +0 -94
  26. data/lib/support/to_discard/validate_length_of.rb +0 -16
  27. data/lib/support/to_discard/validate_numericality_of.rb +0 -16
  28. data/lib/support/to_discard/validate_presence_of.rb +0 -16
  29. data/lib/support/to_discard/validate_uniqueness_of.rb +0 -16
  30. data/lib/support/to_discard/validation_old.rb +0 -37
  31. data/lib/support/to_discard/validations.rb +0 -41
  32. data/lib/support/to_discard/validations_conditional.rb +0 -146
  33. data/lib/support/trace_debug_lines.txt +0 -319
  34. data/lib/support/util.rb +0 -15
@@ -1,188 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Controller
3
- module ActionController
4
- module Matchmaker
5
- module RenderTemplate
6
-
7
- def render_template_matcher_tests
8
- render_template_occurrences = get_render_template_occurrences(@action_controller_controller_sm_model)
9
- if render_template_occurrences.present?
10
- generate_render_template_matcher_tests(render_template_occurrences)
11
- else
12
- []
13
- end
14
- end
15
-
16
-
17
- private
18
-
19
- def generate_render_template_matcher_tests(render_template_occurrences)
20
- render_template_tests = []
21
- render_template_occurrences.sort_by!{ |render_template| [render_template[:view_action], render_template[:view_action_http_method]] }
22
- render_template_occurrences.each do |render_template|
23
- render_template_test = " describe '#{ render_template[:view_action_http_method] } ##{ render_template[:view_action] }' do\n"
24
- render_template_test.concat(" before { #{ render_template[:view_action_http_method].downcase } :#{ render_template[:view_action] } }\n\n")
25
- render_template_test.concat(" it { is_expected.to render_template('#{ render_template[:view_action] }') }\n")
26
- render_template[:view_action_render_occurrences].sort_by!{ |render_occurrence| [render_occurrence[:render_view_type], render_occurrence[:render_view]] }
27
- render_template[:view_action_render_occurrences].each do |render_occurrence|
28
- if render_occurrence[:render_view_type] == "partial" && render_occurrence[:render_view].include?("/") ||
29
- render_occurrence[:render_view_type] == "file"
30
- render_template_test.concat(" it { is_expected.to render_template(#{ render_occurrence[:render_view_type] }: '")
31
- elsif render_occurrence[:render_view_type] == "partial"
32
- render_template_test.concat(" it { is_expected.to render_template(#{ render_occurrence[:render_view_type] }: '_")
33
- elsif render_occurrence[:render_view_type] == "unknown"
34
- render_template_test.concat(" # Unknown view type. Remove 'x' from 'xit' once view type identified (e.g. 'partial:', 'file:', etc.)\n")
35
- render_template_test.concat(" xit { is_expected.to render_template('")
36
- else
37
- render_template_test.concat(" it { is_expected.to render_template('")
38
- end
39
- render_template_test.concat("#{ render_occurrence[:render_view] }') }\n")
40
- end
41
- render_template_test.concat(" end")
42
- render_template_tests << render_template_test
43
- end
44
- render_template_tests = properly_line_space_tests(render_template_tests)
45
- render_template_tests.flatten.compact.uniq.join("\n")
46
- end
47
-
48
-
49
- def get_render_template_occurrences(controller)
50
- render_template_occurrences = []
51
- app_views_path = Rails.root.join("app", "views").to_s + "/"
52
- controller_views_path = app_views_path + controller.underscore.sub(/_controller$/, "/")
53
- %w(erb haml slim).each do |view_file_format|
54
- render_template_occurrences = render_template_occurrences + get_render_template_occurrences_by_file_type(app_views_path, controller_views_path, view_file_format)
55
- end
56
- render_template_occurrences
57
- end
58
-
59
- def get_render_template_occurrences_by_file_type(app_views_path, controller_views_path, view_file_format)
60
- render_template_occurrences_by_file_type = []
61
- Dir.glob(controller_views_path + "**/*.html." + view_file_format) do |view_file_path|
62
- view_action_render_occurrences = []
63
- File.open(view_file_path, 'r') do |view_file|
64
- view_file.each_line do |line|
65
- if line =~ /(?:\s+render|=render)(?:\s+action:\s+|\s+:action\s+=\>\s+|\s+file:\s+|\s+:file\s+=\>\s+|\s+partial:\s+|\s+:partial\s+=\>\s+|\s+template:\s+|\s+:template\s+=\>\s+|\s+)["':][A-Za-z0-9_\/\.]+"*'*\s*$/
66
- render_view_type, render_view_path = line.match(/(?:\s+render|=render)(\s+action:\s+|\s+:action\s+=\>\s+|\s+file:\s+|\s+:file\s+=\>\s+|\s+partial:\s+|\s+:partial\s+=\>\s+|\s+template:\s+|\s+:template\s+=\>\s+|\s+)["':]([A-Za-z0-9_\/\.]+)/).captures
67
- if render_view_type.present?
68
- render_view_type = render_view_type.gsub(/\s+/,"").gsub(":", "").gsub("=>","")
69
- else
70
- render_view_type = get_render_view_type(app_views_path, view_file_path, render_view_path)
71
- end
72
- view_action_render_occurrence = { render_view_type: render_view_type, render_view: render_view_path }
73
- view_action_render_occurrences << view_action_render_occurrence
74
- end
75
- end
76
- end
77
- if view_action_render_occurrences.present?
78
- view_action = get_view_from_path(view_file_path).sub(".html." + view_file_format, "")
79
- if render_template_containing_method_is_action(controller, view_action)
80
- route_controller = controller.underscore.sub(/_controller$/, "")
81
- view_action_route = Rails.application.routes.set.select { |route| route.defaults[:controller] == route_controller && route.defaults[:action] == view_action }
82
- view_action_http_method = view_action_route.first.constraints[:request_method].to_s.gsub("(?-mix:^","").gsub("$)","")
83
- render_template_occurrence = { view_action: view_action, view_action_http_method: view_action_http_method, view_action_render_occurrences: view_action_render_occurrences }
84
- render_template_occurrences_by_file_type << render_template_occurrence
85
- end
86
- end
87
- end
88
- render_template_occurrences_by_file_type
89
- end
90
-
91
- def get_render_view_type(app_views_path, view_file_path, render_view_path)
92
- render_view_and_directory = get_internal_render_view_and_directory(app_views_path, view_file_path, render_view_path)
93
- render_view_type = identify_internal_render_view_type(render_view_and_directory, app_views_path)
94
- if render_view_type == "unknown" && render_view_path.include?("/")
95
- render_view_and_directory = get_external_render_view_and_directory(render_view_path)
96
- render_view_type = identify_external_render_view_type(render_view_and_directory)
97
- end
98
- render_view_type
99
- end
100
-
101
- def get_internal_render_view_and_directory(app_views_path, view_file_path, render_view_path)
102
- if render_view_path.include?("/")
103
- render_view_directory = get_view_directory_prepended(render_view_path,app_views_path)
104
- render_view = get_view_from_path(render_view_path).sub(/^\s*_/,"")
105
- else
106
- render_view_directory = get_view_directory_from_path(view_file_path)
107
- render_view = render_view_path.sub(/^\s*_/,"")
108
- end
109
- { directory: render_view_directory, view: render_view }
110
- end
111
-
112
-
113
- def get_external_render_view_and_directory(render_view_path)
114
- render_view_directory = get_view_directory_from_path(render_view_path)
115
- render_view = get_view_from_path(render_view_path)
116
- { directory: render_view_directory, view: render_view }
117
- end
118
-
119
-
120
- def get_view_from_path(view_path)
121
- view_path.scan(/\/([a-zA-z0-9.]+)$/).last.first
122
- end
123
-
124
-
125
- def get_view_directory_from_path(view_path)
126
- view_path.sub(/\/[a-zA-z0-9.]+$/,"/")
127
- end
128
-
129
-
130
- def get_view_directory_prepended(view_path, prepend_path)
131
- view_path.sub(/\/[a-zA-z0-9.]+$/,"/").prepend(prepend_path)
132
- end
133
-
134
-
135
- def identify_internal_render_view_type(render_view_and_directory, app_views_path)
136
- render_view_type = "unknown"
137
- if view_partial_exist(render_view_and_directory)
138
- render_view_type = "partial"
139
- elsif view_exist(render_view_and_directory)
140
- render_view_controller_name = get_controller_name_from_view_directory_path(render_view_and_directory[:directory], app_views_path)
141
- if render_view_controller_name.present? && render_template_containing_method_is_action(render_view_controller_name, render_view_and_directory[:view])
142
- render_view_type = "action"
143
- else
144
- render_view_type = "template"
145
- end
146
- end
147
- render_view_type
148
- end
149
-
150
-
151
- def identify_external_render_view_type(render_view_and_directory)
152
- render_view_type = "unknown"
153
- if view_partial_exist(render_view_and_directory) || view_exist(render_view_and_directory)
154
- render_view_type = "file"
155
- end
156
- render_view_type
157
- end
158
-
159
-
160
- def view_exist(render_view_and_directory)
161
- File.exist?(render_view_and_directory[:directory] + render_view_and_directory[:view] + ".html.erb") ||
162
- File.exist?(render_view_and_directory[:directory] + render_view_and_directory[:view] + ".html.haml") ||
163
- File.exist?(render_view_and_directory[:directory] + render_view_and_directory[:view] + ".html.slim")
164
- end
165
-
166
-
167
- def view_partial_exist(render_view_and_directory)
168
- File.exist?(render_view_and_directory[:directory] + "_" + render_view_and_directory[:view] + ".html.erb") ||
169
- File.exist?(render_view_and_directory[:directory] + "_" + render_view_and_directory[:view] + ".html.haml") ||
170
- File.exist?(render_view_and_directory[:directory] + "_" + render_view_and_directory[:view] + ".html.slim")
171
- end
172
-
173
-
174
- def get_controller_name_from_view_directory_path(view_directory_path, app_views_path)
175
- view_directory_path.sub(app_views_path, "").sub(/\/$/,"").concat("_controller").camelize
176
- end
177
-
178
-
179
- def render_template_containing_method_is_action(controller, action_candidate)
180
- controller.constantize.instance_methods(false).include?(action_candidate.to_sym)
181
- end
182
-
183
-
184
- end
185
- end
186
- end
187
- end
188
- end
@@ -1,20 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Controller
3
- module ActionController
4
- module ActionControllerMatcher
5
- module UseAroundAction
6
-
7
- def use_around_action_matcher_tests
8
- around_action_tests = []
9
- around_actions.map do |action|
10
- around_action_test = " it { is_expected.to use_around_action(#{ action }) }"
11
- around_action_tests << [around_action_test]
12
- end
13
- around_action_tests.flatten.compact.uniq.join("\n")
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Controller
3
- module ActionController
4
- module ActionControllerMatcher
5
- module UseBeforeAction
6
-
7
- def use_before_action_matcher_tests
8
- before_action_tests = []
9
- before_actions.map do |action|
10
- before_action_test = " it { is_expected.to use_before_action(#{ action }) }"
11
- before_action_tests << [before_action_test]
12
- end
13
- before_action_tests.flatten.compact.uniq.join("\n")
14
- end
15
-
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,16 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveModelMatcher
5
- module ValidateAbsenceOf
6
-
7
- def validate_absence_of_matcher_tests
8
- absence_validators = extract_validators(@active_record_model_sm_model, ::ActiveModel::Validations::AbsenceValidator).flatten
9
- generate_validator_matcher_tests(absence_validators)
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveModelMatcher
5
- module ValidateAcceptanceOf
6
-
7
- def validate_acceptance_of_matcher_tests
8
- acceptance_validators = extract_validators(@active_record_model_sm_model, ::ActiveModel::Validations::AcceptanceValidator).flatten
9
- generate_validator_matcher_tests(acceptance_validators)
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveModelMatcher
5
- module ValidateConfirmationOf
6
-
7
- def validate_confirmation_of_matcher_tests
8
- confirmation_validators = extract_validators(@active_record_model_sm_model, ::ActiveModel::Validations::ConfirmationValidator).flatten
9
- generate_validator_matcher_tests(confirmation_validators)
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,145 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module Matchmaker
5
- module ValidateExclusionOf
6
-
7
-
8
- def validate_exclusion_of_matcher_tests
9
- exclusion_validators = extract_validators(@active_record_model_sm_model, ::ActiveModel::Validations::ExclusionValidator).flatten
10
- if exclusion_validators.present?
11
- generate_exclusion_validator_matcher_tests(exclusion_validators)
12
- else
13
- []
14
- end
15
- end
16
-
17
-
18
- private
19
-
20
- def generate_exclusion_validator_matcher_tests(exclusion_validators)
21
- exclusion_tests = []
22
- exclusion_validators.map do |exclusion_validator|
23
- if conditional_options_exist(exclusion_validator.options)
24
- exclusion_tests = exclusion_tests + generate_exclusion_conditional_tests(exclusion_validator)
25
- else
26
- exclusion_tests << generate_exclusion_test(exclusion_validator, exclusion_validator.options)
27
- end
28
- end
29
- exclusion_tests = properly_line_space_tests(exclusion_tests)
30
- exclusion_tests.flatten.compact.uniq.join("\n")
31
- end
32
-
33
- def generate_exclusion_test(exclusion_validator, exclusion_options)
34
- exclusion_test = get_exclusion_test_core(exclusion_options, exclusion_validator.attributes[0])
35
- exclusion_options_string = get_options_string(exclusion_options)
36
- exclusion_options_string = exclusion_options_string.gsub(".", ".\n ")
37
- exclusion_test.concat(exclusion_options_string + "\n end")
38
- exclusion_test
39
- end
40
-
41
- def generate_exclusion_conditional_tests(exclusion_validator)
42
- exclusion_conditional_tests = []
43
- exclusion_options = parse_validator_options(exclusion_validator.options.dup)
44
- if all_option_values_are_symbols(exclusion_options[:if_option_values]) &&
45
- all_option_values_are_symbols(exclusion_options[:unless_option_values])
46
- exclusion_conditional_tests << generate_exclusion_validating_test(exclusion_validator, exclusion_options[:non_conditional_options])
47
- exclusion_conditional_tests = exclusion_conditional_tests + generate_exclusion_non_validating_tests(exclusion_validator, exclusion_options[:non_conditional_options])
48
- # else
49
- # Skip tests due to non-symbol conditions (see below)
50
- end
51
- exclusion_conditional_tests
52
- end
53
-
54
- def generate_exclusion_validating_test(exclusion_validator, exclusion_options)
55
- exclusion_validating_test = compose_conditional_validating_context_string(exclusion_options)
56
- validating_permutation = get_validating_true_false_permutation(exclusion_options)
57
- exclusion_validating_test.concat(compose_conditional_before_strings(exclusion_options, validating_permutation))
58
- validating_test = generate_exclusion_test(exclusion_validator, exclusion_options[:non_conditional_options])
59
- validating_test = adjust_conditional_test_indentation(validating_test)
60
- exclusion_validating_test.concat(validating_test + "\n end")
61
- end
62
-
63
- def generate_exclusion_non_validating_tests(exclusion_validator, exclusion_options)
64
- exclusion_non_validating_tests = []
65
- possible_conditional_permutations = get_possible_true_false_permutations(exclusion_options)
66
- validating_permutation = get_validating_true_false_permutation(exclusion_options)
67
- non_validating_permutations = possible_conditional_permutations - [validating_permutation]
68
- non_validating_permutations.each do |non_validating_permutation|
69
- exclusion_non_validating_test = generate_exclusion_non_validating_test(exclusion_validator, exclusion_options, non_validating_permutation)
70
- exclusion_non_validating_tests << exclusion_non_validating_test
71
- end
72
- exclusion_non_validating_tests[0] = exclusion_non_validating_tests[0].prepend("#\n# For more natural readability of 'is_expected.not_to' context lines, 'unless' is represented by 'if not'\n# and 'unless not' is represented by 'if'.\n#\n")
73
- exclusion_non_validating_tests
74
- end
75
-
76
- def generate_exclusion_non_validating_test(exclusion_validator, exclusion_options, non_validating_permutation)
77
- exclusion_non_validating_test = compose_conditional_non_validating_context_string(exclusion_options, non_validating_permutation)
78
- exclusion_non_validating_test.concat(compose_conditional_before_strings(exclusion_options, non_validating_permutation))
79
- non_validating_test = generate_exclusion_test(exclusion_validator, exclusion_options[:non_conditional_options])
80
- non_validating_test.sub!("is_expected.to","is_expected.not_to")
81
- non_validating_test = adjust_conditional_test_indentation(non_validating_test)
82
- exclusion_non_validating_test.concat(non_validating_test)
83
- exclusion_non_validating_test.concat("\n end")
84
- end
85
-
86
- def get_exclusion_test_core(validator_options, validator_attribute)
87
- exclusion_enumerable = validator_options[:in] || validator_options[:within]
88
- if exclusion_enumerable.is_a?(Array)
89
- " it do\n is_expected.to validate_exclusion_of(:#{ validator_attribute }).\n in_array(#{ exclusion_enumerable })"
90
- elsif exclusion_enumerable.is_a?(Range)
91
- " it do\n is_expected.to validate_exclusion_of(:#{ validator_attribute }).\n in_range(#{ exclusion_enumerable })"
92
- elsif exclusion_enumerable.lambda?
93
- " #\n # Note: Your 'in:/within:' configuration option value is a 'Lambda'\n" +
94
- " # You will need to implement a customized test.\n" +
95
- " it do\n skip(\"Remove this skip line once test customization has been implemented.\")\n is_expected.to validate_exclusion_of(:#{ validator_attribute })"
96
- # CONFIRMATION TODO: Confirm whether or not exclusion_enumerable could be a 'Proc' that isn't a 'lambda'
97
- elsif exclusion_enumerable.respond_to?(:call)
98
- " #\n # Note: Your 'in:/within:' configuration option value is a 'Proc'\n" +
99
- " # You will need to implement a customized test.\n" +
100
- " it do\n skip(\"Remove this skip line once test customization has been implemented.\")\n is_expected.to validate_exclusion_of(:#{ validator_attribute })"
101
- else
102
- " #\n # Alert: Invalid 'in:/within:' enumerable object type: '#{ exclusion_enumerable.class.to_s }'\n" +
103
- " # Valid exclusion 'in:/within:' enumerable object types: 'Array', 'Range'\n" +
104
- " # (or a proc, lambda or symbol which returns an enumerable)\n" +
105
- " it do\n skip(\"Remove this skip line once valid enumerable object type is provided.\")\n is_expected.to validate_exclusion_of(:#{ validator_attribute })"
106
- end
107
- end
108
-
109
-
110
- # def get_exclusion_test_options(options)
111
- # exclusion_test_options = ""
112
- # options.map do |option, option_value|
113
- # exclusion_test_option = get_exclusion_test_option(option, option_value)
114
- # exclusion_test_options.concat(".\n " + exclusion_test_option) if exclusion_test_option.present?
115
- # end
116
- # exclusion_test_options
117
- # end
118
- #
119
- # def get_exclusion_test_option(option, option_value)
120
- # case option
121
- # # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
122
- # # when :allow_blank
123
- # # "allow_blank"
124
- # # IMPLEMENTATION TODO: Determine if 'allow_nil' is a valid option
125
- # # when :allow_nil
126
- # # "allow_nil"
127
- # when :message
128
- # if option_value.include? '"'
129
- # "with_message('#{ option_value }')"
130
- # else
131
- # "with_message(\"#{ option_value }\")"
132
- # end
133
- # when :on
134
- # "on(:#{ option_value })"
135
- # else
136
- # # IMPLEMENTATION TODO: Possibly handle as an error or modify evaluation of option
137
- # ""
138
- # end
139
- # end
140
-
141
- end
142
- end
143
- end
144
- end
145
- end
@@ -1,94 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module Matchmaker
5
- module ValidateInclusionOf
6
-
7
-
8
- def validate_inclusion_of_matcher_tests
9
- inclusion_tests = []
10
- extract_validators(@active_record_model_sm_model, ::ActiveModel::Validations::InclusionValidator).flatten.map do |validator|
11
- validator_options = validator.options.dup
12
- validator_if_option = validator_options.delete(:if)
13
- validator_unless_option = validator_options.delete(:unless)
14
- validator.attributes.map do |attribute|
15
- inclusion_tests << generate_inclusion_test_multiple_lines(validator_options, attribute)
16
- end
17
- end
18
- inclusion_tests.flatten.compact.uniq.join("\n\n")
19
- end
20
-
21
-
22
- private
23
-
24
- def generate_inclusion_test_multiple_lines(validator_options, attribute)
25
- inclusion_test = get_inclusion_test_core(validator_options, attribute)
26
- inclusion_test_options = get_inclusion_test_options(validator_options)
27
- inclusion_test.concat(inclusion_test_options) if inclusion_test_options.present?
28
- inclusion_test.concat("\n end")
29
- [inclusion_test]
30
- end
31
-
32
-
33
- def get_inclusion_test_core(validator_options, attribute)
34
- inclusion_enumerable = validator_options[:in] || validator_options[:within]
35
- if inclusion_enumerable.is_a?(Array)
36
- " it do\n is_expected.to validate_inclusion_of(:#{ attribute }).\n in_array(#{ inclusion_enumerable })"
37
- elsif inclusion_enumerable.is_a?(Range)
38
- " it do\n is_expected.to validate_inclusion_of(:#{ attribute }).\n in_range(#{ inclusion_enumerable })"
39
- elsif inclusion_enumerable.lambda?
40
- " #\n # Note: Your 'in:/within:' configuration option value is a 'Lambda'\n" +
41
- " # You will need to implement a customized test.\n" +
42
- " it do\n skip(\"Remove this skip line once test customization has been implemented.\")\n is_expected.to validate_inclusion_of(:#{ attribute })"
43
- # CONFIRMATION TODO: Confirm whether or not inclusion_enumerable could be a 'Proc' that isn't a 'lambda'
44
- elsif inclusion_enumerable.respond_to?(:call)
45
- " #\n # Note: Your 'in:/within:' configuration option value is a 'Proc'\n" +
46
- " # You will need to implement a customized test.\n" +
47
- " it do\n skip(\"Remove this skip line once test customization has been implemented.\")\n is_expected.to validate_inclusion_of(:#{ attribute })"
48
- else
49
- " #\n # Alert: Invalid 'in:/within:' enumerable object type: '#{ inclusion_enumerable.class.to_s }'\n" +
50
- " # Valid inclusion 'in:/within:' enumerable object types: 'Array', 'Range'\n" +
51
- " # (or a proc, lambda or symbol which returns an enumerable)\n" +
52
- " it do\n skip(\"Remove this skip line once valid enumerable object type is provided.\")\n is_expected.to validate_inclusion_of(:#{ attribute })"
53
- end
54
- end
55
-
56
-
57
- def get_inclusion_test_options(options)
58
- inclusion_test_options = ""
59
- options.map do |option, option_value|
60
- inclusion_test_option = get_inclusion_test_option(option, option_value)
61
- inclusion_test_options.concat(".\n " + inclusion_test_option) if inclusion_test_option.present?
62
- end
63
- inclusion_test_options
64
- end
65
-
66
-
67
- def get_inclusion_test_option(option, option_value)
68
- # IMPLEMENTATION TODO: Determine if it is possible to implement 'with_low_message' and 'with_high_message'
69
- case option
70
- # IMPLEMENTATION TODO: Determine if 'allow_blank' is a valid option
71
- # when :allow_blank
72
- # "allow_blank"
73
- # IMPLEMENTATION TODO: Determine if 'allow_nil' is a valid option
74
- # when :allow_nil
75
- # "allow_nil"
76
- when :message
77
- if option_value.include? '"'
78
- "with_message('#{ option_value }')"
79
- else
80
- "with_message(\"#{ option_value }\")"
81
- end
82
- when :on
83
- "on(:#{ option_value })"
84
- else
85
- # IMPLEMENTATION TODO: Possibly handle as an error or modify evaluation of option
86
- ""
87
- end
88
- end
89
-
90
- end
91
- end
92
- end
93
- end
94
- end