Forum: Ruby on Rails file_column with both root_path and store_dir

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4bc282522ae33709ea17e4dab3a3fe7d?d=identicon&s=25 Ryan Heneise (Guest)
on 2006-01-17 09:17
(Received via mailing list)
I store my file_column database outside of my RAILS_ROOT.

It seems to work in real life, but not in tests.

In the tests, I can't set both the root_path and the store_dir. In
tests, setting the store_dir option will override the root_path
option. The only way for root_path to work is to remove store_dir. I
think the problem is in file_column.rb on line 22:
   options[:store_dir] ||= File.join(options[:root_path], model, attr)


Here's my test:

   def test_absolute_path_outside_rails_root
     # We might want to store our files on another file system
     # We also want to give the user their own directory
     Entry.file_column :image, {:root_path => "/u/
file_column_db", :store_dir => store_dir_method}
     e = Entry.new
     e.image = uploaded_file(file_path("kerb.jpg"), "image/jpeg",
"kerb.jpg")
     assert File.exists?(e.image)
     assert e.image !~ /\.\./, "#{e.image} is not a simple path"
     assert_match %r{/u/file_column_db/somebodys_account/images},
e.image
   end
   def store_dir_method
     File.join("somebodys_account", "images")
   end

This fails with:
   1) Failure:
test_absolute_path_outside_rails_root(ResourceTest) [test/unit/
resource_test.rb:254]:
<"/usr/home/ryenski/sites/my_app/somebodys_account/images/tmp/
1137483590.895686.58774/kerb.jpg"> expected to be =~
</\/u\/file_column_db\/somebodys_account\/images/>.


Any ideas would be appreciated!
Thanks,
Ryan
This topic is locked and can not be replied to.