Skip to content

Commit

Permalink
Should validate valid params keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kostia committed Jul 20, 2012
1 parent da919c3 commit 121d393
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/careerjet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ module Careerjet
class UnknownLocale < ArgumentError
end

def self.search(locale, params)
class InvalidParam < ArgumentError
end

def self.search(locale, params = {})
domain = LOCALES.fetch(locale) { raise UnknownLocale, "no domain for locale `#{locale}'" }
params.each_key do |k|
unless [:keywords, :location, :sort, :start_num, :pagesize, :page, :contracttype,
:contractperiod].include? k
raise InvalidParam, "Unknown param key `#{k}'"
end
end
MultiJson.decode(RestClient::Resource.new(domain)['/devel/search.api'].get(params))
end
end
10 changes: 9 additions & 1 deletion spec/careerjet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
end

it 'should raise appropriate error on unknown locale' do
lambda { Careerjet.search(:foo_Bar, {}) }.should raise_error(Careerjet::UnknownLocale)
lambda do
Careerjet.search :foo_Bar, {}
end.should raise_error(Careerjet::UnknownLocale)
end

it 'should validate given params' do
lambda do
Careerjet.search :en_US, :keywords => 'rails', :foo => 'bar'
end.should raise_error(Careerjet::InvalidParam)
end
end

0 comments on commit 121d393

Please sign in to comment.