Skip to content

Commit

Permalink
reflects end of model specs section
Browse files Browse the repository at this point in the history
  • Loading branch information
armandofox committed Oct 3, 2011
1 parent 462fe90 commit 4dd3e75
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ GEM
deepopenstruct (0.1.2)
diff-lcs (1.1.3)
erubis (2.7.0)
fakeweb (1.3.0)
ffi (1.0.9)
gherkin (2.4.18)
json (>= 1.4.6)
Expand Down Expand Up @@ -154,7 +153,6 @@ PLATFORMS
DEPENDENCIES
capybara
cucumber-rails
fakeweb
haml
rails (= 3.1)
rspec-rails
Expand Down
11 changes: 10 additions & 1 deletion app/models/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ class Movie < ActiveRecord::Base

class InvalidKeyError < StandardError ; end

def self.api_key
'cc4b67c52acb514bdf4931f7cedfd12b'
end

def self.find_in_tmdb(string)
TmdbMovie.find(:title => string)
Tmdb.api_key = self.api_key
begin
TmdbMovie.find(:title => string)
rescue ArgumentError, RuntimeError
raise Movie::InvalidKeyError
end
end

# rest of file elided for brevity
Expand Down
10 changes: 9 additions & 1 deletion spec/models/movie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
Movie.find_in_tmdb('Inception')
end
end
context 'with no API key' do
it 'should raise an InvalidKeyError' do
Movie.stub(:api_key).and_return('')
lambda { Movie.find_in_tmdb('Inception') }.
should raise_error(Movie::InvalidKeyError)
end
end
context 'with invalid API key' do
it 'should raise an error with a 404 in the message' do
it 'should raise an InvalidKeyError' do
TmdbMovie.stub(:find).and_raise(RuntimeError.new('API returned code 404'))
lambda { Movie.find_in_tmdb('Inception') }.
should raise_error(Movie::InvalidKeyError)
end
Expand Down

0 comments on commit 4dd3e75

Please sign in to comment.