spec_filler 0.0.6
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.
- checksums.yaml +7 -0
- data/bin/spec_filler +6 -0
- data/lib/spec_filler.rb +52 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74878175d5e281300c25c597ae17de01473b5c12
|
4
|
+
data.tar.gz: f3758e089b481b4bb68c9051185017b68d4a75a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4404fb10ed71058e9d9f5456f45ae37ca93f9e6825cadd1e2c35f8adececc2b4deb856cf253bb7f976867e46edb595039d160aa6f0c7d0dfe9c4316673994725
|
7
|
+
data.tar.gz: 1582a76e610f482c43946ad23fb007941ef19d9e74baf9ab85899f9af99d113ab0397a99966526555d0584226e3822e54e931a604723a64195338f0af0bc2757
|
data/bin/spec_filler
ADDED
data/lib/spec_filler.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# require './schema.txt'
|
2
|
+
module SpecFiller
|
3
|
+
class Filler
|
4
|
+
|
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
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spec_filler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- publicover
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Use your schema to fill out a FactoryBot file
|
14
|
+
email: jameslpublicover@gmail.com
|
15
|
+
executables:
|
16
|
+
- spec_filler
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/spec_filler
|
21
|
+
- lib/spec_filler.rb
|
22
|
+
homepage:
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.2.3
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Create a FactoryBot file
|
46
|
+
test_files: []
|