factory_girl_rails 4.4.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +18 -22
  3. data/CONTRIBUTING.md +27 -26
  4. data/Gemfile +18 -1
  5. data/Gemfile.lock +144 -0
  6. data/NEWS +15 -0
  7. data/README.md +51 -38
  8. data/bin/setup +16 -0
  9. data/bin/stubs/a2h +16 -0
  10. data/bin/stubs/appraisal +17 -0
  11. data/bin/stubs/aruba +16 -0
  12. data/bin/stubs/autospec +17 -0
  13. data/bin/stubs/bcat +16 -0
  14. data/bin/stubs/btee +16 -0
  15. data/bin/stubs/bundler +17 -0
  16. data/bin/stubs/cdiff +16 -0
  17. data/bin/stubs/cucumber +17 -0
  18. data/bin/stubs/decolor +16 -0
  19. data/bin/stubs/erubis +17 -0
  20. data/bin/stubs/htmldiff +17 -0
  21. data/bin/stubs/ldiff +17 -0
  22. data/bin/stubs/nokogiri +16 -0
  23. data/bin/stubs/rackup +17 -0
  24. data/bin/stubs/rails +17 -0
  25. data/bin/stubs/rake +17 -0
  26. data/bin/stubs/rake2thor +16 -0
  27. data/bin/stubs/rdiscount +16 -0
  28. data/bin/stubs/rdoc +16 -0
  29. data/bin/stubs/ri +16 -0
  30. data/bin/stubs/rspec +17 -0
  31. data/bin/stubs/setup +16 -0
  32. data/bin/stubs/sprockets +16 -0
  33. data/bin/stubs/thor +17 -0
  34. data/bin/stubs/tilt +16 -0
  35. data/factory_girl_rails.gemspec +6 -13
  36. data/features/fixture_replacement_config.feature +51 -11
  37. data/features/generators.feature +40 -14
  38. data/features/load_definitions.feature +8 -8
  39. data/features/step_definitions/appraisal.rb +1 -1
  40. data/features/step_definitions/rails_steps.rb +5 -23
  41. data/features/support/env.rb +2 -2
  42. data/gemfiles/rails3.2.gemfile +14 -8
  43. data/gemfiles/rails3.2.gemfile.lock +117 -100
  44. data/gemfiles/rails4.1.gemfile +23 -0
  45. data/gemfiles/rails4.1.gemfile.lock +183 -0
  46. data/gemfiles/rails4.2.gemfile +21 -0
  47. data/gemfiles/rails4.2.gemfile.lock +193 -0
  48. data/gemfiles/rails5.0.gemfile +22 -0
  49. data/gemfiles/rails5.0.gemfile.lock +156 -0
  50. data/lib/factory_girl_rails/generators/rspec_generator.rb +1 -1
  51. data/lib/factory_girl_rails/railtie.rb +4 -0
  52. data/lib/generators/factory_girl/model/model_generator.rb +77 -9
  53. data/lib/generators/factory_girl.rb +1 -1
  54. data/pkg/factory_girl_rails-4.5.0.gem +0 -0
  55. data/tmp/aruba/testapp/Gemfile +55 -0
  56. data/tmp/aruba/testapp/Gemfile.lock +195 -0
  57. data/tmp/aruba/testapp/README.md +24 -0
  58. data/tmp/aruba/testapp/Rakefile +6 -0
  59. data/tmp/aruba/testapp/app/assets/config/manifest.js +3 -0
  60. data/tmp/aruba/testapp/app/assets/javascripts/application.js +16 -0
  61. data/tmp/aruba/testapp/app/assets/javascripts/cable.js +13 -0
  62. data/tmp/aruba/testapp/app/assets/stylesheets/application.css +15 -0
  63. data/tmp/aruba/testapp/app/channels/application_cable/channel.rb +4 -0
  64. data/tmp/aruba/testapp/app/channels/application_cable/connection.rb +4 -0
  65. data/tmp/aruba/testapp/app/controllers/application_controller.rb +3 -0
  66. data/tmp/aruba/testapp/app/helpers/application_helper.rb +2 -0
  67. data/tmp/aruba/testapp/app/jobs/application_job.rb +2 -0
  68. data/tmp/aruba/testapp/app/mailers/application_mailer.rb +4 -0
  69. data/tmp/aruba/testapp/app/models/application_record.rb +3 -0
  70. data/tmp/aruba/testapp/app/models/user.rb +2 -0
  71. data/tmp/aruba/testapp/app/views/layouts/application.html.erb +14 -0
  72. data/tmp/aruba/testapp/app/views/layouts/mailer.html.erb +13 -0
  73. data/tmp/aruba/testapp/app/views/layouts/mailer.text.erb +1 -0
  74. data/tmp/aruba/testapp/bin/bundle +3 -0
  75. data/tmp/aruba/testapp/bin/rails +9 -0
  76. data/tmp/aruba/testapp/bin/rake +9 -0
  77. data/tmp/aruba/testapp/bin/setup +34 -0
  78. data/tmp/aruba/testapp/bin/spring +17 -0
  79. data/tmp/aruba/testapp/bin/update +29 -0
  80. data/tmp/aruba/testapp/config/application.rb +16 -0
  81. data/tmp/aruba/testapp/config/boot.rb +3 -0
  82. data/tmp/aruba/testapp/config/cable.yml +9 -0
  83. data/tmp/aruba/testapp/config/database.yml +25 -0
  84. data/tmp/aruba/testapp/config/environment.rb +5 -0
  85. data/tmp/aruba/testapp/config/environments/development.rb +54 -0
  86. data/tmp/aruba/testapp/config/environments/production.rb +86 -0
  87. data/tmp/aruba/testapp/config/environments/test.rb +42 -0
  88. data/tmp/aruba/testapp/config/initializers/application_controller_renderer.rb +8 -0
  89. data/tmp/aruba/testapp/config/initializers/assets.rb +11 -0
  90. data/tmp/aruba/testapp/config/initializers/backtrace_silencers.rb +7 -0
  91. data/tmp/aruba/testapp/config/initializers/cookies_serializer.rb +5 -0
  92. data/tmp/aruba/testapp/config/initializers/filter_parameter_logging.rb +4 -0
  93. data/tmp/aruba/testapp/config/initializers/inflections.rb +16 -0
  94. data/tmp/aruba/testapp/config/initializers/mime_types.rb +4 -0
  95. data/tmp/aruba/testapp/config/initializers/new_framework_defaults.rb +26 -0
  96. data/tmp/aruba/testapp/config/initializers/session_store.rb +3 -0
  97. data/tmp/aruba/testapp/config/initializers/wrap_parameters.rb +14 -0
  98. data/tmp/aruba/testapp/config/locales/en.yml +23 -0
  99. data/tmp/aruba/testapp/config/puma.rb +47 -0
  100. data/tmp/aruba/testapp/config/routes.rb +3 -0
  101. data/tmp/aruba/testapp/config/secrets.yml +22 -0
  102. data/tmp/aruba/testapp/config/spring.rb +6 -0
  103. data/tmp/aruba/testapp/config.ru +5 -0
  104. data/tmp/aruba/testapp/db/development.sqlite3 +0 -0
  105. data/tmp/aruba/testapp/db/migrate/1_create_users.rb +7 -0
  106. data/tmp/aruba/testapp/db/schema.rb +19 -0
  107. data/tmp/aruba/testapp/db/seeds.rb +7 -0
  108. data/tmp/aruba/testapp/db/test.sqlite3 +0 -0
  109. data/tmp/aruba/testapp/lib/some_railtie/factories.rb +5 -0
  110. data/tmp/aruba/testapp/lib/some_railtie/railties.rb +8 -0
  111. data/tmp/aruba/testapp/log/development.log +16 -0
  112. data/tmp/aruba/testapp/log/test.log +21 -0
  113. data/tmp/aruba/testapp/public/404.html +67 -0
  114. data/tmp/aruba/testapp/public/422.html +67 -0
  115. data/tmp/aruba/testapp/public/500.html +66 -0
  116. data/tmp/aruba/testapp/public/apple-touch-icon-precomposed.png +0 -0
  117. data/tmp/aruba/testapp/public/apple-touch-icon.png +0 -0
  118. data/tmp/aruba/testapp/public/favicon.ico +0 -0
  119. data/tmp/aruba/testapp/public/robots.txt +5 -0
  120. data/tmp/aruba/testapp/test/test_helper.rb +10 -0
  121. data/tmp/aruba/testapp/test/unit/user_test.rb +8 -0
  122. metadata +116 -100
  123. data/.gitignore +0 -9
  124. data/.travis.yml +0 -16
  125. data/gemfiles/rails3.1.gemfile +0 -16
  126. data/gemfiles/rails3.1.gemfile.lock +0 -171
  127. data/lib/generators/factory_girl/model/templates/fixtures.erb +0 -9
@@ -0,0 +1,193 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ factory_girl_rails (4.9.0)
5
+ factory_girl (~> 4.9.0)
6
+ railties (>= 3.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.7.1)
12
+ actionpack (= 4.2.7.1)
13
+ actionview (= 4.2.7.1)
14
+ activejob (= 4.2.7.1)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.7.1)
18
+ actionview (= 4.2.7.1)
19
+ activesupport (= 4.2.7.1)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.7.1)
25
+ activesupport (= 4.2.7.1)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ activejob (4.2.7.1)
31
+ activesupport (= 4.2.7.1)
32
+ globalid (>= 0.3.0)
33
+ activemodel (4.2.7.1)
34
+ activesupport (= 4.2.7.1)
35
+ builder (~> 3.1)
36
+ activerecord (4.2.7.1)
37
+ activemodel (= 4.2.7.1)
38
+ activesupport (= 4.2.7.1)
39
+ arel (~> 6.0)
40
+ activesupport (4.2.7.1)
41
+ i18n (~> 0.7)
42
+ json (~> 1.7, >= 1.7.7)
43
+ minitest (~> 5.1)
44
+ thread_safe (~> 0.3, >= 0.3.4)
45
+ tzinfo (~> 1.1)
46
+ appraisal (2.1.0)
47
+ bundler
48
+ rake
49
+ thor (>= 0.14.0)
50
+ arel (6.0.4)
51
+ aruba (0.14.2)
52
+ childprocess (~> 0.5.6)
53
+ contracts (~> 0.9)
54
+ cucumber (>= 1.3.19)
55
+ ffi (~> 1.9.10)
56
+ rspec-expectations (>= 2.99)
57
+ thor (~> 0.19)
58
+ builder (3.2.3)
59
+ childprocess (0.5.9)
60
+ ffi (~> 1.0, >= 1.0.11)
61
+ coffee-rails (4.2.2)
62
+ coffee-script (>= 2.2.0)
63
+ railties (>= 4.0.0)
64
+ coffee-script (2.4.1)
65
+ coffee-script-source
66
+ execjs
67
+ coffee-script-source (1.12.2)
68
+ concurrent-ruby (1.0.5)
69
+ contracts (0.16.0)
70
+ crass (1.0.2)
71
+ cucumber (1.3.19)
72
+ builder (>= 2.1.2)
73
+ diff-lcs (>= 1.1.3)
74
+ gherkin (~> 2.12)
75
+ multi_json (>= 1.7.5, < 2.0)
76
+ multi_test (>= 0.1.2)
77
+ diff-lcs (1.3)
78
+ erubis (2.7.0)
79
+ execjs (2.7.0)
80
+ factory_girl (4.9.0)
81
+ activesupport (>= 3.0.0)
82
+ ffi (1.9.18)
83
+ gherkin (2.12.2)
84
+ multi_json (~> 1.3)
85
+ globalid (0.4.0)
86
+ activesupport (>= 4.2.0)
87
+ i18n (0.9.0)
88
+ concurrent-ruby (~> 1.0)
89
+ jquery-rails (4.3.1)
90
+ rails-dom-testing (>= 1, < 3)
91
+ railties (>= 4.2.0)
92
+ thor (>= 0.14, < 2.0)
93
+ json (1.8.6)
94
+ loofah (2.1.1)
95
+ crass (~> 1.0.2)
96
+ nokogiri (>= 1.5.9)
97
+ mail (2.6.6)
98
+ mime-types (>= 1.16, < 4)
99
+ mime-types (3.1)
100
+ mime-types-data (~> 3.2015)
101
+ mime-types-data (3.2016.0521)
102
+ mini_portile2 (2.3.0)
103
+ minitest (5.10.3)
104
+ multi_json (1.12.2)
105
+ multi_test (0.1.2)
106
+ nokogiri (1.8.1)
107
+ mini_portile2 (~> 2.3.0)
108
+ power_assert (0.3.0)
109
+ rack (1.6.8)
110
+ rack-test (0.6.3)
111
+ rack (>= 1.0)
112
+ rails (4.2.7.1)
113
+ actionmailer (= 4.2.7.1)
114
+ actionpack (= 4.2.7.1)
115
+ actionview (= 4.2.7.1)
116
+ activejob (= 4.2.7.1)
117
+ activemodel (= 4.2.7.1)
118
+ activerecord (= 4.2.7.1)
119
+ activesupport (= 4.2.7.1)
120
+ bundler (>= 1.3.0, < 2.0)
121
+ railties (= 4.2.7.1)
122
+ sprockets-rails
123
+ rails-deprecated_sanitizer (1.0.3)
124
+ activesupport (>= 4.2.0.alpha)
125
+ rails-dom-testing (1.0.8)
126
+ activesupport (>= 4.2.0.beta, < 5.0)
127
+ nokogiri (~> 1.6)
128
+ rails-deprecated_sanitizer (>= 1.0.1)
129
+ rails-html-sanitizer (1.0.3)
130
+ loofah (~> 2.0)
131
+ railties (4.2.7.1)
132
+ actionpack (= 4.2.7.1)
133
+ activesupport (= 4.2.7.1)
134
+ rake (>= 0.8.7)
135
+ thor (>= 0.18.1, < 2.0)
136
+ rake (12.1.0)
137
+ rspec-core (3.7.0)
138
+ rspec-support (~> 3.7.0)
139
+ rspec-expectations (3.7.0)
140
+ diff-lcs (>= 1.2.0, < 2.0)
141
+ rspec-support (~> 3.7.0)
142
+ rspec-mocks (3.7.0)
143
+ diff-lcs (>= 1.2.0, < 2.0)
144
+ rspec-support (~> 3.7.0)
145
+ rspec-rails (3.7.0)
146
+ actionpack (>= 3.0)
147
+ activesupport (>= 3.0)
148
+ railties (>= 3.0)
149
+ rspec-core (~> 3.7.0)
150
+ rspec-expectations (~> 3.7.0)
151
+ rspec-mocks (~> 3.7.0)
152
+ rspec-support (~> 3.7.0)
153
+ rspec-support (3.7.0)
154
+ sprockets (3.7.1)
155
+ concurrent-ruby (~> 1.0)
156
+ rack (> 1, < 3)
157
+ sprockets-rails (3.2.1)
158
+ actionpack (>= 4.0)
159
+ activesupport (>= 4.0)
160
+ sprockets (>= 3.0.0)
161
+ sqlite3 (1.3.13)
162
+ test-unit (3.2.0)
163
+ power_assert
164
+ thor (0.20.0)
165
+ thread_safe (0.3.6)
166
+ tzinfo (1.2.3)
167
+ thread_safe (~> 0.1)
168
+ uglifier (3.2.0)
169
+ execjs (>= 0.3.0, < 3)
170
+
171
+ PLATFORMS
172
+ ruby
173
+
174
+ DEPENDENCIES
175
+ activerecord-jdbcsqlite3-adapter
176
+ appraisal
177
+ aruba
178
+ coffee-rails
179
+ cucumber (= 1.3.19)
180
+ factory_girl_rails!
181
+ jdbc-sqlite3
182
+ jquery-rails
183
+ jruby-openssl
184
+ rails (~> 4.2.0)
185
+ rake
186
+ rspec-rails
187
+ sqlite3
188
+ test-unit
189
+ therubyrhino
190
+ uglifier
191
+
192
+ BUNDLED WITH
193
+ 1.13.6
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "aruba"
7
+ gem "coffee-rails"
8
+ gem "cucumber", "1.3.19"
9
+ gem "jquery-rails"
10
+ gem "rake"
11
+ gem "rspec-rails", "~> 3.5.0.beta4"
12
+ gem "uglifier"
13
+ gem "test-unit"
14
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
15
+ gem "jdbc-sqlite3", :platforms => :jruby
16
+ gem "therubyrhino", :platforms => :jruby
17
+ gem "jruby-openssl", :platforms => :jruby
18
+ gem "sqlite3", :platforms => :ruby
19
+ gem "activerecord", "~> 5.0.0"
20
+ gem "railties", "~> 5.0.0"
21
+
22
+ gemspec :path => "../"
@@ -0,0 +1,156 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ factory_girl_rails (4.9.0)
5
+ factory_girl (~> 4.9.0)
6
+ railties (>= 3.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (5.0.6)
12
+ actionview (= 5.0.6)
13
+ activesupport (= 5.0.6)
14
+ rack (~> 2.0)
15
+ rack-test (~> 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.0.6)
19
+ activesupport (= 5.0.6)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
+ activemodel (5.0.6)
25
+ activesupport (= 5.0.6)
26
+ activerecord (5.0.6)
27
+ activemodel (= 5.0.6)
28
+ activesupport (= 5.0.6)
29
+ arel (~> 7.0)
30
+ activesupport (5.0.6)
31
+ concurrent-ruby (~> 1.0, >= 1.0.2)
32
+ i18n (~> 0.7)
33
+ minitest (~> 5.1)
34
+ tzinfo (~> 1.1)
35
+ appraisal (2.1.0)
36
+ bundler
37
+ rake
38
+ thor (>= 0.14.0)
39
+ arel (7.1.4)
40
+ aruba (0.14.2)
41
+ childprocess (~> 0.5.6)
42
+ contracts (~> 0.9)
43
+ cucumber (>= 1.3.19)
44
+ ffi (~> 1.9.10)
45
+ rspec-expectations (>= 2.99)
46
+ thor (~> 0.19)
47
+ builder (3.2.3)
48
+ childprocess (0.5.9)
49
+ ffi (~> 1.0, >= 1.0.11)
50
+ coffee-rails (4.2.2)
51
+ coffee-script (>= 2.2.0)
52
+ railties (>= 4.0.0)
53
+ coffee-script (2.4.1)
54
+ coffee-script-source
55
+ execjs
56
+ coffee-script-source (1.12.2)
57
+ concurrent-ruby (1.0.5)
58
+ contracts (0.16.0)
59
+ crass (1.0.2)
60
+ cucumber (1.3.19)
61
+ builder (>= 2.1.2)
62
+ diff-lcs (>= 1.1.3)
63
+ gherkin (~> 2.12)
64
+ multi_json (>= 1.7.5, < 2.0)
65
+ multi_test (>= 0.1.2)
66
+ diff-lcs (1.3)
67
+ erubis (2.7.0)
68
+ execjs (2.7.0)
69
+ factory_girl (4.9.0)
70
+ activesupport (>= 3.0.0)
71
+ ffi (1.9.18)
72
+ gherkin (2.12.2)
73
+ multi_json (~> 1.3)
74
+ i18n (0.9.0)
75
+ concurrent-ruby (~> 1.0)
76
+ jquery-rails (4.3.1)
77
+ rails-dom-testing (>= 1, < 3)
78
+ railties (>= 4.2.0)
79
+ thor (>= 0.14, < 2.0)
80
+ loofah (2.1.1)
81
+ crass (~> 1.0.2)
82
+ nokogiri (>= 1.5.9)
83
+ method_source (0.9.0)
84
+ mini_portile2 (2.3.0)
85
+ minitest (5.10.3)
86
+ multi_json (1.12.2)
87
+ multi_test (0.1.2)
88
+ nokogiri (1.8.1)
89
+ mini_portile2 (~> 2.3.0)
90
+ power_assert (0.3.0)
91
+ rack (2.0.3)
92
+ rack-test (0.6.3)
93
+ rack (>= 1.0)
94
+ rails-dom-testing (2.0.3)
95
+ activesupport (>= 4.2.0)
96
+ nokogiri (>= 1.6)
97
+ rails-html-sanitizer (1.0.3)
98
+ loofah (~> 2.0)
99
+ railties (5.0.6)
100
+ actionpack (= 5.0.6)
101
+ activesupport (= 5.0.6)
102
+ method_source
103
+ rake (>= 0.8.7)
104
+ thor (>= 0.18.1, < 2.0)
105
+ rake (12.1.0)
106
+ rspec-core (3.5.4)
107
+ rspec-support (~> 3.5.0)
108
+ rspec-expectations (3.5.0)
109
+ diff-lcs (>= 1.2.0, < 2.0)
110
+ rspec-support (~> 3.5.0)
111
+ rspec-mocks (3.5.0)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.5.0)
114
+ rspec-rails (3.5.2)
115
+ actionpack (>= 3.0)
116
+ activesupport (>= 3.0)
117
+ railties (>= 3.0)
118
+ rspec-core (~> 3.5.0)
119
+ rspec-expectations (~> 3.5.0)
120
+ rspec-mocks (~> 3.5.0)
121
+ rspec-support (~> 3.5.0)
122
+ rspec-support (3.5.0)
123
+ sqlite3 (1.3.13)
124
+ test-unit (3.2.0)
125
+ power_assert
126
+ thor (0.20.0)
127
+ thread_safe (0.3.6)
128
+ tzinfo (1.2.3)
129
+ thread_safe (~> 0.1)
130
+ uglifier (3.2.0)
131
+ execjs (>= 0.3.0, < 3)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ activerecord (~> 5.0.0)
138
+ activerecord-jdbcsqlite3-adapter
139
+ appraisal
140
+ aruba
141
+ coffee-rails
142
+ cucumber (= 1.3.19)
143
+ factory_girl_rails!
144
+ jdbc-sqlite3
145
+ jquery-rails
146
+ jruby-openssl
147
+ railties (~> 5.0.0)
148
+ rake
149
+ rspec-rails (~> 3.5.0.beta4)
150
+ sqlite3
151
+ test-unit
152
+ therubyrhino
153
+ uglifier
154
+
155
+ BUNDLED WITH
156
+ 1.13.6
@@ -16,7 +16,7 @@ module FactoryGirlRails
16
16
  end
17
17
 
18
18
  def factory_girl_directory
19
- @generators.options.fetch(:factory_girl, { dir: 'spec/factories' })[:dir]
19
+ @generators.options.fetch(:factory_girl, {}).fetch(:dir, 'spec/factories')
20
20
  end
21
21
  end
22
22
  end
@@ -19,6 +19,10 @@ module FactoryGirl
19
19
 
20
20
  config.after_initialize do
21
21
  FactoryGirl.find_definitions
22
+
23
+ if defined?(Spring)
24
+ Spring.after_fork { FactoryGirl.reload }
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -4,28 +4,96 @@ require 'factory_girl_rails'
4
4
  module FactoryGirl
5
5
  module Generators
6
6
  class ModelGenerator < Base
7
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
8
- class_option :dir, :type => :string, :default => "test/factories", :desc => "The directory where the factories should go"
7
+ argument(
8
+ :attributes,
9
+ type: :array,
10
+ default: [],
11
+ banner: "field:type field:type"
12
+ )
13
+
14
+ class_option(
15
+ :dir,
16
+ type: :string,
17
+ default: "test/factories",
18
+ desc: "The directory or file root where factories belong"
19
+ )
20
+
21
+ class_option(
22
+ :suffix,
23
+ type: :string,
24
+ default: nil,
25
+ desc: "Suffix to add factory file"
26
+ )
9
27
 
10
28
  def create_fixture_file
11
- filename = [table_name, filename_suffix].compact.join('_')
12
- template 'fixtures.erb', File.join(options[:dir], "#{filename}.rb")
29
+ if File.exist?(factories_file)
30
+ insert_factory_into_existing_file
31
+ else
32
+ create_factory_file
33
+ end
13
34
  end
14
35
 
15
36
  private
16
37
 
17
- def filename_suffix
18
- factory_girl_options[:suffix]
38
+ def factories_file
39
+ options[:dir] + ".rb"
19
40
  end
20
41
 
21
- def generators
22
- config = FactoryGirl::Railtie.config
23
- config.respond_to?(:app_generators) ? config.app_generators : config.generators
42
+ def insert_factory_into_existing_file
43
+ insert_into_file(
44
+ factories_file,
45
+ factory_definition,
46
+ after: "FactoryGirl.define do\n"
47
+ )
48
+ end
49
+
50
+ def create_factory_file
51
+ file = File.join(options[:dir], "#{filename}.rb")
52
+ create_file(file, single_file_factory_definition)
53
+ end
54
+
55
+ def factory_definition
56
+ <<-RUBY
57
+ factory :#{singular_table_name}#{explicit_class_option} do
58
+ #{factory_attributes.gsub(/^/, " ")}
59
+ end
60
+ RUBY
61
+ end
62
+
63
+ def single_file_factory_definition
64
+ <<-RUBY
65
+ FactoryGirl.define do
66
+ #{factory_definition.chomp}
67
+ end
68
+ RUBY
69
+ end
70
+
71
+ def factory_attributes
72
+ attributes.map do |attribute|
73
+ "#{attribute.name} #{attribute.default.inspect}"
74
+ end.join("\n")
75
+ end
76
+
77
+ def filename
78
+ if factory_girl_options[:filename_proc].present?
79
+ factory_girl_options[:filename_proc].call(table_name)
80
+ else
81
+ [table_name, filename_suffix].compact.join('_')
82
+ end
83
+ end
84
+
85
+ def filename_suffix
86
+ factory_girl_options[:suffix] || options[:suffix]
24
87
  end
25
88
 
26
89
  def factory_girl_options
27
90
  generators.options[:factory_girl] || {}
28
91
  end
92
+
93
+ def generators
94
+ config = FactoryGirl::Railtie.config
95
+ config.respond_to?(:app_generators) ? config.app_generators : config.generators
96
+ end
29
97
  end
30
98
  end
31
99
  end
@@ -8,7 +8,7 @@ module FactoryGirl
8
8
  end
9
9
 
10
10
  def explicit_class_option
11
- ", :class => '#{class_name}'" unless class_name == singular_table_name.camelize
11
+ ", class: '#{class_name}'" unless class_name == singular_table_name.camelize
12
12
  end
13
13
  end
14
14
  end
Binary file
@@ -0,0 +1,55 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+
9
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
10
+ gem 'rails', '~> 5.0.6'
11
+ # Use sqlite3 as the database for Active Record
12
+ gem 'sqlite3'
13
+ # Use Puma as the app server
14
+ gem 'puma', '~> 3.0'
15
+ # Use SCSS for stylesheets
16
+ gem 'sass-rails', '~> 5.0'
17
+ # Use Uglifier as compressor for JavaScript assets
18
+ gem 'uglifier', '>= 1.3.0'
19
+ # Use CoffeeScript for .coffee assets and views
20
+ gem 'coffee-rails', '~> 4.2'
21
+ # See https://github.com/rails/execjs#readme for more supported runtimes
22
+ # gem 'therubyracer', platforms: :ruby
23
+
24
+ # Use jquery as the JavaScript library
25
+ gem 'jquery-rails'
26
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
27
+ gem 'turbolinks', '~> 5'
28
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
29
+ gem 'jbuilder', '~> 2.5'
30
+ # Use Redis adapter to run Action Cable in production
31
+ # gem 'redis', '~> 3.0'
32
+ # Use ActiveModel has_secure_password
33
+ # gem 'bcrypt', '~> 3.1.7'
34
+
35
+ # Use Capistrano for deployment
36
+ # gem 'capistrano-rails', group: :development
37
+
38
+ group :development, :test do
39
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
40
+ gem 'byebug', platform: :mri
41
+ end
42
+
43
+ group :development do
44
+ # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
45
+ gem 'web-console', '>= 3.3.0'
46
+ gem 'listen', '~> 3.0.5'
47
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
48
+ gem 'spring'
49
+ gem 'spring-watcher-listen', '~> 2.0.0'
50
+ end
51
+
52
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
53
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
54
+ gem "factory_girl_rails", :path => "/Users/joshuaclayton/dev/gems/factory_bot_rails"
55
+ gem "test-unit"