shoulda_matchmakers 0.1.0 → 0.1.1

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 (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
@@ -153,17 +153,3 @@ module ShouldaMatchmakers
153
153
  end
154
154
  end
155
155
  end
156
-
157
- # else
158
- # Skip tests due to non-symbol conditions (see below)
159
- # validator.attributes.map do |attribute|
160
- # skip = true
161
- # presence_test = generate_presence_test_single_line(validator_options, attribute, skip)
162
- # if presence_test[0].length > 100 || validator_options.count > 1
163
- # presence_test = generate_presence_test_multiple_lines(validator_options, attribute, skip)
164
- # end
165
- # presence_test_comment = " # This test is currently skipped due to if: and/or unless: conditions that aren't symbols.\n"
166
- # presence_test_comment.concat(" # Provide ")
167
- # presence_test.prepend(presence_test_comment)
168
- # presence_tests << presence_test
169
- # end
@@ -1,3 +1,3 @@
1
1
  module ShouldaMatchmakers
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -42,13 +42,7 @@ module ShouldaMatchmakers
42
42
  " then the controllers in the arguments list of this option are applied.\n\n\n"
43
43
 
44
44
  def create_controller_matchmakers
45
-
46
45
  generator_options = options.to_hash
47
-
48
- # TRACE.debug ""
49
- # TRACE.debug " GENERATOR OPTIONS:"
50
- # TRACE.debug generator_options.inspect
51
-
52
46
  load_application
53
47
  generate_controller_matchmakers(generator_options)
54
48
  end
@@ -61,15 +55,11 @@ module ShouldaMatchmakers
61
55
  app_action_controller_descendants_names = load_action_controller_controller_names
62
56
  if app_action_controller_descendants_names.present?
63
57
  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
58
  selected_action_controller_controller_names.each do |controller_name|
69
59
  save_generate(controller_name) do
70
- @action_controller_controller_sm_model = ::ShouldaMatchmakers::Controller::ActionController::ActionControllerController.new(controller_name)
60
+ @action_controller_controller_sm_model = ::ShouldaMatchmakers::Controller::ActionController::ActionControllerController.new(controller_name)
71
61
  template_filename = File.expand_path('vendor/shoulda_matchmakers/lib/templates/controller/action_controller/controller_spec_template.haml')
72
- template = File.read(template_filename)
62
+ template = File.read(template_filename)
73
63
  create_file "#{ ShouldaMatchmakers.configuration.controllers_test_path }/#{ controller_name.underscore }_spec.rb",
74
64
  Haml::Engine.new(template, filename: template_filename, format: :html5).to_html(binding)
75
65
  end
@@ -141,58 +131,16 @@ module ShouldaMatchmakers
141
131
  def select_controller_names_config(app_action_controller_descendants_names)
142
132
  controller_names_config_included = ShouldaMatchmakers.configuration.models_included
143
133
  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
134
  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
135
  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
136
  selected_controller_names_config
164
137
  elsif controller_names_config_excluded.present?
165
138
  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
139
  selected_controller_names_config
171
140
  else
172
-
173
- # TRACE.debug " NO CONTROLLERS INCLUDED OR EXCLUDED:"
174
- # TRACE.debug app_action_controller_descendants_names.map.inspect
175
-
176
141
  app_action_controller_descendants_names.map.uniq.sort
177
142
  end
178
143
  end
179
144
 
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
145
  end
198
146
  end
@@ -97,7 +97,7 @@ if defined?(ShouldaMatchmakers) && Rails.env.test?
97
97
  # Preferred length of generated code lines
98
98
  # Wherever possible, generated code lines will be broken into multiple lines to keep lines under
99
99
  # your preferred length.
100
- # The default value is '100' characters.
100
+ # The default value is '120' characters.
101
101
  #
102
102
  # Note: Due to the fact that tests and factories are generated dynamically, lead spacing/tabbing
103
103
  # for each generated line of code is difficult to predict. Therefore, your preferred line length
@@ -105,7 +105,7 @@ if defined?(ShouldaMatchmakers) && Rails.env.test?
105
105
  # there is an inability to break a line further, either due to syntax rules or for the preservation
106
106
  # of readability. If line length is critical, account for this variation in the value you choose.
107
107
  #
108
- # config.preferred_generated_code_line_length = 100
108
+ # config.preferred_generated_code_line_length = 120
109
109
 
110
110
  end
111
111
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda_matchmakers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Edwards
@@ -208,30 +208,6 @@ files:
208
208
  - lib/shoulda_matchmakers/version.rb
209
209
  - lib/support/command_line_interface.rb
210
210
  - lib/support/controller_generator.rb
211
- - lib/support/indefinite_article.rb
212
- - lib/support/to_discard/belong_to.rb
213
- - lib/support/to_discard/have_and_belong_to_many.rb
214
- - lib/support/to_discard/have_many.rb
215
- - lib/support/to_discard/have_one.rb
216
- - lib/support/to_discard/permit_refactor.rb
217
- - lib/support/to_discard/render_template_new.rb
218
- - lib/support/to_discard/render_template_reconstruction.rb
219
- - lib/support/to_discard/use_around_action.rb
220
- - lib/support/to_discard/use_before_action.rb
221
- - lib/support/to_discard/validate_absence_of.rb
222
- - lib/support/to_discard/validate_acceptance_of.rb
223
- - lib/support/to_discard/validate_confirmation_of.rb
224
- - lib/support/to_discard/validate_exclusion_of.rb
225
- - lib/support/to_discard/validate_inclusion_of.rb
226
- - lib/support/to_discard/validate_length_of.rb
227
- - lib/support/to_discard/validate_numericality_of.rb
228
- - lib/support/to_discard/validate_presence_of.rb
229
- - lib/support/to_discard/validate_uniqueness_of.rb
230
- - lib/support/to_discard/validation_old.rb
231
- - lib/support/to_discard/validations.rb
232
- - lib/support/to_discard/validations_conditional.rb
233
- - lib/support/trace_debug_lines.txt
234
- - lib/support/util.rb
235
211
  - lib/templates/controller/action_controller/controller_spec_template.haml
236
212
  - lib/templates/factory/active_record/factory_template.haml
237
213
  - lib/templates/model/active_record/model_spec_template.haml
@@ -1,70 +0,0 @@
1
- module ShouldaMatchmakers
2
-
3
- # Source: https://gist.github.com/michaelglass/7905878
4
- # A vs An ported to ruby from: http://home.nerbonne.org/A-vs-An/
5
-
6
- # encoding: UTF-8
7
- # by Eamon Nerbonne (from http://home.nerbonne.org/A-vs-An), Apache 2.0 license
8
- class IndefiniteArticle
9
- # Usage example: IndefiniteArticle.for("example ")
10
- # example returns: "an"
11
- # Note that the terminal space indicates this is a complete word - this is sometimes significant, particularly for acronyms!
12
- DICT = "]08[09[0-11[0-4[0-4 ]0-6-[0-8[11[110]111]112]113]114]115]116]117]118]119]11.4]18[180]1800[1801[1802[1803[1804[1805[1806[1807[1808[1809[181-]181 ]182-]182 ]183-]183 ]184-]184 ]185-]185 ]186-]186 ]187-]187 ]188-]188 ]189-]189 ]8[800x]890]8,1]8,2]–i[#i[$11 [$11.[$18 [$18,[$18.[$8[&a[&o[*a[*e[*i[.av[.mp[.og[/a[/e[/h[/i[/l[/s/[@[`a[£8[∞[a[a ]abou]about-[agai]al-I]algu]alth]amon]an ]and]and\"[anda[ande[andr[anot]anyw]apart ]appears]apre]are ]are:]artí]A[A$]AAA]Akiz]Amar\"]Andaluc]Armat]Asturias]Athl]Athleti[Athlo[AU$]AUD]AUSC]Á[á[à[Ä[ā[Å[æ[Æ[Æn]Bhai[Bhá[Buddhism[contains[Chais[County,[das [dem [der [describes[Dinas[Diver-[Dún]e[e.g]each ]either ]either.]el-]ella]empez]enoug]eu]eup [ew]exists]E[Empez]Enam]Esp]Espad[Espe[Espo[Eu]Eul[EUR]é[ég]ét]éta[étu[É[f-[f [f\"[f/[fM[fp[ft[F0[F1[F2[F3[F4[F5[F6[F9[F'[F-[F [F\"[F#[F,[F.[F/[F”[FA[FAC]FAD]FAIR]FAL]FAM]FAN]FAP]FAQ]FAR]FAS]FAT]FB[FC[Fc[FD[FEC[FEI[FF[FF ]Ff[Fh[FH[FIA[FIAT]FID [FIR [FIS [FK[FLC[FLN[FLP[FM[FMR]FO [FOI [FP[FP.]FP?]FPC?]FRC[FRS[FS[FT[FTS]FTT]FU [FU,[FU.[FV[FW[FWD]FX[FY[Fσ[Ghae[Ghai[h'[h-[h-U]h [h\"[h,[hC[heir[heira]hims[historic\"[historic\" ]homa[homm[hon[honey]honk]honv]hors [hour[ht[htt]http [H1[H2[H3[H4[H5[H'[H-[H [H\"[H&[H,[H.[H.A]H+[Habilitations[HB[HC[HD[HDB]Heir[HF[HG[HH[HI[HID]HIG]HIM]HIP]HL[HLA-D]HM[HN[Hon[Hond]Hone]Hones[Hong]Honk]Honol]Hour[HO [HOV[HP[HQ[HR[HRT]HS[HS ]HSR]HST]HT[HTP]HV[HWT[i[i.e]ibn]if ]ii]includi]indicates]instea]instead?[is ]is.]it ]iu]I[I-A]I-I]III]Ilb]IMH]Imams]IR£]Islam ]Islam,]Islam.]Islands]İ[Jia[Jian]ku [l [l\"[lp[L1[L2[L3[L5[L'[L'A]L-[L-a]L [L\"[L&[L,[L.[L/[Lae[Laoig[LA [LAL[LAP[LB[LC[LD[LE[LEA]LEE]LEG]LEO]LEP]LET]LF[LG[LH[LIR[LL[LM[LMX]LN[Locha[LOE[LP[LR[LS[LT[LU [LV[LX[LZ[m-[m [m\"[m&[m×[makes [mb[mein[mentions[mf[mp[mR[mt[M1[M19]M190[M2[M3[M4[M5[M6[M7[M8[M9[M'[M-[M-t]M [M\"[M&[M,[M.[M.A.S]M/[MA[MAC]MAD]MAF]MAG]MAJ]MAL]MAM]MAN]MAP]MAR]MAS]MAT]MAX]MAY]MB[MC[MD[Me-[MEd[MEn[MEP[MF[Mf[MG[MH[Mh[Mie[MI5[MI6[MI [MIA[MIT[MK[ML[MM[MMT]MN[MoU[MO [MOT [MOU[MP[MR[MS[Msc[MT[MTR]MUV[MV[MX[N4[N6[N'[N-[N-a]N-S]N [N\"[N,[N.[N.Y]N=[N²[Nao[NA [NAA[NAAF]NAI[NASL[NB[NC[ND[NEA[NEH[NES [NF[NG[NH[NI[NIC]NIL]NIM]NIMH[NIN]NIS]NJC[NK[NL[NLS]NM[NNR[NNT[NP[NPO]NPOV-[NR[NRJ]NRT]NS[NSW]NT[NT$]NUS[NV[Nv[NWA[NX[NYP[NYU[n-[n−[n [n\"[n&[n,[n+[n×[nda[npa[nt[nV[nW[o[obr]occurs]ocho]of ]on]on-[on/[onb[onco[ond[oner[ong[oni[onl[onm[ono[onr[ons[ont[onu[onw[ony[or ]or,]oui]O[Obers]Oberst [Oberstl[Olv]One]Onei[ONE]Oop]Oui]Ó[Ö[ö[Ō[ō[Phob[Phoi[r'[r-[r [r\"[r&[r.[refers[rf[rm[rs[R1[R10]R2[R3[R4[R5[R6[R'[R-[R [R\"[R&[R,[R.[R.C]R/[RA [RAF[RB[RC[RD[RE [RER[RF[Rf[RG[RHS[RIA[RIC [RJ[RK[RL[RL ]RM[RM1]RN[RNG]ROT[RP[RQ[RR[RS[RS ]RS)]RS,]RS.]RS?]RST]RT[RU[RV[RX[s-[s\"[s)[s,[s.[says[sich[sp3[sprot[ssh[states [states:[sv[sva]sve]S1[S2[S3[S4[S5[S6[S'[S-[S [S\"[S&[S&W]S,[S.B[S.M[S.O[S”[SA-[SA-1]SA [SACD[SAE[SAS[SASE]SAT [SATB[SB[SCA [SCC[SCM[SCO [SCR[SCRA]SCT[SD[SE [SEC[SECO]SECR]SEI[SEO[SF[SG[SH2[SH3[SH-[SI [SJ[SK[SL[SLA]SLI]SLO]SM[SMA]SME]SME [SMI]SN[SNA]SNE]SNO]SO([SOA [SOAI[SOE[SOI[SOS[SOV[SP[SPAC]SPAD]SPAM]SPAN]SPAR]SPE]SPE [SPIC]SPO]SPU]SR[SS[ST-[STA [STB[STC[STD[STF[STL[STM[STS[STV[Sura [SU[SUB]SUL]SUN]SUP]SUS]SV[SWF[SWP[SWR[SX[SXS]t-S[than [tS[Taves[Tà[u[u-]u ]u\"]u.]ub]ube[uf]uk]uka[ulu]um ]un ]una ]unan]unana[unann[unans[unant[unary]une ]uni]unicorp[unid[unidi]unim[unimo]unin[unintentionall]unintentionally [univo[unles]until ]upo]ura]ure]uri]url]uro]us]us-[us [ush[ut]utm[utt[uv]uw]U1[U-21[U-23 [U-B[U-Bo]Ua[Ub[Ubi]UDP-[Ud[Ugl[Uh[Ui[Ul[Uli]Um[UMN[Un-[Una[Unan]Unb[Unc[Und[Une[Unes]Unf[Ung[Unh[Unid[Unin[Unk[Unl[Unm[Unn[Uno[Unp[Unr[Uns[Unt[Unters]Unu[Unw[Up[Ur[Ura]Uri]Uru]Uruguayan-[Uruk[Ush[Ust[Utn[Uto-[Utr[Utt[Ux[Uz[ü[Ü[verses[Valley,[VII[WikiEl[x[xa]xe]xi]xo]xx]xy]X[Xa]XA]Xe]Xh]Xi]Xiany[XIV]XIX]Xo]Xu]XU]XV]XX]XX [Xy]Yp[Zen)[α[ε[ω[西[長["
13
-
14
- @root = {}
15
- DICT.gsub /([^\[\]]*)([\[\]])/ do |match|
16
- m = /([^\[\]]*)([\[\]])/.match match
17
- prefix = m[1]
18
- aVsAn = m[2] # a is closing bracket, an is opening.
19
- node = @root
20
- prefix.each_char do |letter|
21
- node[letter] ||= {}
22
- node = node[letter]
23
- end
24
-
25
- node[:article] = aVsAn == "]" ? "a" : "an"
26
- end
27
-
28
- def self.for(word)
29
- node = @root
30
- article = node[:article]
31
- sI = 0
32
-
33
- while true
34
- if sI >= word.size
35
- return article
36
- elsif word[sI] === "(" || word[sI] === "'" || word[sI] === '"'
37
- sI += 1
38
- else
39
- break
40
- end
41
- end
42
-
43
- while true
44
- node = node[word[sI]];
45
- break unless node
46
- article = node[:article] if node[:article]
47
-
48
- sI += 1
49
- if sI >= word.length
50
- node = node[" "]
51
- article = node[:article] if node && node[:article]
52
- break
53
- end
54
- end
55
-
56
- article.dup
57
- end
58
-
59
- def self.correct_sentence(initial_sentence)
60
- initial_sentence.gsub /\b(a|an|A|An)\b(\s)+\b([\w']+)\b/ do |s|
61
- article, space, word = s.split /\b/
62
- new_article = self.for word
63
- new_article.capitalize! if article[0] == 'A'
64
-
65
- "#{new_article}#{space}#{word}"
66
- end
67
- end
68
- end
69
-
70
- end
@@ -1,94 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveRecordMatcher
5
- module BelongTo
6
-
7
- def belong_to_matcher_tests
8
- belong_to_tests = []
9
- @active_record_model_sm_model.constantize.reflect_on_all_associations(:belongs_to).map{ |belong_to| { :association_class_name=>belong_to.name, :association_options=>belong_to.options } }.map do |association|
10
- association_class_name = association[:association_class_name].to_s
11
- association_options = association[:association_options]
12
- belong_to_test = generate_belong_to_test_single_line(association_class_name, association_options)
13
- if belong_to_test[0].length > 80 || association_options.count > 1
14
- belong_to_test = generate_belong_to_test_multiple_lines(association_class_name, association_options)
15
- end
16
- belong_to_tests << belong_to_test
17
- end
18
- belong_to_tests.flatten.compact.uniq.join("\n\n")
19
- end
20
-
21
-
22
- private
23
-
24
- def generate_belong_to_test_single_line(association_class_name, association_options)
25
- belong_to_test = " it { is_expected.to belong_to(:#{ association_class_name })"
26
- association_options.map do |option, option_value|
27
- belong_to_test_option = get_belong_to_test_option(option, option_value)
28
- belong_to_test.concat("." + belong_to_test_option) if belong_to_test_option.present?
29
- end
30
- belong_to_test.concat(" }")
31
- [belong_to_test]
32
- end
33
-
34
-
35
- def generate_belong_to_test_multiple_lines(association_class_name, association_options)
36
- belong_to_test = " it do\n is_expected.to belong_to(:#{ association_class_name })"
37
- belong_to_test_options = get_belong_to_test_options(association_options)
38
- belong_to_test.concat(belong_to_test_options) if belong_to_test_options.present?
39
- belong_to_test.concat("\n end")
40
- [belong_to_test]
41
- end
42
-
43
-
44
- def get_belong_to_test_options(association_options)
45
- belong_to_test_options = ""
46
- association_options.map do |option, option_value|
47
- belong_to_test_option = get_belong_to_test_option(option, option_value)
48
- belong_to_test_options.concat(".\n " + belong_to_test_option) if belong_to_test_option.present?
49
- end
50
- belong_to_test_options
51
- end
52
-
53
-
54
- def get_belong_to_test_option(option, option_value)
55
- # IMPLEMENTATION TODO: Determine if it is possible to implement 'conditions'
56
- case option
57
- when :autosave
58
- "autosave(#{ option_value })"
59
- when :class_name
60
- "class_name('#{ option_value }')"
61
- when :counter_cache
62
- "counter_cache(#{ option_value })"
63
- when :dependent
64
- if option_value.to_s == "true" or option_value.to_s == "false"
65
- "dependent(#{ option_value })"
66
- else
67
- "dependent(:#{ option_value })"
68
- end
69
- when :foreign_key
70
- "with_foreign_key('#{ option_value }')"
71
- when :inverse_of
72
- "inverse_of(:#{ option_value })"
73
- # # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
74
- when :order
75
- if option_value.include? '"'
76
- "order('#{ option_value }')"
77
- else
78
- "order(\"#{ option_value }\")"
79
- end
80
- when :primary_key
81
- "with_primary_key('#{ option_value }')"
82
- when :touch
83
- "touch(#{ option_value })"
84
- else
85
- # IMPLEMENTATION TODO: Possibly handle this case option as an error or modify evaluation of option (see TODO above)
86
- ""
87
- end
88
- end
89
-
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,83 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveRecordMatcher
5
- module HaveAndBelongToMany
6
-
7
-
8
- def have_and_belong_to_many_matcher_tests
9
- habtm_tests = []
10
- @active_record_model_sm_model.constantize.reflect_on_all_associations(:has_and_belongs_to_many).map{ |habtm| { :association_class_name=>habtm.name, :association_options=>habtm.options } }.map do |association|
11
- association_class_name = association[:association_class_name].to_s
12
- association_options = association[:association_options]
13
- habtm_test = generate_habtm_test_single_line(association_class_name, association_options)
14
- if habtm_test[0].length > 80 || association_options.count > 1
15
- habtm_test = generate_habtm_test_multiple_lines(association_class_name, association_options)
16
- end
17
- habtm_tests << habtm_test
18
- end
19
- habtm_tests.flatten.compact.uniq.join("\n\n")
20
- end
21
-
22
-
23
- private
24
-
25
- def generate_habtm_test_single_line(association_class_name, association_options)
26
- habtm_test = " it { is_expected.to have_and_belong_to_many(:#{ association_class_name })"
27
- association_options.map do |option, option_value|
28
- habtm_test_option = get_habtm_test_option(option, option_value)
29
- habtm_test.concat("." + habtm_test_option) if habtm_test_option.present?
30
- end
31
- habtm_test.concat(" }")
32
- [habtm_test]
33
- end
34
-
35
-
36
- def generate_habtm_test_multiple_lines(association_class_name, association_options)
37
- habtm_test = " it do\n is_expected.to have_and_belong_to_many(:#{ association_class_name })"
38
- habtm_test_options = get_habtm_test_options(association_options)
39
- habtm_test.concat(habtm_test_options) if habtm_test_options.present?
40
- habtm_test.concat("\n end")
41
- [habtm_test]
42
- end
43
-
44
-
45
- def get_habtm_test_options(association_options)
46
- habtm_test_options = ""
47
- association_options.map do |option, option_value|
48
- habtm_test_option = get_habtm_test_option(option, option_value)
49
- habtm_test_options.concat(".\n " + habtm_test_option) if habtm_test_option.present?
50
- end
51
- habtm_test_options
52
- end
53
-
54
-
55
- def get_habtm_test_option(option, option_value)
56
- # IMPLEMENTATION TODO: Determine if it is possible to implement 'conditions'
57
- case option
58
- when :autosave
59
- "autosave(#{ option_value })"
60
- when :class_name
61
- "class_name('#{ option_value }')"
62
- when :join_table
63
- "join_table('#{ option_value }')"
64
- # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
65
- when :order
66
- if option_value.include? '"'
67
- "order('#{ option_value }')"
68
- else
69
- "order(\"#{ option_value }\")"
70
- end
71
- when :validate
72
- "validate(#{ option_value })"
73
- else
74
- # IMPLEMENTATION TODO: Possibly handle this case option as an error or modify evaluation of option (see TODO above)
75
- ""
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
82
- end
83
- end
@@ -1,96 +0,0 @@
1
- module ShouldaMatchmakers
2
- module Model
3
- module ActiveRecord
4
- module ActiveRecordMatcher
5
- module HaveMany
6
-
7
- def have_many_matcher_tests
8
- have_many_tests = []
9
- @active_record_model_sm_model.constantize.reflect_on_all_associations(:has_many).map{ |have_many| { :association_class_name=>have_many.name, :association_options=>have_many.options } }.map do |association|
10
- association_class_name = association[:association_class_name].to_s
11
- association_options = association[:association_options]
12
- have_many_test = generate_have_many_test_single_line(association_class_name, association_options)
13
- if have_many_test[0].length > 80 || association_options.count > 1
14
- have_many_test = generate_have_many_test_multiple_lines(association_class_name, association_options)
15
- end
16
- have_many_tests << have_many_test
17
- end
18
- have_many_tests.flatten.compact.uniq.join("\n\n")
19
- end
20
-
21
-
22
- private
23
-
24
- def generate_have_many_test_single_line(association_class_name, association_options)
25
- have_many_test = " it { is_expected.to have_many(:#{ association_class_name })"
26
- association_options.map do |option, option_value|
27
- have_many_test_option = get_have_many_test_option(option, option_value)
28
- have_many_test.concat("." + have_many_test_option) if have_many_test_option.present?
29
- end
30
- have_many_test.concat(" }")
31
- [have_many_test]
32
- end
33
-
34
-
35
- def generate_have_many_test_multiple_lines(association_class_name, association_options)
36
- have_many_test = " it do\n is_expected.to have_many(:#{ association_class_name })"
37
- have_many_test_options = get_have_many_test_options(association_options)
38
- have_many_test.concat(have_many_test_options) if have_many_test_options.present?
39
- have_many_test.concat("\n end")
40
- [have_many_test]
41
- end
42
-
43
-
44
- def get_have_many_test_options(association_options)
45
- have_many_test_options = ""
46
- association_options.map do |option, option_value|
47
- have_many_test_option = get_have_many_test_option(option, option_value)
48
- have_many_test_options.concat(".\n " + have_many_test_option) if have_many_test_option.present?
49
- end
50
- have_many_test_options
51
- end
52
-
53
-
54
- def get_have_many_test_option(option, option_value)
55
- # IMPLEMENTATION TODO: Determine if it is possible to implement 'conditions'
56
- case option
57
- when :autosave
58
- "autosave(#{ option_value })"
59
- when :class_name
60
- "class_name('#{ option_value }')"
61
- when :dependent
62
- if option_value.to_s == "true" or option_value.to_s == "false"
63
- "dependent(#{ option_value })"
64
- else
65
- "dependent(:#{ option_value })"
66
- end
67
- when :foreign_key
68
- "with_foreign_key('#{ option_value }')"
69
- when :inverse_of
70
- "inverse_of(:#{ option_value })"
71
- # VERIFICATION TODO: Verify capture of 'order' value due to its unique syntax (e.g. '-> { order("priority desc")' })
72
- when :order
73
- if option_value.include? '"'
74
- "order('#{ option_value }')"
75
- else
76
- "order(\"#{ option_value }\")"
77
- end
78
- when :primary_key
79
- "with_primary_key('#{ option_value }')"
80
- when :source
81
- "source(:#{ option_value })"
82
- when :through
83
- "through(:#{ option_value })"
84
- when :validate
85
- "validate(#{ option_value })"
86
- else
87
- # IMPLEMENTATION TODO: Possibly handle this case option as an error or modify evaluation of option (see TODO above)
88
- ""
89
- end
90
- end
91
-
92
- end
93
- end
94
- end
95
- end
96
- end