Skip to content

Commit

Permalink
Added ruby-tmdb gem to Gemfile
Browse files Browse the repository at this point in the history
This commit reflects state after getting the failing movie specs around
exception handling
  • Loading branch information
armandofox committed Oct 3, 2011
1 parent 1d8b4f6 commit 462fe90
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'rails', '3.1'

gem 'sqlite3', '~> 1.3.3'
gem 'haml'
gem 'ruby-tmdb'

group :test, :development do
gem 'capybara'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GEM
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
addressable (2.2.6)
arel (2.2.1)
bcrypt-ruby (3.0.0)
builder (3.0.0)
Expand All @@ -53,8 +54,10 @@ GEM
capybara (>= 1.1.1)
cucumber (~> 1.0.4)
nokogiri (>= 1.5.0)
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 @@ -119,6 +122,10 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-tmdb (0.2.1)
addressable
deepopenstruct (>= 0.1.2)
json
rubyzip (0.9.4)
selenium-webdriver (2.5.0)
childprocess (>= 0.2.1)
Expand Down Expand Up @@ -147,8 +154,10 @@ PLATFORMS
DEPENDENCIES
capybara
cucumber-rails
fakeweb
haml
rails (= 3.1)
rspec-rails
ruby-debug
ruby-tmdb
sqlite3 (~> 1.3.3)
20 changes: 6 additions & 14 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
class Movie < ActiveRecord::Base

@@ratings_with_ages = {
'G' => 0,
'PG' => 0,
'PG-13' => 13,
'R' => 17,
'NC-17' => 17
}
@@ratings = @@ratings_with_ages.keys
cattr_reader :ratings
class InvalidKeyError < StandardError ; end

validates_presence_of :title
validates_length_of :description, :minimum => 10
validates_uniqueness_of :title, :message => "already exists in the database"
validates_inclusion_of :rating, :in => Movie.ratings, :message => "is not a valid rating"

def self.find_in_tmdb(string)
TmdbMovie.find(:title => string)
end

# rest of file elided for brevity
end
15 changes: 14 additions & 1 deletion spec/models/movie_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
require 'spec_helper'

describe Movie do
pending "add some examples to (or delete) #{__FILE__}"
describe 'searching Tmdb by keyword' do
context 'with valid API key' do
it 'should call Tmdb with title keywords' do
TmdbMovie.should_receive(:find).with(hash_including :title => 'Inception')
Movie.find_in_tmdb('Inception')
end
end
context 'with invalid API key' do
it 'should raise an error with a 404 in the message' do
lambda { Movie.find_in_tmdb('Inception') }.
should raise_error(Movie::InvalidKeyError)
end
end
end
end

0 comments on commit 462fe90

Please sign in to comment.