prevents timelines spec to change settings for following specs

pull/517/head
Jens Ulferts 11 years ago
parent 3c6225dc76
commit 9467ca20fe
  1. 22
      spec/models/timeline_spec.rb
  2. 12
      spec/support/settings.rb

@ -26,21 +26,23 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../spec_helper', __FILE__)
require File.expand_path('../../spec_helper', __FILE__)
describe Timeline do
describe 'helper methods for creation' do
describe 'available_responsibles' do
it 'is sorted according to general setting' do
ab = FactoryGirl.create(:user, :firstname => 'a', :lastname => 'b')
describe Timeline do
describe 'helper methods for creation' do
describe 'available_responsibles' do
it 'is sorted according to general setting' do
ab = FactoryGirl.create(:user, :firstname => 'a', :lastname => 'b')
ba = FactoryGirl.create(:user, :firstname => 'b', :lastname => 'a')
t = Timeline.new
Setting.user_format = :firstname_lastname
t.available_responsibles.should == [ab, ba]
with_settings :user_format => :firstname_lastname do
t.available_responsibles.should == [ab, ba]
end
Setting.user_format = :lastname_firstname
t.available_responsibles.should == [ba, ab]
with_settings :user_format => :lastname_firstname do
t.available_responsibles.should == [ba, ab]
end
end
end
end

@ -30,9 +30,15 @@
# Runs block with settings specified in options.
# The original settings are restored afterwards.
def with_settings(options, &block)
saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
options.each {|k, v| Setting[k] = v}
saved_settings = options.keys.inject({}) do |h, k|
h[k] = Setting[k].is_a?(Symbol) ?
Setting[k] :
Setting[k].dup
h
end
options.each { |k, v| Setting[k] = v }
yield
ensure
saved_settings.each {|k, v| Setting[k] = v}
saved_settings.each { |k, v| Setting[k] = v }
end

Loading…
Cancel
Save