hot-glue 0.5.14 → 0.5.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +74 -0
  3. data/.github/workflows/test.yml +33 -14
  4. data/.gitignore +0 -2
  5. data/.ruby-version +1 -1
  6. data/Gemfile +4 -2
  7. data/Gemfile.lock +280 -0
  8. data/README.md +9 -1
  9. data/lib/generators/hot_glue/direct_upload_install_generator.rb +1 -1
  10. data/lib/generators/hot_glue/dropzone_install_generator.rb +1 -1
  11. data/lib/generators/hot_glue/field_factory.rb +4 -1
  12. data/lib/generators/hot_glue/fields/association_field.rb +73 -6
  13. data/lib/generators/hot_glue/fields/attachment_field.rb +7 -3
  14. data/lib/generators/hot_glue/fields/boolean_field.rb +21 -0
  15. data/lib/generators/hot_glue/fields/date_field.rb +13 -0
  16. data/lib/generators/hot_glue/fields/date_time_field.rb +13 -2
  17. data/lib/generators/hot_glue/fields/enum_field.rb +39 -6
  18. data/lib/generators/hot_glue/fields/field.rb +43 -3
  19. data/lib/generators/hot_glue/fields/float_field.rb +9 -0
  20. data/lib/generators/hot_glue/fields/integer_field.rb +4 -0
  21. data/lib/generators/hot_glue/fields/string_field.rb +17 -0
  22. data/lib/generators/hot_glue/fields/text_field.rb +17 -0
  23. data/lib/generators/hot_glue/fields/time_field.rb +20 -0
  24. data/lib/generators/hot_glue/fields/uuid_field.rb +1 -1
  25. data/lib/generators/hot_glue/flash_notices_install_generator.rb +1 -1
  26. data/lib/generators/hot_glue/install_generator.rb +15 -9
  27. data/lib/generators/hot_glue/markup_templates/erb.rb +14 -279
  28. data/lib/generators/hot_glue/scaffold_generator.rb +3 -5
  29. data/lib/hotglue/version.rb +1 -1
  30. data/script/test +9 -14
  31. metadata +5 -3
@@ -10,7 +10,6 @@ class DateTimeField < Field
10
10
  end
11
11
 
12
12
  def spec_make_assertion
13
-
14
13
  "expect(page).to have_content(new_#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone))"
15
14
  end
16
15
 
@@ -19,6 +18,18 @@ class DateTimeField < Field
19
18
  end
20
19
 
21
20
  def spec_list_view_assertion
22
- "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(current_timezone) )"
21
+ "expect(page).to have_content(#{singular}#{1}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ').gsub(' ', ' ') + timezonize(current_timezone) )"
22
+ end
23
+
24
+ def form_field_output
25
+ "<%= datetime_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }', #{auth ? auth+'.timezone' : 'nil'}) %>"
26
+ end
27
+
28
+ def line_field_output
29
+ "<% unless #{singular}.#{name}.nil? %>
30
+ <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone) %>
31
+ <% else %>
32
+ <span class='alert-danger'>MISSING</span>
33
+ <% end %>"
23
34
  end
24
35
  end
@@ -1,12 +1,17 @@
1
1
  class EnumField < Field
2
2
  def spec_setup_and_change_act(which_partial = nil)
3
- " list_of_#{name.to_s} = #{singular_class}.defined_enums['#{name.to_s}'].keys \n" +
4
- " " + "new_#{name.to_s} = list_of_#{name.to_s}[rand(list_of_#{name.to_s}.length)].to_s \n" +
5
- ' find("select[name=\'' + singular + '[' + name.to_s + ']\'] option[value=\'#{new_' + name.to_s + '}\']").select_option'
3
+ # what is the enum name
4
+ " list_of_#{enum_type} = #{class_name}.defined_enums['#{enum_type}'].keys \n" +
5
+ " " + "new_#{name} = list_of_#{enum_type}[rand(list_of_#{enum_type}.length)].to_s \n" +
6
+ ' find("select[name=\'' + singular + '[' + name + ']\'] option[value=\'#{new_' + name + '}\']").select_option'
7
+ end
8
+
9
+ def enum_type
10
+ eval("#{class_name}.columns.select{|x| x.name == '#{name}'}[0].sql_type")
6
11
  end
7
12
 
8
13
  def spec_make_assertion
9
- if(eval("#{singular_class}.respond_to?(:#{name}_labels)"))
14
+ if(eval("#{class_name}.respond_to?(:#{name}_labels)"))
10
15
  "expect(page).to have_content(#{singular_class}.#{name}_labels[new_#{name}])"
11
16
  else
12
17
  "expect(page).to have_content(new_#{name})"
@@ -18,10 +23,38 @@ class EnumField < Field
18
23
  end
19
24
 
20
25
  def spec_list_view_assertion
21
- if(eval("#{singular_class}.respond_to?(:#{name}_labels)"))
22
- "expect(page).to have_content(#{singular_class}.#{name}_labels[#{singular}#{1}.#{name}])"
26
+ if(eval("#{class_name}.respond_to?(:#{name}_labels)"))
27
+ "expect(page).to have_content(#{class_name}.#{name}_labels[#{singular}#{1}.#{name}])"
23
28
  else
24
29
  "expect(page).to have_content(#{singular}1.#{name})"
25
30
  end
26
31
  end
32
+
33
+ def form_field_output
34
+ enum_type = eval("#{class_name}.columns.select{|x| x.name == '#{name}'}[0].sql_type")
35
+
36
+ if eval("defined? #{class_name}.#{enum_type}_labels") == "method"
37
+ enum_definer = "#{class_name}.#{enum_type}_labels"
38
+ else
39
+ enum_definer = "#{class_name}.defined_enums['#{enum_type}']"
40
+ end
41
+ return "<%= f.collection_select(:#{name}, enum_to_collection_select(#{enum_definer}), :key, :value, {selected: #{singular}.#{name} }, class: 'form-control') %>"
42
+ end
43
+
44
+ def line_field_output
45
+ enum_type = eval("#{class_name}.columns.select{|x| x.name == '#{name}'}[0].sql_type")
46
+
47
+ if eval("defined? #{class_name}.#{enum_type}_labels") == "method"
48
+ enum_definer = "#{class_name}.#{enum_type}_labels"
49
+ else
50
+ enum_definer = "#{class_name}.defined_enums['#{enum_type}']"
51
+ end
52
+ "
53
+ <% if #{singular}.#{name}.nil? %>
54
+ <span class='alert-danger'>MISSING</span>
55
+ <% else %>
56
+ <%= #{enum_definer}[#{singular}.#{name}.to_sym] %>
57
+ <% end %>
58
+ "
59
+ end
27
60
  end
@@ -3,11 +3,16 @@ class Field
3
3
  :update_show_only
4
4
  attr_accessor :assoc_model, :assoc_name, :assoc_class, :associations, :alt_lookups, :assoc_label
5
5
 
6
- attr_accessor :hawk_keys, :auth, :sample_file_path
6
+ attr_accessor :hawk_keys, :auth, :sample_file_path, :form_placeholder_labels, :ownership_field,
7
+ :sql_type, :limit, :layout_strategy, :form_labels_position
8
+
9
+ def initialize(name: , class_name: , alt_lookups: , singular: , update_show_only: , form_labels_position:,
10
+ form_placeholder_labels: ,
11
+ auth: , ownership_field: , hawk_keys: nil, layout_strategy: ,
12
+ sample_file_path: nil, attachment_data: nil )
7
13
 
8
- def initialize(name: , class_name: , alt_lookups: , singular: , update_show_only: ,
9
- hawk_keys: , auth: , sample_file_path: nil, attachment_data: nil )
10
14
  @name = name
15
+ @layout_strategy = layout_strategy
11
16
  @alt_lookups = alt_lookups
12
17
  @singular = singular
13
18
  @class_name = class_name
@@ -15,12 +20,26 @@ class Field
15
20
  @hawk_keys = hawk_keys
16
21
  @auth = auth
17
22
  @sample_file_path = sample_file_path
23
+ @form_placeholder_labels = form_placeholder_labels
24
+ @ownership_field = ownership_field
25
+ @form_labels_position = form_labels_position
26
+
27
+
28
+ # TODO: remove knowledge of subclasses from Field
29
+ unless self.class == AttachmentField
30
+ @sql_type = eval("#{class_name}.columns_hash['#{name}']").sql_type
31
+ @limit = eval("#{class_name}.columns_hash['#{name}']").limit
32
+ end
18
33
  end
19
34
 
20
35
  def getName
21
36
  @name
22
37
  end
23
38
 
39
+ def field_error_name
40
+ name
41
+ end
42
+
24
43
  def spec_random_data
25
44
 
26
45
  end
@@ -48,4 +67,25 @@ class Field
48
67
  def spec_related_column_lets
49
68
  ""
50
69
  end
70
+
71
+ def form_show_only_output
72
+ "<%= #{singular}.#{name} %>"
73
+ end
74
+
75
+ def line_field_output
76
+ "<%= #{singular}.#{name} %>"
77
+ end
78
+
79
+ def field_output(type = nil, width )
80
+ " <%= f.text_field :#{name}, value: #{singular}.#{name}, autocomplete: 'off', size: #{width}, class: 'form-control', type: '#{type}'" + (form_placeholder_labels ? ", placeholder: '#{name.to_s.humanize}'" : "") + " %>\n " + "\n"
81
+ end
82
+
83
+ def text_area_output(field_length )
84
+ lines = field_length % 40
85
+ if lines > 5
86
+ lines = 5
87
+ end
88
+
89
+ "<%= f.text_area :#{name}, class: 'form-control', autocomplete: 'off', cols: 40, rows: '#{lines}'" + ( form_placeholder_labels ? ", placeholder: '#{name.to_s.humanize}'" : "") + " %>"
90
+ end
51
91
  end
@@ -8,4 +8,13 @@ class FloatField < Field
8
8
  def spec_setup_let_arg
9
9
  "#{name}: rand(1)*10000"
10
10
  end
11
+
12
+ def form_field_output
13
+ field_output(nil, 5)
14
+ end
15
+
16
+ def line_field_output
17
+ width = (limit && limit < 40) ? limit : (40)
18
+ "<%= #{singular}.#{name}%>"
19
+ end
11
20
  end
@@ -23,4 +23,8 @@ class IntegerField < Field
23
23
  def spec_list_view_assertion
24
24
  "expect(page).to have_content(#{singular}#{1}.#{name})"
25
25
  end
26
+
27
+ def form_field_output
28
+ " <%= f.text_field :#{name}, value: #{singular}.#{name}, autocomplete: 'off', size: 4, class: 'form-control', type: 'number'" + (form_placeholder_labels ? ", placeholder: '#{name.to_s.humanize}'" : "") + " %>\n " + "\n"
29
+ end
26
30
  end
@@ -30,4 +30,21 @@ class StringField < Field
30
30
  "#{name}: FFaker::Movie.title"
31
31
  end
32
32
  end
33
+
34
+ def form_field_output
35
+ if sql_type == "varchar" || sql_type == "character varying"
36
+ field_output(nil, limit || 40)
37
+ else
38
+ text_area_output( 65536)
39
+ end
40
+ end
41
+
42
+ # TODO: dry with text_field.rb
43
+ def text_result(col, sql_type, limit)
44
+ if sql_type == "varchar"
45
+ field_output( nil, limit)
46
+ else
47
+ text_area_output( 65536)
48
+ end
49
+ end
33
50
  end
@@ -11,4 +11,21 @@ class TextField < Field
11
11
  def spec_setup_let_arg
12
12
  "#{name}: FFaker::Lorem.paragraphs(10).join(" ")"
13
13
  end
14
+
15
+ def form_field_output
16
+ if sql_type == "varchar" || sql_type == "character varying"
17
+ field_output( nil, limit || 40)
18
+ else
19
+ text_area_output( 65536)
20
+ end
21
+ end
22
+
23
+ # TODO: dry with string_field.rb
24
+ def text_result( sql_type, limit)
25
+ if sql_type == "varchar"
26
+ field_output( nil, limit)
27
+ else
28
+ text_area_output( 65536)
29
+ end
30
+ end
14
31
  end
@@ -3,4 +3,24 @@ class TimeField < Field
3
3
  def spec_setup_let_arg
4
4
  "#{name}: Time.current + rand(5000).seconds"
5
5
  end
6
+
7
+ def form_field_output
8
+ "<%= time_field_localized(f, :#{name}, #{singular}.#{name}, '#{ name.to_s.humanize }', #{auth ? auth+'.timezone' : 'nil'}) %>"
9
+ end
10
+
11
+ def line_field_output
12
+ "<% unless #{singular}.#{name}.nil? %>
13
+ <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone) %>
14
+ <% else %>
15
+ <span class='alert-danger'>MISSING</span>
16
+ <% end %>"
17
+ end
18
+
19
+ def spec_make_assertion
20
+ "#expect(page).to have_content(new_#{name} .in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone))"
21
+ end
22
+
23
+ def spec_list_view_assertion
24
+ "#expect(page).to have_content(#{singular}#{1}.#{name})"
25
+ end
6
26
  end
@@ -1,4 +1,4 @@
1
- class UUIDField < Field
1
+ class UUIDField < AssociationField
2
2
  def spec_setup_let_arg
3
3
  "#{name.to_s.gsub('_id','')}: #{name.to_s.gsub('_id','')}1"
4
4
  end
@@ -4,7 +4,7 @@ module HotGlue
4
4
 
5
5
  def filepath_prefix
6
6
  # todo: inject the context
7
- 'spec/dummy/' if Rails.env.test?
7
+ 'spec/dummy/' if $INTERNAL_SPECS
8
8
  end
9
9
 
10
10
 
@@ -13,6 +13,12 @@ module HotGlue
13
13
 
14
14
 
15
15
 
16
+
17
+ def filepath_prefix
18
+ 'spec/dummy/' if $INTERNAL_SPECS
19
+ end
20
+
21
+
16
22
  def initialize(*args) #:nodoc:
17
23
  super
18
24
  layout = options['layout'] || "hotglue"
@@ -28,7 +34,7 @@ module HotGlue
28
34
 
29
35
 
30
36
  @markup = options['markup'] || "erb"
31
- copy_file "erb/_flash_notices.erb", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.erb"
37
+ copy_file "erb/_flash_notices.erb", "#{filepath_prefix}app/views/layouts/_flash_notices.erb"
32
38
 
33
39
  begin
34
40
  if Rails.version.split(".")[0].to_i == 6
@@ -51,7 +57,7 @@ module HotGlue
51
57
 
52
58
 
53
59
  begin
54
- rails_helper_contents = File.read("#{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb")
60
+ rails_helper_contents = File.read("#{filepath_prefix}spec/rails_helper.rb")
55
61
  if !rails_helper_contents.include?("Capybara.default_driver =")
56
62
  rails_helper_contents << "\nCapybara.default_driver = :selenium_chrome_headless "
57
63
  puts " HOTGLUE --> added to spec/rails_helper.rb: `Capybara.default_driver = :selenium_chrome_headless` "
@@ -61,14 +67,14 @@ module HotGlue
61
67
  rails_helper_contents.gsub!("RSpec.configure do |config|", "RSpec.configure do |config| \n
62
68
  config.include FactoryBot::Syntax::Methods
63
69
  ")
64
- puts " HOTGLUE --> added to #{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
70
+ puts " HOTGLUE --> added to #{filepath_prefix}spec/rails_helper.rb: `config.include FactoryBot::Syntax::Methods` "
65
71
  end
66
72
 
67
73
  if ! rails_helper_contents.include?("require 'support/capybara_login.rb'")
68
74
  rails_helper_contents.gsub!("require 'rspec/rails'","require 'rspec/rails' \nrequire 'support/capybara_login.rb'")
69
75
  puts " HOTGLUE --> added to spec/rails_helper.rb: `require 'support/capybara_login.rb'` "
70
76
  end
71
- File.write("#{'spec/dummy/' if Rails.env.test?}spec/rails_helper.rb", rails_helper_contents)
77
+ File.write("#{filepath_prefix}spec/rails_helper.rb", rails_helper_contents)
72
78
 
73
79
  rescue StandardError => e
74
80
  puts "WARNING: error writing to spec/rails_helper --- #{e.message}"
@@ -95,7 +101,7 @@ module HotGlue
95
101
  theme_location = "themes/hotglue_scaffold_#{@theme}.scss"
96
102
  theme_file = "hotglue_scaffold_#{@theme}.scss"
97
103
 
98
- copy_file theme_location, "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/#{theme_file}"
104
+ copy_file theme_location, "#{filepath_prefix}app/assets/stylesheets/#{theme_file}"
99
105
 
100
106
  application_scss = File.read("app/assets/stylesheets/application.scss")
101
107
 
@@ -114,10 +120,10 @@ module HotGlue
114
120
 
115
121
 
116
122
  begin
117
- if !File.exist?("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml")
123
+ if !File.exist?("#{filepath_prefix}config/hot_glue.yml")
118
124
  yaml = {layout: layout,
119
125
  markup: @markup}.to_yaml
120
- File.write("#{'spec/dummy/' if Rails.env.test?}config/hot_glue.yml", yaml)
126
+ File.write("#{filepath_prefix}config/hot_glue.yml", yaml)
121
127
 
122
128
  end
123
129
  rescue StandardError => e
@@ -126,8 +132,8 @@ module HotGlue
126
132
 
127
133
 
128
134
  begin
129
- if !File.exist?("#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb")
130
- copy_file "capybara_login.rb", "#{'spec/dummy/' if Rails.env.test?}spec/support/capybara_login.rb"
135
+ if !File.exist?("#{filepath_prefix}spec/support/capybara_login.rb")
136
+ copy_file "capybara_login.rb", "#{filepath_prefix}spec/support/capybara_login.rb"
131
137
  end
132
138
  rescue StandardError => e
133
139
  puts "WARNING: error writing to #{Rails.env.test? ? 'spec/dummmy/' : ''}spec/support/capybara_login.rb --- #{e.message}"