Method: Test::Unit::TestCase#setup_fixture_files
- Defined in:
- lib/test_case.rb
#setup_fixture_files ⇒ Object
Copies the fixture files from “RAILS_ROOT/test/fixtures/file_column” into the temporary storage directory used for testing (“RAILS_ROOT/test/tmp/file_column”). Call this method in your setup methods to get the file fixtures (images, for example) into the directory used by file_column in testing.
Note that the files and directories in the “fixtures/file_column” directory must have the same structure as you would expect in your “/public” directory after uploading with FileColumn.
For example, the directory structure could look like this:
test/fixtures/file_column/
`-- container
|-- first_image
| |-- 1
| | `-- image1.jpg
| `-- tmp
`-- second_image
|-- 1
| `-- image2.jpg
`-- tmp
Your fixture file for this one “container” class fixture could look like this:
first:
id: 1
first_image: image1.jpg
second_image: image1.jpg
A usage example:
def setup
setup_fixture_files
# ...
end
72 73 74 75 76 77 78 |
# File 'lib/test_case.rb', line 72 def setup_fixture_files tmp_path = File.join(RAILS_ROOT, "test", "tmp", "file_column") file_fixtures = Dir.glob File.join(RAILS_ROOT, "test", "fixtures", "file_column", "*") FileUtils.mkdir_p tmp_path unless File.exists?(tmp_path) FileUtils.cp_r file_fixtures, tmp_path end |