Use rails configuration for sounds file path

* Add sounds_path initializer
This commit is contained in:
Thibault Jouan 2011-09-21 21:21:14 +00:00
parent 6af1540640
commit a8067404f4
4 changed files with 8 additions and 3 deletions

View File

@ -7,7 +7,7 @@ class Sound < ActiveRecord::Base
validates_presence_of :mime_type validates_presence_of :mime_type
def path def path
"#{Rails.root}/data/sounds/#{sha256}" "#{Rails.configuration.sounds_path}/#{sha256}"
end end
def file=(file) def file=(file)

View File

@ -0,0 +1 @@
Scube::Application.config.sounds_path = "#{Rails.root}/data/sounds"

View File

@ -10,8 +10,12 @@ describe Sound do
it { should validate_presence_of :mime_type } it { should validate_presence_of :mime_type }
describe '#path' do describe '#path' do
it 'starts by the path specified in Rails.configuration.sound_path' do
sound.path.should match(/\A#{Rails.configuration.sounds_path}/)
end
it 'returns the sound file path based on the SHA256 digest' do it 'returns the sound file path based on the SHA256 digest' do
sound.path.should == "#{Rails.root}/data/sounds/#{sound.sha256}" sound.path.should == "#{Rails.configuration.sounds_path}/#{sound.sha256}"
end end
end end

View File

@ -11,7 +11,7 @@ Spork.prefork do
config.mock_with :rspec config.mock_with :rspec
config.use_transactional_fixtures = true config.use_transactional_fixtures = true
config.after(:all) do config.after(:all) do
`rm -f #{Rails.root}/data/sounds/*` `rm -f #{Rails.configuration.sounds_path}/*`
end end
end end
end end