From a8067404f43857fc77da04a4d5e72f5e00b79145 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Wed, 21 Sep 2011 21:21:14 +0000 Subject: [PATCH] Use rails configuration for sounds file path * Add sounds_path initializer --- app/models/sound.rb | 2 +- config/initializers/sounds_path.rb | 1 + spec/models/sound_spec.rb | 6 +++++- spec/spec_helper.rb | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 config/initializers/sounds_path.rb diff --git a/app/models/sound.rb b/app/models/sound.rb index 8fe4d3c..6dfd0d6 100644 --- a/app/models/sound.rb +++ b/app/models/sound.rb @@ -7,7 +7,7 @@ class Sound < ActiveRecord::Base validates_presence_of :mime_type def path - "#{Rails.root}/data/sounds/#{sha256}" + "#{Rails.configuration.sounds_path}/#{sha256}" end def file=(file) diff --git a/config/initializers/sounds_path.rb b/config/initializers/sounds_path.rb new file mode 100644 index 0000000..d4e2378 --- /dev/null +++ b/config/initializers/sounds_path.rb @@ -0,0 +1 @@ +Scube::Application.config.sounds_path = "#{Rails.root}/data/sounds" diff --git a/spec/models/sound_spec.rb b/spec/models/sound_spec.rb index 1e5571b..9f110de 100644 --- a/spec/models/sound_spec.rb +++ b/spec/models/sound_spec.rb @@ -10,8 +10,12 @@ describe Sound do it { should validate_presence_of :mime_type } 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 - sound.path.should == "#{Rails.root}/data/sounds/#{sound.sha256}" + sound.path.should == "#{Rails.configuration.sounds_path}/#{sound.sha256}" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab980b7..9f05987 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,7 @@ Spork.prefork do config.mock_with :rspec config.use_transactional_fixtures = true config.after(:all) do - `rm -f #{Rails.root}/data/sounds/*` + `rm -f #{Rails.configuration.sounds_path}/*` end end end