hot-glue 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,8 +44,10 @@ module HotGlue
44
44
  # THE FORM
45
45
 
46
46
  def all_form_fields(*args)
47
+
47
48
  @columns = args[0][:columns]
48
49
  @show_only = args[0][:show_only]
50
+
49
51
  @singular_class = args[0][:singular_class]
50
52
  @ownership_field = args[0][:ownership_field]
51
53
  @form_labels_position = args[0][:form_labels_position]
@@ -53,25 +55,28 @@ module HotGlue
53
55
  @hawk_keys = args[0][:hawk_keys]
54
56
  @singular = args[0][:singular]
55
57
 
56
- column_classes = args[0][:col_identifier]
58
+ @alt_lookups = args[0][:alt_lookups]
57
59
 
60
+ column_classes = args[0][:col_identifier]
61
+ update_show_only = args[0][:update_show_only] || []
58
62
  singular = @singular
63
+
59
64
  result = columns.map{ |column|
60
65
  " <div class='#{column_classes}' >" +
61
66
  column.map { |col|
67
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
68
+ limit = eval("#{singular_class}.columns_hash['#{col}']").limit
69
+ sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
70
+
62
71
  field_result =
63
72
  if show_only.include?(col.to_sym)
64
- "<%= #{singular}.#{col} %>"
73
+ show_only_result(type: type, col: col, singular: singular)
65
74
  else
66
- type = eval("#{singular_class}.columns_hash['#{col}']").type
67
- limit = eval("#{singular_class}.columns_hash['#{col}']").limit
68
- sql_type = eval("#{singular_class}.columns_hash['#{col}']").sql_type
69
-
70
75
  case type
71
76
  when :integer
72
77
  integer_result(col)
73
78
  when :uuid
74
- uuid_result(col)
79
+ association_result(col)
75
80
  when :string
76
81
  string_result(col, sql_type, limit)
77
82
  when :text
@@ -96,11 +101,18 @@ module HotGlue
96
101
  else
97
102
  field_error_name = col
98
103
  end
99
-
104
+ show_only_open = ""
105
+ show_only_close = ""
106
+ if update_show_only.include?(col)
107
+ show_only_open = "<% if action_name == 'edit' %>" +
108
+ show_only_result(type: type, col: col, singular: singular) + "<% else %>"
109
+ show_only_close = "<% end %>"
110
+ end
100
111
  the_label = "\n<label class='small form-text text-muted'>#{col.to_s.humanize}</label>"
101
112
  add_spaces_each_line( "\n <span class='<%= \"alert-danger\" if #{singular}.errors.details.keys.include?(:#{field_error_name}) %>' #{'style="display: inherit;"'} >\n" +
102
113
  add_spaces_each_line( (@form_labels_position == 'before' ? the_label : "") +
103
- field_result + (@form_labels_position == 'after' ? the_label : "") , 4) +
114
+ show_only_open + field_result + show_only_close +
115
+ (@form_labels_position == 'after' ? the_label : "") , 4) +
104
116
  "\n </span>\n <br />", 2)
105
117
 
106
118
 
@@ -110,6 +122,14 @@ module HotGlue
110
122
  end
111
123
 
112
124
 
125
+ def show_only_result(type:, col: , singular: )
126
+ if type == :uuid || (type == :integer && col.ends_with?("_id"))
127
+ association_read_only_result(col)
128
+ else
129
+ "<%= #{singular}.#{col} %>"
130
+ end
131
+ end
132
+
113
133
  def integer_result(col)
114
134
  # look for a belongs_to on this object
115
135
  if col.to_s.ends_with?("_id")
@@ -119,13 +139,7 @@ module HotGlue
119
139
  end
120
140
  end
121
141
 
122
-
123
- def uuid_result(col)
124
- association_result(col)
125
- end
126
-
127
-
128
- def association_result(col)
142
+ def association_read_only_result(col)
129
143
  assoc_name = col.to_s.gsub("_id","")
130
144
  assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
131
145
  if assoc.nil?
@@ -134,7 +148,7 @@ module HotGlue
134
148
  end
135
149
 
136
150
  is_owner = col == ownership_field
137
- assoc_class_name = assoc.active_record.name
151
+ assoc_class_name = assoc.class_name.to_s
138
152
  display_column = HotGlue.derrive_reference_name(assoc_class_name)
139
153
 
140
154
  if @hawk_keys[assoc.foreign_key.to_sym]
@@ -143,12 +157,39 @@ module HotGlue
143
157
  else
144
158
  hawked_association = "#{assoc.class_name}.all"
145
159
  end
160
+ "<%= #{@singular}.#{assoc_name}.#{display_column} %>"
161
+ end
162
+
163
+ def association_result(col)
164
+ assoc_name = col.to_s.gsub("_id","")
165
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
146
166
 
147
- (is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
148
- " <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
149
- (is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
150
- (is_owner ? "\n<% end %>" : "")
151
167
 
168
+ if @alt_lookups.keys.include?(col.to_s)
169
+ alt = @alt_lookups[col.to_s][:lookup_as]
170
+ "<%= f.text_field :__lookup_#{alt}, value: @#{singular}.#{assoc_name}.try(:#{alt}), placeholder: \"search by #{alt}\" %>"
171
+ else
172
+ if assoc.nil?
173
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
174
+ exit
175
+ end
176
+
177
+ is_owner = col == ownership_field
178
+ assoc_class_name = assoc.class_name.to_s
179
+ display_column = HotGlue.derrive_reference_name(assoc_class_name)
180
+
181
+ if @hawk_keys[assoc.foreign_key.to_sym]
182
+ hawk_definition = @hawk_keys[assoc.foreign_key.to_sym]
183
+ hawked_association = hawk_definition.join(".")
184
+ else
185
+ hawked_association = "#{assoc.class_name}.all"
186
+ end
187
+
188
+ (is_owner ? "<% unless @#{assoc_name} %>\n" : "") +
189
+ " <%= f.collection_select(:#{col}, #{hawked_association}, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col} }, class: 'form-control') %>\n" +
190
+ (is_owner ? "<% else %>\n <%= @#{assoc_name}.#{display_column} %>" : "") +
191
+ (is_owner ? "\n<% end %>" : "")
192
+ end
152
193
  end
153
194
 
154
195
  def string_result(col, sql_type, limit)
@@ -192,7 +233,14 @@ module HotGlue
192
233
 
193
234
  def enum_result(col)
194
235
  enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
195
- "<%= f.collection_select(:#{col}, enum_to_collection_select( #{singular_class}.defined_enums['#{enum_type}']), :key, :value, {selected: @#{singular}.#{col} }, class: 'form-control') %>"
236
+
237
+ if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
238
+ enum_definer = "#{singular_class}.#{enum_type}_labels"
239
+ else
240
+ enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
241
+ end
242
+
243
+ "<%= f.collection_select(:#{col}, enum_to_collection_select(#{enum_definer}), :key, :value, {selected: @#{singular}.#{col} }, class: 'form-control') %>"
196
244
  end
197
245
 
198
246
  ################################################################
@@ -247,7 +295,8 @@ module HotGlue
247
295
  exit
248
296
  # raise(HotGlue::Error,exit_message)
249
297
  end
250
- assoc_class_name = assoc.active_record.name
298
+ assoc_class_name = assoc.class_name
299
+
251
300
  display_column = HotGlue.derrive_reference_name(assoc_class_name)
252
301
  "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
253
302
 
@@ -265,8 +314,8 @@ module HotGlue
265
314
  exit
266
315
  # raise(HotGlue::Error,exit_message)
267
316
  end
268
- assoc_class_name = assoc.active_record.name
269
- display_column = HotGlue.derrive_reference_name(assoc_class_name)
317
+
318
+ display_column = HotGlue.derrive_reference_name(assoc.class_name.to_s)
270
319
  "<%= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe %>"
271
320
 
272
321
  when :float
@@ -309,11 +358,16 @@ module HotGlue
309
358
  when :enum
310
359
  enum_type = eval("#{singular_class}.columns.select{|x| x.name == '#{col}'}[0].sql_type")
311
360
 
361
+ if eval("defined? #{singular_class}.#{enum_type}_labels") == "method"
362
+ enum_definer = "#{singular_class}.#{enum_type}_labels"
363
+ else
364
+ enum_definer = "#{singular_class}.defined_enums['#{enum_type}']"
365
+ end
312
366
  "
313
367
  <% if #{singular}.#{col}.nil? %>
314
368
  <span class='alert-danger'>MISSING</span>
315
369
  <% else %>
316
- <%= #{singular_class}.defined_enums['#{enum_type}'][#{singular}.#{col}] %>
370
+ <%= #{enum_definer}[#{singular}.#{col}.to_sym] %>
317
371
  <% end %>
318
372
 
319
373
  "
@@ -121,6 +121,7 @@ module HotGlue
121
121
  class_option :no_paginate, type: :boolean, default: false
122
122
  class_option :big_edit, type: :boolean, default: false
123
123
  class_option :show_only, type: :string, default: ""
124
+ class_option :update_show_only, type: :string, default: ""
124
125
 
125
126
  class_option :ujs_syntax, type: :boolean, default: nil
126
127
  class_option :downnest, type: :string, default: nil
@@ -133,19 +134,24 @@ module HotGlue
133
134
  class_option :hawk, type: :string, default: nil
134
135
  class_option :with_turbo_streams, type: :boolean, default: false
135
136
 
136
- class_option :no_list_label, type: :boolean, default: false
137
+ class_option :label, default: nil
138
+ class_option :list_label_heading, default: nil
139
+ class_option :new_button_label, default: nil
140
+ class_option :new_form_heading, default: nil
137
141
 
142
+ class_option :no_list_label, type: :boolean, default: false
138
143
  class_option :no_list_heading, type: :boolean, default: false
139
144
 
140
-
141
145
  # determines if the labels show up BEFORE or AFTER on the NEW/EDIT (form)
142
146
  class_option :form_labels_position, type: :string, default: 'after' # choices are before, after, omit
143
147
  class_option :form_placeholder_labels, type: :boolean, default: false # puts the field names into the placeholder labels
144
148
 
145
-
146
- # NOT YET IMPLEMENTED
147
149
  # determines if labels appear within the rows of the VIEWABLE list (does NOT affect the list heading)
148
150
  class_option :inline_list_labels, default: 'omit' # choices are before, after, omit
151
+ class_option :factory_creation, default: ''
152
+ class_option :alt_foreign_key_lookup, default: '' #
153
+
154
+
149
155
 
150
156
  def initialize(*meta_args)
151
157
  super
@@ -259,8 +265,9 @@ module HotGlue
259
265
 
260
266
  if !options['include'].empty?
261
267
  @include_fields = []
268
+
262
269
  # semicolon to denote layout columns; commas separate fields
263
- @include_fields += options['include'].gsub(":","").split(",").collect(&:to_sym)
270
+ @include_fields += options['include'].split(":").collect{|x|x.split(",")}.flatten.collect(&:to_sym)
264
271
  end
265
272
 
266
273
 
@@ -269,6 +276,13 @@ module HotGlue
269
276
  @show_only += options['show_only'].split(",").collect(&:to_sym)
270
277
  end
271
278
 
279
+ @update_show_only = []
280
+ if !options['update_show_only'].empty?
281
+ @update_show_only += options['update_show_only'].split(",").collect(&:to_sym)
282
+ end
283
+
284
+
285
+
272
286
  @god = options['god'] || options['gd'] || false
273
287
  @specs_only = options['specs_only'] || false
274
288
 
@@ -404,6 +418,8 @@ module HotGlue
404
418
  identify_object_owner
405
419
  setup_hawk_keys
406
420
 
421
+ @factory_creation = options['factory_creation'].gsub(";", "\n")
422
+
407
423
 
408
424
 
409
425
  # SETUP FIELDS & LAYOUT
@@ -421,15 +437,63 @@ module HotGlue
421
437
  smart_layout: @smart_layout )
422
438
  @layout_object = builder.construct
423
439
 
424
- @menu_file_exists = true if @nested_set.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
440
+ @menu_file_exists = true if @nested_set.none? && File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
425
441
 
426
442
  @turbo_streams = !!options['with_turbo_streams']
443
+
444
+
445
+ # syntax should be xyz_id{xyz_email},abc_id{abc_email}
446
+ # instead of a drop-down for the foreign entity, a text field will be presented
447
+ # You must ALSO use a factory that contains a parameter of the same name as the 'value' (for example, `xyz_email`)
448
+
449
+ alt_lookups_entry = options['alt_foreign_key_lookup'].split(",")
450
+ @alt_lookups = {}
451
+ @alt_foreign_key_lookup = alt_lookups_entry.each do |setting|
452
+ setting =~ /(.*){(.*)}/
453
+ key, lookup_as = $1, $2
454
+ assoc = eval("#{class_name}.reflect_on_association(:#{key.to_s.gsub("_id","")}).class_name")
455
+
456
+ data = {lookup_as: lookup_as.gsub("+",""),
457
+ assoc: assoc,
458
+ with_create: lookup_as.include?("+")}
459
+ @alt_lookups[key] = data
460
+ end
461
+
462
+ puts "------ ALT LOOKUPS for #{@alt_lookups}"
463
+
464
+ @update_alt_lookups = @alt_lookups.collect{|key, value|
465
+ @update_show_only.include?(key) ?
466
+ { key: value }
467
+ : nil}.compact
468
+
469
+ @label = options['label'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? eval("#{class_name}.class_variable_get(:@@table_label_singular)") : singular.gsub("_", " ").titleize )
470
+ @list_label_heading = options['list_label_heading'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_plural)") ? eval("#{class_name}.class_variable_get(:@@table_label_plural)") : plural.gsub("_", " ").upcase )
471
+
472
+ @new_button_label = options['new_button_label'] || ( eval("#{class_name}.class_variable_defined?(:@@table_label_singular)") ? "New " + eval("#{class_name}.class_variable_get(:@@table_label_singular)") : "New " + singular.gsub("_", " ").titleize )
473
+ @new_form_heading = options['new_form_heading'] || "New #{@label}"
427
474
  end
428
475
 
476
+
477
+ def fields_filtered_for_email_lookups
478
+ @columns.reject{|c| @alt_lookups.keys.include?(c) } + @alt_lookups.values.map{|v| ("__lookup_#{v[:lookup_as]}").to_sym}
479
+ end
480
+
481
+
482
+ def creation_syntax
483
+ if @factory_creation == ''
484
+ "@#{singular_name } = #{ class_name }.create(modified_params)"
485
+ else
486
+ "#{@factory_creation}\n" +
487
+ " @#{singular_name } = #{ class_name }.create(modified_params)"
488
+ end
489
+ end
490
+
491
+
492
+
429
493
  def setup_hawk_keys
430
494
  @hawk_keys = {}
431
495
 
432
- if options['hawk']
496
+ if options["hawk"]
433
497
  options['hawk'].split(",").each do |hawk_entry|
434
498
  # format is: abc_id[thing]
435
499
 
@@ -443,7 +507,9 @@ module HotGlue
443
507
 
444
508
  hawk_scope = key.gsub("_id", "").pluralize
445
509
  @hawk_keys[key.to_sym] = [hawk_to]
446
- if @use_shorthand # only include the hawk scope if using the shorthand
510
+ use_shorthand = !hawk_scope.include?("{")
511
+
512
+ if use_shorthand # only include the hawk scope if using the shorthand
447
513
  @hawk_keys[key.to_sym] << hawk_scope
448
514
  end
449
515
  end
@@ -496,6 +562,7 @@ module HotGlue
496
562
  @columns = @the_object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
497
563
  end
498
564
 
565
+
499
566
  @associations = []
500
567
  @columns.each do |col|
501
568
  if col.to_s.starts_with?("_")
@@ -573,7 +640,7 @@ module HotGlue
573
640
  unless @no_specs
574
641
  dest_file = File.join("#{'spec/dummy/' if Rails.env.test?}spec/system#{namespace_with_dash}", "#{plural}_behavior_spec.rb")
575
642
 
576
- if File.exists?(dest_file)
643
+ if File.exist?(dest_file)
577
644
  existing_file = File.open(dest_file)
578
645
  existing_content = existing_file.read
579
646
  if existing_content =~ /\#HOTGLUE-SAVESTART/
@@ -589,12 +656,30 @@ module HotGlue
589
656
  @existing_content = " #HOTGLUE-SAVESTART\n #HOTGLUE-END"
590
657
  end
591
658
 
659
+
592
660
  template "system_spec.rb.erb", dest_file
593
661
  end
594
662
 
595
663
  template "#{@markup}/_errors.#{@markup}", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.#{@markup}")
596
664
  end
597
665
 
666
+ def spec_foreign_association_merge_hash
667
+ ", #{testing_name}: #{testing_name}1"
668
+ end
669
+
670
+ def spec_related_column_lets
671
+ (@columns - @show_only).map { |col|
672
+ type = eval("#{singular_class}.columns_hash['#{col}']").type
673
+ if (type == :integer && col.to_s.ends_with?("_id") || type == :uuid)
674
+ assoc = "#{col.to_s.gsub('_id','')}"
675
+ the_foreign_class = eval(@singular_class + ".reflect_on_association(:" + assoc + ")").class_name.split("::").last.underscore
676
+ hawk_keys_on_lets = (@hawk_keys["#{assoc}_id".to_sym] ? ", #{@auth.gsub('current_', '')}: #{@auth}": "")
677
+
678
+ " let!(:#{assoc}1) {create(:#{the_foreign_class}" + hawk_keys_on_lets + ")}"
679
+ end
680
+ }.compact.join("\n")
681
+ end
682
+
598
683
  def list_column_headings
599
684
  @template_builder.list_column_headings(
600
685
  columns: @layout_object[:columns][:container],
@@ -622,11 +707,13 @@ module HotGlue
622
707
 
623
708
 
624
709
  def regenerate_me_code
625
- "rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].join(" ")}"
710
+ "rails generate hot_glue:scaffold #{ @meta_args[0][0] } #{@meta_args[1].collect{|x| x.gsub(/\s*=\s*([\S\s]+)/, '=\'\1\'')}.join(" ")}"
626
711
  end
627
712
 
628
713
  def object_parent_mapping_as_argument_for_specs
629
- if @nested_set.any?
714
+ if @self_auth
715
+ ""
716
+ elsif @nested_set.any?
630
717
  ", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
631
718
  elsif @auth
632
719
  ", #{@auth_identifier}: #{@auth}"
@@ -640,7 +727,7 @@ module HotGlue
640
727
  end
641
728
 
642
729
  @nested_set.each do |arg|
643
- res << " let(:#{arg[:singular]}) {create(:#{arg[:singular]} #{last_parent} )}\n"
730
+ res << "let(:#{arg[:singular]}) {create(:#{arg[:singular]} #{last_parent} )}\n"
644
731
  last_parent = ", #{arg[:singular]}: #{arg[:singular]}"
645
732
  end
646
733
  res
@@ -661,7 +748,7 @@ module HotGlue
661
748
  end
662
749
 
663
750
  def testing_name
664
- singular_class_name.gsub("::","_").downcase
751
+ singular_class_name.gsub("::","_").underscore
665
752
  end
666
753
 
667
754
  def singular_class_name
@@ -676,8 +763,8 @@ module HotGlue
676
763
  @auth_identifier
677
764
  end
678
765
 
679
- def test_capybara_block
680
- (@columns - @show_only).map { |col|
766
+ def test_capybara_block(which_partial = :create)
767
+ (@columns - (which_partial == :create ? @show_only : (@update_show_only+@show_only))).map { |col|
681
768
  type = eval("#{singular_class}.columns_hash['#{col}']").type
682
769
  case type
683
770
  when :date
@@ -692,16 +779,17 @@ module HotGlue
692
779
  ' ' + "find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
693
780
 
694
781
  when :integer
695
-
696
782
  if col.to_s.ends_with?("_id")
697
- assoc = col.to_s.gsub('_id','')
698
- " #{col}_selector = find(\"[name='#{singular}[#{col}]']\").click \n" +
699
- " #{col}_selector.first('option', text: #{assoc}1.name).select_option"
783
+ capybara_block_for_association(col_name: col, which_partial: which_partial)
700
784
  else
701
785
  " new_#{col} = rand(10) \n" +
702
- " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
703
-
786
+ " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
704
787
  end
788
+ when :float
789
+ " " + "new_#{col} = rand(10) \n" +
790
+ " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
791
+ when :uuid
792
+ capybara_block_for_association(col_name: col, which_partial: which_partial)
705
793
 
706
794
  when :enum
707
795
  " list_of_#{col.to_s} = #{singular_class}.defined_enums['#{col.to_s}'].keys \n" +
@@ -709,17 +797,21 @@ module HotGlue
709
797
  ' find("select[name=\'' + singular + '[' + col.to_s + ']\'] option[value=\'#{new_' + col.to_s + '}\']").select_option'
710
798
 
711
799
  when :boolean
712
- " new_#{col} = rand(2).floor \n" +
713
- " find(\"[name='#{testing_name}[#{col}]'][value='\#{new_" + col.to_s + "}']\").choose"
800
+ " new_#{col} = 1 \n" +
801
+ " find(\"[name='#{testing_name}[#{col}]'][value='\#{new_" + col.to_s + "}']\").choose"
714
802
  when :string
715
- if col.to_s.include?("email")
716
- " " + "new_#{col} = 'new_test-email@nowhere.com' \n" +
717
- " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
718
-
719
- else
720
- " " + "new_#{col} = 'new_test-email@nowhere.com' \n" +
721
- " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
722
- end
803
+ faker_string =
804
+ if col.to_s.include?('email')
805
+ "FFaker::Internet.email"
806
+ elsif col.to_s.include?('domain')
807
+ "FFaker::Internet.domain_name"
808
+ elsif col.to_s.include?('ip_address') || col.to_s.ends_with?('_ip')
809
+ "FFaker::Internet.ip_v4_address"
810
+ else
811
+ "FFaker::Movie.title"
812
+ end
813
+ " " + "new_#{col} = #{faker_string} \n" +
814
+ " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
723
815
  when :text
724
816
  " " + "new_#{col} = FFaker::Lorem.paragraphs(1).join("") \n" +
725
817
  " find(\"[name='#{testing_name}[#{ col.to_s }]']\").fill_in(with: new_#{col.to_s})"
@@ -729,6 +821,20 @@ module HotGlue
729
821
  end
730
822
 
731
823
 
824
+ def capybara_block_for_association(col_name: nil , which_partial: nil )
825
+ assoc = col_name.to_s.gsub('_id','')
826
+ if which_partial == :update && @update_show_only.include?(col_name)
827
+ # do not update tests
828
+ elsif @alt_lookups.keys.include?(col_name.to_s)
829
+ lookup = @alt_lookups[col_name.to_s][:lookup_as]
830
+ " find(\"[name='#{singular}[__lookup_#{lookup}]']\").fill_in( with: #{assoc}1.#{lookup} )"
831
+ else
832
+ " #{col_name}_selector = find(\"[name='#{singular}[#{col_name}]']\").click \n" +
833
+ " #{col_name}_selector.first('option', text: #{assoc}1.name).select_option"
834
+ end
835
+ end
836
+
837
+
732
838
  def path_helper_args
733
839
  if @nested_set.any? && @nested
734
840
  [(@nested_set).collect{|a| "#{a[:singular]}"} , singular].join(",")
@@ -911,7 +1017,7 @@ module HotGlue
911
1017
 
912
1018
 
913
1019
  def include_nav_template
914
- File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}")
1020
+ File.exist?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_nav.html.#{@markup}")
915
1021
  end
916
1022
 
917
1023
  def copy_view_files
@@ -948,7 +1054,7 @@ module HotGlue
948
1054
 
949
1055
  # menu_file = "app/views#{namespace_with_dash}/menu.erb"
950
1056
  #
951
- # if File.exists?(menu_file)
1057
+ # if File.exist?(menu_file)
952
1058
  # # TODO: can I insert the new menu item into the menu programatically here?
953
1059
  # # not sure how i would achieve this without nokogiri
954
1060
  #
@@ -1004,9 +1110,11 @@ module HotGlue
1004
1110
 
1005
1111
  unless @no_edit
1006
1112
  res << 'edit'
1007
- res << '_form'
1008
1113
  end
1009
1114
 
1115
+ if !( @no_edit && @no_create)
1116
+ res << '_form'
1117
+ end
1010
1118
  res
1011
1119
  end
1012
1120
 
@@ -1041,35 +1149,28 @@ module HotGlue
1041
1149
  []
1042
1150
  end
1043
1151
 
1044
- def all_form_fields
1152
+ def form_fields_html
1045
1153
  @template_builder.all_form_fields(
1046
1154
  columns: @layout_object[:columns][:container],
1047
1155
  show_only: @show_only,
1156
+ update_show_only: @update_show_only,
1048
1157
  singular_class: singular_class,
1049
1158
  singular: singular,
1050
1159
  hawk_keys: @hawk_keys,
1051
1160
  col_identifier: @layout_strategy.column_classes_for_form_fields,
1052
1161
  ownership_field: @ownership_field,
1053
1162
  form_labels_position: @form_labels_position,
1054
- form_placeholder_labels: @form_placeholder_labels
1163
+ form_placeholder_labels: @form_placeholder_labels,
1164
+ alt_lookups: @alt_lookups
1055
1165
  )
1056
1166
  end
1057
1167
 
1058
-
1059
1168
  def list_label
1060
- if(eval("#{class_name}.class_variable_defined?(:@@table_label_plural)"))
1061
- eval("#{class_name}.class_variable_get(:@@table_label_plural)")
1062
- else
1063
- plural.gsub("_", " ").upcase
1064
- end
1169
+ @list_label_heading
1065
1170
  end
1066
1171
 
1067
- def thing_label
1068
- if(eval("#{class_name}.class_variable_defined?(:@@table_label_singular)"))
1069
- eval("#{class_name}.class_variable_get(:@@table_label_singular)")
1070
- else
1071
- singular.gsub("_", " ").upcase
1072
- end
1172
+ def new_thing_label
1173
+ @new_thing_label
1073
1174
  end
1074
1175
 
1075
1176
  def all_line_fields
@@ -1155,12 +1256,18 @@ module HotGlue
1155
1256
  }.join("\n") + "\n"
1156
1257
  end
1157
1258
 
1259
+
1158
1260
  def controller_update_params_tap_away_magic_buttons
1159
1261
  @magic_buttons.collect{ |magic_button|
1160
1262
  ".tap{ |ary| ary.delete('#{magic_button}') }"
1161
1263
  }.join("")
1162
1264
  end
1163
1265
 
1266
+ def controller_update_params_tap_away_alt_lookups
1267
+ @alt_lookups.collect{ |key, data|
1268
+ ".tap{ |ary| ary.delete('__lookup_#{data[:lookup_as]}') }"
1269
+ }.join("")
1270
+ end
1164
1271
 
1165
1272
  def nested_for_turbo_id_list_constructor
1166
1273
  if @nested_set.any?
@@ -1207,9 +1314,10 @@ module HotGlue
1207
1314
  end
1208
1315
 
1209
1316
  def hawk_to_ruby
1210
- @hawk_keys.collect{ |k,v|
1211
- "#{k}: [#{v[0]}, \"#{v[1]}\"] "
1317
+ res = @hawk_keys.collect{ |k,v|
1318
+ "#{k}: [#{v[0]}, \"#{v[1]}\"]"
1212
1319
  }.join(", ")
1320
+ res
1213
1321
  end
1214
1322
  end
1215
1323
  end