Skip to content

Commit a351079

Browse files
committed
Support file_fixture in Factory definitions
Related to [factory_bot#1282][] [rails/rails#45606][] has been merged and is likely to be released as part of Rails 7.1. With that addition, the path toward resolving [factory_bot#1282][] becomes more clear. If factories can pass along [Pathname][] instances to attachment attributes, Active Support will handle the rest. Instances of `ActiveSupport::TestCase` provide a [file_fixture][] helper to construct a `Pathname` instance based on the path defined by `ActiveSupport::TestCase.file_fixture_path` (relative to the Rails root directory). [factory_bot#1282]: thoughtbot/factory_bot#1282 (comment) [rails/rails#45606]: rails/rails#45606 [Pathname]: https://docs.ruby-lang.org/en/master/Pathname.html [file_fixture]: https://api.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
1 parent 346e3c7 commit a351079

File tree

14 files changed

+304
-171
lines changed

14 files changed

+304
-171
lines changed

Gemfile.lock

Lines changed: 140 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,128 +8,148 @@ PATH
88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
actionpack (7.1.2)
12-
actionview (= 7.1.2)
13-
activesupport (= 7.1.2)
11+
actionpack (7.2.2)
12+
actionview (= 7.2.2)
13+
activesupport (= 7.2.2)
1414
nokogiri (>= 1.8.5)
1515
racc
16-
rack (>= 2.2.4)
16+
rack (>= 2.2.4, < 3.2)
1717
rack-session (>= 1.0.1)
1818
rack-test (>= 0.6.3)
1919
rails-dom-testing (~> 2.2)
2020
rails-html-sanitizer (~> 1.6)
21-
actionview (7.1.2)
22-
activesupport (= 7.1.2)
21+
useragent (~> 0.16)
22+
actionview (7.2.2)
23+
activesupport (= 7.2.2)
2324
builder (~> 3.1)
2425
erubi (~> 1.11)
2526
rails-dom-testing (~> 2.2)
2627
rails-html-sanitizer (~> 1.6)
27-
activemodel (7.1.2)
28-
activesupport (= 7.1.2)
29-
activerecord (7.1.2)
30-
activemodel (= 7.1.2)
31-
activesupport (= 7.1.2)
28+
activejob (7.2.2)
29+
activesupport (= 7.2.2)
30+
globalid (>= 0.3.6)
31+
activemodel (7.2.2)
32+
activesupport (= 7.2.2)
33+
activerecord (7.2.2)
34+
activemodel (= 7.2.2)
35+
activesupport (= 7.2.2)
3236
timeout (>= 0.4.0)
33-
activesupport (7.1.2)
37+
activestorage (7.2.2)
38+
actionpack (= 7.2.2)
39+
activejob (= 7.2.2)
40+
activerecord (= 7.2.2)
41+
activesupport (= 7.2.2)
42+
marcel (~> 1.0)
43+
activesupport (7.2.2)
3444
base64
45+
benchmark (>= 0.3)
3546
bigdecimal
36-
concurrent-ruby (~> 1.0, >= 1.0.2)
47+
concurrent-ruby (~> 1.0, >= 1.3.1)
3748
connection_pool (>= 2.2.5)
3849
drb
3950
i18n (>= 1.6, < 2)
51+
logger (>= 1.4.2)
4052
minitest (>= 5.1)
41-
mutex_m
42-
tzinfo (~> 2.0)
53+
securerandom (>= 0.3)
54+
tzinfo (~> 2.0, >= 2.0.5)
4355
appraisal (2.5.0)
4456
bundler
4557
rake
4658
thor (>= 0.14.0)
47-
aruba (2.1.0)
59+
aruba (2.2.0)
4860
bundler (>= 1.17, < 3.0)
49-
childprocess (>= 2.0, < 5.0)
5061
contracts (>= 0.16.0, < 0.18.0)
51-
cucumber (>= 4.0, < 9.0)
62+
cucumber (>= 8.0, < 10.0)
5263
rspec-expectations (~> 3.4)
5364
thor (~> 1.0)
5465
ast (2.4.2)
5566
base64 (0.2.0)
67+
benchmark (0.3.0)
5668
bigdecimal (3.1.8)
57-
bigdecimal (3.1.8-java)
5869
builder (3.3.0)
59-
childprocess (4.1.0)
6070
concurrent-ruby (1.3.4)
6171
connection_pool (2.4.1)
62-
contracts (0.17)
72+
contracts (0.17.2)
6373
crass (1.0.6)
64-
cucumber (8.0.0)
65-
builder (~> 3.2, >= 3.2.4)
66-
cucumber-ci-environment (~> 9.0, >= 9.0.4)
67-
cucumber-core (~> 11.0, >= 11.0.0)
68-
cucumber-cucumber-expressions (~> 15.1, >= 15.1.1)
69-
cucumber-gherkin (~> 23.0, >= 23.0.1)
70-
cucumber-html-formatter (~> 19.1, >= 19.1.0)
71-
cucumber-messages (~> 18.0, >= 18.0.0)
72-
diff-lcs (~> 1.5, >= 1.5.0)
73-
mime-types (~> 3.4, >= 3.4.1)
74-
multi_test (~> 1.1, >= 1.1.0)
75-
sys-uname (~> 1.2, >= 1.2.2)
76-
cucumber-ci-environment (9.1.0)
77-
cucumber-core (11.0.0)
78-
cucumber-gherkin (~> 23.0, >= 23.0.1)
79-
cucumber-messages (~> 18.0, >= 18.0.0)
80-
cucumber-tag-expressions (~> 4.1, >= 4.1.0)
81-
cucumber-cucumber-expressions (15.2.0)
82-
cucumber-gherkin (23.0.1)
83-
cucumber-messages (~> 18.0, >= 18.0.0)
84-
cucumber-html-formatter (19.2.0)
85-
cucumber-messages (~> 18.0, >= 18.0.0)
86-
cucumber-messages (18.0.0)
87-
cucumber-tag-expressions (4.1.0)
74+
cucumber (9.2.0)
75+
builder (~> 3.2)
76+
cucumber-ci-environment (> 9, < 11)
77+
cucumber-core (> 13, < 14)
78+
cucumber-cucumber-expressions (~> 17.0)
79+
cucumber-gherkin (> 24, < 28)
80+
cucumber-html-formatter (> 20.3, < 22)
81+
cucumber-messages (> 19, < 25)
82+
diff-lcs (~> 1.5)
83+
mini_mime (~> 1.1)
84+
multi_test (~> 1.1)
85+
sys-uname (~> 1.2)
86+
cucumber-ci-environment (10.0.1)
87+
cucumber-core (13.0.3)
88+
cucumber-gherkin (>= 27, < 28)
89+
cucumber-messages (>= 20, < 23)
90+
cucumber-tag-expressions (> 5, < 7)
91+
cucumber-cucumber-expressions (17.1.0)
92+
bigdecimal
93+
cucumber-gherkin (27.0.0)
94+
cucumber-messages (>= 19.1.4, < 23)
95+
cucumber-html-formatter (21.7.0)
96+
cucumber-messages (> 19, < 27)
97+
cucumber-messages (22.0.0)
98+
cucumber-tag-expressions (6.1.1)
8899
diff-lcs (1.5.1)
89100
drb (2.2.1)
90101
erubi (1.13.0)
91102
factory_bot (6.5.0)
92103
activesupport (>= 5.0.0)
93-
ffi (1.15.5)
94-
ffi (1.15.5-java)
95-
i18n (1.14.5)
104+
ffi (1.17.0-aarch64-linux-gnu)
105+
ffi (1.17.0-aarch64-linux-musl)
106+
ffi (1.17.0-arm-linux-gnu)
107+
ffi (1.17.0-arm-linux-musl)
108+
ffi (1.17.0-arm64-darwin)
109+
ffi (1.17.0-x86-linux-gnu)
110+
ffi (1.17.0-x86-linux-musl)
111+
ffi (1.17.0-x86_64-darwin)
112+
ffi (1.17.0-x86_64-linux-gnu)
113+
ffi (1.17.0-x86_64-linux-musl)
114+
globalid (1.2.1)
115+
activesupport (>= 6.1)
116+
i18n (1.14.6)
96117
concurrent-ruby (~> 1.0)
97118
io-console (0.7.2)
98-
io-console (0.7.2-java)
99-
irb (1.14.0)
119+
irb (1.14.1)
100120
rdoc (>= 4.0.0)
101121
reline (>= 0.4.2)
102-
jar-dependencies (0.4.1)
103-
json (2.7.2)
104-
json (2.7.2-java)
122+
json (2.7.5)
105123
language_server-protocol (3.17.0.3)
106124
lint_roller (1.1.0)
107-
loofah (2.22.0)
125+
logger (1.6.1)
126+
loofah (2.23.1)
108127
crass (~> 1.0.2)
109128
nokogiri (>= 1.12.0)
110-
mime-types (3.4.1)
111-
mime-types-data (~> 3.2015)
112-
mime-types-data (3.2023.0218.1)
113-
mini_portile2 (2.8.7)
129+
marcel (1.0.4)
130+
mini_mime (1.1.5)
114131
minitest (5.25.1)
115132
multi_test (1.1.0)
116-
mutex_m (0.2.0)
117-
nokogiri (1.16.7)
118-
mini_portile2 (~> 2.8.2)
133+
nokogiri (1.16.7-aarch64-linux)
134+
racc (~> 1.4)
135+
nokogiri (1.16.7-arm-linux)
136+
racc (~> 1.4)
137+
nokogiri (1.16.7-arm64-darwin)
119138
racc (~> 1.4)
120-
nokogiri (1.16.7-java)
139+
nokogiri (1.16.7-x86-linux)
140+
racc (~> 1.4)
141+
nokogiri (1.16.7-x86_64-darwin)
142+
racc (~> 1.4)
143+
nokogiri (1.16.7-x86_64-linux)
121144
racc (~> 1.4)
122145
parallel (1.26.3)
123-
parser (3.3.4.2)
146+
parser (3.3.5.1)
124147
ast (~> 2.4.1)
125148
racc
126149
psych (5.1.2)
127150
stringio
128-
psych (5.1.2-java)
129-
jar-dependencies (>= 0.1.7)
130151
racc (1.8.1)
131-
racc (1.8.1-java)
132-
rack (3.1.7)
152+
rack (3.1.8)
133153
rack-session (2.0.0)
134154
rack (>= 3.0.0)
135155
rack-test (2.1.0)
@@ -144,10 +164,10 @@ GEM
144164
rails-html-sanitizer (1.6.0)
145165
loofah (~> 2.21)
146166
nokogiri (~> 1.14)
147-
railties (7.1.2)
148-
actionpack (= 7.1.2)
149-
activesupport (= 7.1.2)
150-
irb
167+
railties (7.2.2)
168+
actionpack (= 7.2.2)
169+
activesupport (= 7.2.2)
170+
irb (~> 1.13)
151171
rackup (>= 1.0.0)
152172
rake (>= 12.2)
153173
thor (~> 1.0, >= 1.2.2)
@@ -157,77 +177,95 @@ GEM
157177
rdoc (6.7.0)
158178
psych (>= 4.0.0)
159179
regexp_parser (2.9.2)
160-
reline (0.5.9)
180+
reline (0.5.10)
161181
io-console (~> 0.5)
162-
rexml (3.3.6)
163-
strscan
164-
rspec-core (3.13.0)
182+
rspec-core (3.13.2)
165183
rspec-support (~> 3.13.0)
166-
rspec-expectations (3.13.2)
184+
rspec-expectations (3.13.3)
167185
diff-lcs (>= 1.2.0, < 2.0)
168186
rspec-support (~> 3.13.0)
169-
rspec-mocks (3.13.1)
187+
rspec-mocks (3.13.2)
170188
diff-lcs (>= 1.2.0, < 2.0)
171189
rspec-support (~> 3.13.0)
172-
rspec-rails (6.1.4)
173-
actionpack (>= 6.1)
174-
activesupport (>= 6.1)
175-
railties (>= 6.1)
190+
rspec-rails (7.0.1)
191+
actionpack (>= 7.0)
192+
activesupport (>= 7.0)
193+
railties (>= 7.0)
176194
rspec-core (~> 3.13)
177195
rspec-expectations (~> 3.13)
178196
rspec-mocks (~> 3.13)
179197
rspec-support (~> 3.13)
180198
rspec-support (3.13.1)
181-
rubocop (1.65.1)
199+
rubocop (1.66.1)
182200
json (~> 2.3)
183201
language_server-protocol (>= 3.17.0)
184202
parallel (~> 1.10)
185203
parser (>= 3.3.0.2)
186204
rainbow (>= 2.2.2, < 4.0)
187205
regexp_parser (>= 2.4, < 3.0)
188-
rexml (>= 3.2.5, < 4.0)
189-
rubocop-ast (>= 1.31.1, < 2.0)
206+
rubocop-ast (>= 1.32.2, < 2.0)
190207
ruby-progressbar (~> 1.7)
191208
unicode-display_width (>= 2.4.0, < 3.0)
192-
rubocop-ast (1.32.1)
209+
rubocop-ast (1.33.0)
193210
parser (>= 3.3.1.0)
194-
rubocop-performance (1.21.1)
211+
rubocop-performance (1.22.1)
195212
rubocop (>= 1.48.1, < 2.0)
196213
rubocop-ast (>= 1.31.1, < 2.0)
197214
ruby-progressbar (1.13.0)
198-
sqlite3 (1.6.2)
199-
mini_portile2 (~> 2.8.0)
200-
standard (1.40.0)
215+
securerandom (0.3.1)
216+
sqlite3 (2.2.0-aarch64-linux-gnu)
217+
sqlite3 (2.2.0-aarch64-linux-musl)
218+
sqlite3 (2.2.0-arm-linux-gnu)
219+
sqlite3 (2.2.0-arm-linux-musl)
220+
sqlite3 (2.2.0-arm64-darwin)
221+
sqlite3 (2.2.0-x86-linux-gnu)
222+
sqlite3 (2.2.0-x86-linux-musl)
223+
sqlite3 (2.2.0-x86_64-darwin)
224+
sqlite3 (2.2.0-x86_64-linux-gnu)
225+
sqlite3 (2.2.0-x86_64-linux-musl)
226+
standard (1.41.1)
201227
language_server-protocol (~> 3.17.0.2)
202228
lint_roller (~> 1.0)
203-
rubocop (~> 1.65.0)
229+
rubocop (~> 1.66.0)
204230
standard-custom (~> 1.0.0)
205-
standard-performance (~> 1.4)
231+
standard-performance (~> 1.5)
206232
standard-custom (1.0.2)
207233
lint_roller (~> 1.0)
208234
rubocop (~> 1.50)
209-
standard-performance (1.4.0)
235+
standard-performance (1.5.0)
210236
lint_roller (~> 1.1)
211-
rubocop-performance (~> 1.21.0)
237+
rubocop-performance (~> 1.22.0)
212238
stringio (3.1.1)
213-
strscan (3.1.0)
214-
strscan (3.1.0-java)
215-
sys-uname (1.2.3)
239+
sys-uname (1.3.0)
216240
ffi (~> 1.1)
217241
thor (1.3.2)
218-
timeout (0.4.1)
242+
timeout (0.4.2)
219243
tzinfo (2.0.6)
220244
concurrent-ruby (~> 1.0)
221-
unicode-display_width (2.5.0)
222-
webrick (1.8.1)
223-
zeitwerk (2.6.17)
245+
unicode-display_width (2.6.0)
246+
useragent (0.16.10)
247+
webrick (1.8.2)
248+
zeitwerk (2.7.1)
224249

225250
PLATFORMS
226-
java
227-
ruby
251+
aarch64-linux
252+
aarch64-linux-gnu
253+
aarch64-linux-musl
254+
arm-linux
255+
arm-linux-gnu
256+
arm-linux-musl
257+
arm64-darwin
258+
x86-linux
259+
x86-linux-gnu
260+
x86-linux-musl
261+
x86_64-darwin
262+
x86_64-linux
263+
x86_64-linux-gnu
264+
x86_64-linux-musl
228265

229266
DEPENDENCIES
230267
activerecord (>= 5.0.0)
268+
activestorage (>= 5.0.0)
231269
appraisal
232270
aruba
233271
cucumber

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ using an empty array:
8484
config.factory_bot.definition_file_paths = []
8585
```
8686

87+
### File Fixture Support
88+
89+
Factories have access to [ActiveSupport::Testing::FileFixtures#file_fixture][]
90+
helper to read files from tests.
91+
92+
To disable file fixture support, set `file_fixture_support = false`:
93+
94+
```rb
95+
config.factory_bot.file_fixture_support = false
96+
```
97+
98+
[ActiveSupport::Testing::FileFixtures#file_fixture]: https://api.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
99+
87100
### Generators
88101

89102
Including factory\_bot\_rails in the development group of your Gemfile

Rakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "bundler/setup"
22
require "cucumber/rake/task"
33
require "rspec/core/rake_task"
4+
require "minitest/test_task"
45
require "standard/rake"
56

67
Bundler::GemHelper.install_tasks name: "factory_bot_rails"
@@ -12,5 +13,7 @@ end
1213

1314
RSpec::Core::RakeTask.new(:spec)
1415

16+
Minitest::TestTask.create
17+
1518
desc "Run the test suite and standard"
16-
task default: %w[spec cucumber standard]
19+
task default: %w[spec test cucumber standard]

0 commit comments

Comments
 (0)