-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Movie JSON submission #26
Open
codeblahblah
wants to merge
23
commits into
RubyoffRails:master
Choose a base branch
from
codeblahblah:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
745009b
Panda Level complete.
codeblahblah c7a7953
Added unrefactored Tiger Level.
codeblahblah 0c115b4
Added refactored Tiger Level.
codeblahblah 8df31e7
Added RSpec file as #expect syntax was failing. Movie.average_rating …
codeblahblah ccfed8f
Added Gemfiles.
codeblahblah 910010d
Added partial yearly search.
codeblahblah 3b54798
Added MovieLibrary concept.
codeblahblah 32fddc6
Deleted MovieList class.
codeblahblah b770147
Added MovieLibrary#average_rating.
codeblahblah 527e834
Code clean-up.
codeblahblah 048dce5
In Ruby, dividing by zero doesn't always raise a ZeroDivisionError - …
codeblahblah d3a2f34
Removed unnecessary test from movie_spec.rb
codeblahblah 86c4e24
General clean-up and regression testing.
codeblahblah b977711
Added yearly average method.
codeblahblah 12f27b0
Refactored MovieLibrary#average_rating.
codeblahblah 7f81c59
Further refactoring of MovieLibrary#average_rating.
codeblahblah 5b786f0
Add slope calculation.
codeblahblah 78d49fd
Fixed #calculate_slope. Using #catalog to handle all dependencies.
codeblahblah cb1e2c0
Added program summary and one movie slope test.
codeblahblah f9814fd
Removed the use of unless as a 1 statement modifier.
codeblahblah a93af62
Refactored the use of instance variables and rename the catalog method.
codeblahblah 10a00ea
Removed verbose calls to catalog.
codeblahblah 2e367b8
Added fixes inline with renamed methods
codeblahblah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'http://rubygems.org' | ||
|
||
|
||
gem 'rspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
rspec (2.14.1) | ||
rspec-core (~> 2.14.0) | ||
rspec-expectations (~> 2.14.0) | ||
rspec-mocks (~> 2.14.0) | ||
rspec-core (2.14.7) | ||
rspec-expectations (2.14.5) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.14.5) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
class Movie | ||
|
||
@@movies = [] | ||
attr_reader :id, :title, :year, :score | ||
def initialize(hash={}) | ||
@id = hash.fetch(:id) | ||
@title = hash.fetch(:title) | ||
@year = hash.fetch(:year) | ||
@score = hash.fetch(:score) | ||
end | ||
|
||
def self.build(args) | ||
movie = Movie.new(args) | ||
@@movies << movie | ||
movie | ||
end | ||
|
||
def self.average_rating | ||
all_movies.inject(0.0) { |sum, movie| sum + movie.score } / all_movies.size | ||
end | ||
|
||
def self.count | ||
@@movies.count | ||
end | ||
|
||
def self.all_movies | ||
@@movies | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,50 @@ | ||
require 'rspec' | ||
require_relative "../lib/movie" | ||
describe Movie do | ||
|
||
it "should store the title, year, and score" do | ||
movie = Movie.new(id: "the-id", title: "the-title", year: 1998, score: 50) | ||
movie.id.should eq("the-id") | ||
movie.title.should eq("the-title") | ||
movie.year.should eq(1998) | ||
movie.score.should eq(50) | ||
describe "#new" do | ||
|
||
let (:movie){Movie.new(id: "the-id", title: "the-title", year: 1998, score: 50)} | ||
|
||
it "should store the title, year, and score" do | ||
movie.id.should eq("the-id") | ||
movie.title.should eq("the-title") | ||
movie.year.should eq(1998) | ||
movie.score.should eq(50) | ||
end | ||
|
||
it 'should inherit from vehicle' do | ||
movie.is_a?(Movie).should be_true | ||
end | ||
|
||
it 'should not change the movie count' do | ||
Movie.count.should eq(0) | ||
end | ||
end | ||
|
||
describe ".build" do | ||
|
||
it "records the movie when I build it" do | ||
movie = Movie.build(id: 10020, title: 'Pirates of the Caribbean: The Curse of the Black Pearl', year: 2003, score: 79) | ||
expect(Movie.all_movies).to include (movie) | ||
end | ||
|
||
it "should increment the movie count" do | ||
expect{Movie.build(id: 10036, title: 'Forrest Gump', year: 1994, score: 71)}.to change{Movie.count}.from(1).to(2) | ||
end | ||
end | ||
|
||
describe ".average_rating" do | ||
it "should have no average rating initially" do | ||
#how do you mock this scenario | ||
end | ||
|
||
it 'should calculate the average rating while ignoring the Movie#build calls above' do | ||
#how do you change scope for RSpec object. Or rather how do you reset the Movie object instance variables? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Movie.new will always give you a new object. |
||
end | ||
|
||
it "should calculate the average rating for Forrest Gump and Pirates of the...as 75 " do | ||
Movie.average_rating.should eq(75) | ||
end | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I don't think using a class variable makes 100% sense.
Instead, you could have the caller keep track of the MovieLibrary and help simplify this code and your tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(actually, looks like you just need to remove old code from here)