spec_fill 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 270e5fe97a01761e4d8826cd338d0abf913329455f8989291fc67f4f6cdb59df
4
- data.tar.gz: 11e1ed9e794ec83e3bd75ddb0c7cd3bc295ee351ef0df31c6de84467e05f525d
3
+ metadata.gz: 4b0eda93bcae2732cf93da79b3373dbe0b64753f443b42591435e7bb378cfb8e
4
+ data.tar.gz: 1e3ac451aab22876defe5a6980f77b43962dee06b6a3ba0510dee64a8ee63363
5
5
  SHA512:
6
- metadata.gz: 3a71de58e04ffe8f4abd6e881ac7bb09277b194651d6d85ce9c435f7ccd6467019da8a1130caf2d10e36a25a310a13cbc00a415939005ff8c89dc693897bd31a
7
- data.tar.gz: 0f78b479045dd285ddca1bdaa2bf67d9b910c8f8fb6a69d0c73316b72c94f09fe924b06da69b9d44173a1b8827ecac46c2a0f551634f33f96c59b2b32e66d968
6
+ metadata.gz: 3574d8729d618a76a4bba1bbd36b474aa89462f80eab48f14c5d2f1612c7d2c1a12df62c85d63e7bdb1a7f0a640f10f47b095a6afc67e2edd95fb936044e4d61
7
+ data.tar.gz: dc3eff9938f82d6d98ac273f71c2d8ab874738af82f2d608920b51c0bfcf7d7713c912d892da6b67dff88b196cc457be0b50a2030577b7d7df818baee182e29e
data/bin/names.txt ADDED
@@ -0,0 +1,33 @@
1
+ city, Address
2
+ street_name, Address
3
+ street_address, Address
4
+ secondary_address, Address
5
+ building_number, Address
6
+ community, Address
7
+ zip_code, Address
8
+ zip, Address
9
+ postcode, Address
10
+ time_zone, Address
11
+ street_suffix, Address
12
+ city_suffix, Address
13
+ city_prefix, Address
14
+ state, Address
15
+ state_abbr, Address
16
+ country, Address
17
+ country_code, Address
18
+ latitude, Address
19
+ longitude, Address
20
+ full_address, Address
21
+ god, Ancient
22
+ primordial, Ancient
23
+ titan, Ancient
24
+ hero, Ancient
25
+ brand,Beer
26
+ name,Beer
27
+ style,Beer
28
+ hop,Beer
29
+ yeast,Beer
30
+ malts,Beer
31
+ ibu,Beer
32
+ alcohol,Beer
33
+ blg,Beer
data/lib/spec_fill.rb CHANGED
@@ -1,51 +1,65 @@
1
- require "spec_fill/version"
2
-
3
- module SpecFill
4
- class Error < StandardError; end
5
- def fill_factory(column, factory_name='')
6
-
7
- class_name = column.split('_').map(&:capitalize).join
8
- line_array = []
9
- next_line = false
10
-
11
- File.foreach('db/schema.rb') do |line|
12
- if line.chomp.empty? && next_line == true
13
- break
14
- end
15
- if next_line
16
- line_array << line
17
- end
18
- if line.include?(column)
19
- line_array << line unless line.include?('add_index')
20
- next_line = true
21
- end
22
- end
23
-
24
- File.open("spec/factories/#{column}.rb", 'w') do |file|
25
- unless factory_name.empty?
26
- file.print("FactoryGirl.define do\n\tfactory :#{factory_name}, class: #{class_name} do\n")
27
- else
28
- file.print("FactoryGirl.define do\n\tfactory :#{column} do\n")
29
- end
30
- if line_array[0].include?('primary_key')
31
- file.print("\t\t# It looks like your primary key isn't the record ID.\n")
32
- file.print("\t\t# Don't forget to pass in your primary key when you're creating\n")
33
- file.print("\t\t# the test object (e.g., create(:object, primary_key: column_name)).\n")
34
- end
35
- line_array.shift
36
- get_attributes(line_array).each do |attr|
37
- file.print "\t\t#{attr}\n"
38
- end
39
- file.print("\tend\n")
40
- file.print('end')
41
- end
42
- end
43
-
44
- def get_attributes(ary)
45
- stripped_ary = []
46
- ary.each do |char|
47
- stripped_ary << char.scan(/"([^"]*)"/)
48
- end
49
- stripped_ary.flatten
50
- end
51
- end
1
+ # require "spec_fill/version"
2
+ #
3
+ # module SpecFill
4
+ # class Error < StandardError; end
5
+ # def fill_factory(column, factory_name='')
6
+ #
7
+ # class_name = column.split('_').map(&:capitalize).join
8
+ # line_array = []
9
+ # next_line = false
10
+ #
11
+ # File.foreach('db/schema.rb') do |line|
12
+ # if line.chomp.empty? && next_line == true
13
+ # break
14
+ # end
15
+ # if next_line
16
+ # line_array << line
17
+ # end
18
+ # if line.include?(column)
19
+ # line_array << line unless line.include?('add_index')
20
+ # next_line = true
21
+ # end
22
+ # end
23
+ #
24
+ # File.open("spec/factories/#{column}.rb", 'w') do |file|
25
+ # unless factory_name.empty?
26
+ # file.print("FactoryGirl.define do\n\tfactory :#{factory_name}, class: #{class_name} do\n")
27
+ # else
28
+ # file.print("FactoryGirl.define do\n\tfactory :#{column} do\n")
29
+ # end
30
+ # if line_array[0].include?('primary_key')
31
+ # file.print("\t\t# It looks like your primary key isn't the record ID.\n")
32
+ # file.print("\t\t# Don't forget to pass in your primary key when you're creating\n")
33
+ # file.print("\t\t# the test object (e.g., create(:object, primary_key: column_name)).\n")
34
+ # end
35
+ # line_array.shift
36
+ # get_attributes(line_array).each do |attr|
37
+ # file.print "\t\t#{attr}\n"
38
+ # end
39
+ # file.print("\tend\n")
40
+ # file.print('end')
41
+ # end
42
+ # end
43
+ #
44
+ # def get_attributes(ary)
45
+ # stripped_ary = []
46
+ # ary.each do |char|
47
+ # stripped_ary << char.scan(/"([^"]*)"/)
48
+ # end
49
+ # stripped_ary.flatten
50
+ # end
51
+ #
52
+ # def check_spec(*lorem)
53
+ # File.foreach('db/beer.txt') do |line|
54
+ # if line.to_s.include?('ibu')
55
+ # File.open("db/beer_terms.rb", 'w') do |file|
56
+ # file.print line
57
+ # end
58
+ # else
59
+ # File.open("db/beer_terms.rb", 'w') do |file|
60
+ # file.puts "DID NOT FIND #{line}"
61
+ # end
62
+ # end
63
+ # end
64
+ # end
65
+ # end
data/lib/spec_fill/cli.rb CHANGED
@@ -8,34 +8,42 @@ module SpecFill
8
8
  class_name = column.split('_').map(&:capitalize).join
9
9
  line_array = []
10
10
  next_line = false
11
+ faker_terms = 'vendor/bundle/ruby/2.6.0/gems/spec_fill-0.1.0/lib/faker_terms.txt'
12
+ skip_spaces = indent_length(faker_terms)
11
13
 
12
14
  File.foreach('db/schema.rb') do |line|
13
- if line.chomp.empty? && next_line == true
14
- break
15
- end
16
- if next_line
17
- line_array << line
18
- end
15
+ break if line.chomp.empty? && next_line == true
16
+ line_array << line if next_line
19
17
  if line.include?(column)
20
18
  line_array << line unless line.include?('add_index')
21
19
  next_line = true
22
20
  end
23
21
  end
24
22
 
23
+ not_a_colum(line_array)
24
+
25
25
  File.open("spec/factories/#{column}.rb", 'w') do |file|
26
26
  unless factory_name.empty?
27
27
  file.print("FactoryGirl.define do\n\tfactory :#{factory_name}, class: #{class_name} do\n")
28
28
  else
29
29
  file.print("FactoryGirl.define do\n\tfactory :#{column} do\n")
30
30
  end
31
- if line_array[0].include?('primary_key')
32
- file.print("\t\t# It looks like your primary key isn't the record ID.\n")
33
- file.print("\t\t# Don't forget to pass in your primary key when you're creating\n")
34
- file.print("\t\t# the test object (e.g., create(:object, primary_key: column_name)).\n")
35
- end
31
+
32
+ reminder if line_array[0].include?('primary_key')
33
+
36
34
  line_array.shift
37
35
  get_attributes(line_array).each do |attr|
38
- file.print "\t\t#{attr}\n"
36
+ finished = false
37
+ File.foreach(faker_terms) do |line|
38
+ if line.to_s.include?(attr)
39
+ meth = line.split(',')
40
+ file.print "\t\t#{attr}\t\t\tFaker::#{meth[1].chomp}.#{meth[0]}\n"
41
+ finished = true
42
+ end
43
+ end
44
+ if finished == false
45
+ file.print "\t\t#{attr}\n"
46
+ end
39
47
  end
40
48
  file.print("\tend\n")
41
49
  file.print('end')
@@ -56,7 +64,32 @@ module SpecFill
56
64
  puts "\nSpecFill!"
57
65
  puts "version: " + SpecFill::VERSION
58
66
  puts "author: Publicover\n"
67
+ end
59
68
 
69
+ desc 'reminder', 'Puts reminder about primary keys in the file'
70
+ def reminder
71
+ file.print("\t\t# It looks like your primary key isn't the record ID.\n")
72
+ file.print("\t\t# Don't forget to pass in your primary key when you're creating\n")
73
+ file.print("\t\t# the test object (e.g., create(:object, primary_key: column_name)).\n")
74
+ end
75
+
76
+ desc 'indent_length |schema|', 'A helper method for #fill(column)'
77
+ def indent_length(schema)
78
+ num = 0
79
+ File.foreach(schema) do |line|
80
+ if line.to_i > num
81
+ num = line.to_i
82
+ end
83
+ end
84
+ num
85
+ end
86
+
87
+ desc 'not_a_column |column|', 'A helper method for #fill(column)'
88
+ def not_a_colum(ary)
89
+ if ary.empty?
90
+ puts 'That is not a column in your db'
91
+ return false
92
+ end
60
93
  end
61
94
  end
62
95
  end
@@ -1,3 +1,3 @@
1
1
  module SpecFill
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spec_fill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Publicover
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-06 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,12 +86,14 @@ files:
86
86
  - README.md
87
87
  - Rakefile
88
88
  - bin/console
89
+ - bin/names.txt
89
90
  - bin/setup
90
91
  - exe/spec_fill
91
92
  - lib/spec_fill.rb
92
93
  - lib/spec_fill/cli.rb
93
94
  - lib/spec_fill/version.rb
94
95
  - spec_fill-0.1.0.gem
96
+ - spec_fill-0.1.1.gem
95
97
  - spec_fill.gemspec
96
98
  - vendor/bundle/ruby/2.6.0/bin/htmldiff
97
99
  - vendor/bundle/ruby/2.6.0/bin/ldiff