Skip to content

Commit

Permalink
implement checking for uncompressed support and version checking, sta…
Browse files Browse the repository at this point in the history
…rting constructing url w/ option overrides
  • Loading branch information
ratbeard committed Jun 25, 2009
1 parent 2ca05e0 commit 9ce5716
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
33 changes: 31 additions & 2 deletions lib/query.rb
Expand Up @@ -34,12 +34,41 @@ def download(opts={})

# TODO
def url(opts={})
path
opts.empty?? path : construct_url(opts)
end

def latest_version
def has_uncompressed?
!! respond_to?("path(u)")
end

def latest
versions.first
end

private
def construct_url(opts)
defaults = { :version => latest, :uncompressed => false}
defaults.merge!(opts)
check_version_available(opts[:version])
check_uncompressed_available if opts[:uncompressed]

end

def check_version_available(version)
if not versions.include? version
raise "#{name} doesn't have version: #{version}. available versions: #{versions}"
end
true
end

def check_uncompressed_available
if not uncompressed?
raise "#{name} doesn't support uncompressed"
end
true
end


end

# Query Google about the libraries it provides w/ this class
Expand Down
16 changes: 14 additions & 2 deletions spec/query_spec.rb
Expand Up @@ -40,14 +40,26 @@ module JsJuice
@jquery = @google['jquery']
end

it "tells if a library offers an uncompressed version" do
@google['jquery'].should have_uncompressed
@google['prototype'].should_not have_uncompressed


end
describe "url" do
it "is by default the latest compressed library version" do
# given
version = @jquery.latest_version
version = @jquery.latest
expected_url = "http://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js"
# then
@jquery.url.should == expected_url

end

it "can be overriden what version to use" do
# given
expected_url = "http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"
# then
@jquery.url(:version => '1.3.0').should == expected_url
end
end
end
Expand Down

0 comments on commit 9ce5716

Please sign in to comment.