Skip to content

Commit

Permalink
found another obscure bug where cache_bust values aren't being defaul…
Browse files Browse the repository at this point in the history
…ted b/c of a 'false' setting accidentally being interpreted as 'nil'
  • Loading branch information
kellyredding committed May 9, 2011
1 parent 7978156 commit cea5d0e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rack-less (2.0.0)
rack-less (2.0.1)
less (~> 1.2)
rack (~> 1.0)

Expand Down Expand Up @@ -43,8 +43,6 @@ PLATFORMS

DEPENDENCIES
bundler (~> 1.0)
less (~> 1.2)
rack (~> 1.0)
rack-less!
rack-test (>= 0.5.3)
sinatra (>= 0.9.4)
Expand Down
21 changes: 13 additions & 8 deletions lib/rack/less/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config

def initialize(settings={})
ATTRIBUTES.each do |a|
instance_variable_set("@#{a}", settings[a] || DEFAULTS[a])
instance_variable_set("@#{a}", settings[a].nil? ? DEFAULTS[a] : settings[a])
end
end

Expand Down Expand Up @@ -77,22 +77,27 @@ def stylesheet_filename(key)
filename = key.strip
filename += ".css" unless filename.include?('.css')
if !filename.include?('?') && self.cache_bust != false
filename += "?"
filename += if self.cache_bust == true
Time.now.to_i
else
self.cache_bust ||= default_cache_bust
end.to_s
if !(cb = cache_bust_value).empty?
filename += "?#{cb}"
end
end
filename
end

def cache_bust_value
if self.cache_bust == true
Time.now.to_i
else
self.cache_bust ||= default_cache_bust
end.to_s
end

def default_cache_bust
if defined?(::Sinatra) && defined?(::Sinatra::Application)
app_root_cache_bust(::Sinatra::Application)
elsif defined?(::Rails)
app_root_cache_bust(::Rails)
end || false
end || ""
end

def app_root_cache_bust(app)
Expand Down
2 changes: 1 addition & 1 deletion test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ConfigTest < Test::Unit::TestCase
{ :cache => false,
:compress => false,
:combinations => {},
:cache_bust => false
:cache_bust => nil
}.each do |k,v|
should "default #{k} correctly" do
assert_equal v, @config.send(k)
Expand Down

0 comments on commit cea5d0e

Please sign in to comment.