forked from case451/hw3_rottenpotatoes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acedabb
commit 357ef52
Showing
24 changed files
with
637 additions
and
20 deletions.
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
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 was deleted.
Oops, something went wrong.
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,2 +1,49 @@ | ||
class MoviesController < ApplicationController | ||
|
||
def index | ||
@movies = Movie.find(:all, :order => 'released_on') | ||
end | ||
|
||
def new | ||
@movie = Movie.new | ||
end | ||
|
||
def create | ||
@movie = Movie.new(params[:movie]) | ||
if @movie.save | ||
flash[:notice] = "#{@movie.title} added to Rotten Potatoes!" | ||
redirect_to movie_path(@movie) | ||
else | ||
render :action => "new" | ||
end | ||
end | ||
|
||
def show | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@movie = Movie.find(params[:id]) | ||
end | ||
|
||
def update | ||
@movie = Movie.find(params[:id]) | ||
if @movie.update_attributes(params[:movie]) | ||
flash[:notice] = "#{@movie.title} has been updated!" | ||
redirect_to movie_path(@movie) | ||
else | ||
render :action => "edit" | ||
end | ||
end | ||
|
||
def destroy | ||
@movie = Movie.find(params[:id]) | ||
if @movie.destroy | ||
flash[:notice] = "#{@movie.title} has been deleted!" | ||
else | ||
flash[:error] = "Failed to delete #{@movie.title}!" | ||
end | ||
redirect_to(movies_url) | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
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,2 +1,6 @@ | ||
module MoviesHelper | ||
# Checks if a number is odd: | ||
def oddness(count) | ||
count.odd? ? "odd" : "even" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
class Movie < ActiveRecord::Base | ||
|
||
@@ratings = ['G', 'PG', 'PG-13', 'R', 'NC-17'] | ||
cattr_accessor :ratings | ||
|
||
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" | ||
|
||
# Returns a formatted version of the date: | ||
def release_date | ||
self.released_on.strftime('%B %d, %Y') if self.released_on | ||
end | ||
|
||
def self.required_age_for(rating) | ||
{ | ||
"G" => 0, | ||
"PG" => 0, | ||
"PG-13" => 13, | ||
"R" => 17, | ||
"NC-17" => 17 | ||
}[rating] | ||
end | ||
|
||
def appropriate_for_birthdate?(birthdate) | ||
latest_acceptable_time = Movie.required_age_for(self.rating).years.ago | ||
birthdate <= latest_acceptable_time | ||
end | ||
|
||
def self.find_all_appropriate_for_birthdate(birthdate) | ||
Movie.all.select do |movie| | ||
movie.appropriate_for_birthdate?(birthdate) | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
!!! Strict | ||
%html{'xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en', 'lang' => 'en'} | ||
%head | ||
%title Rotten Potatoes! | ||
= stylesheet_link_tag 'general' | ||
|
||
%body | ||
%h1= link_to 'Rotten Potatoes!', movies_path | ||
#body | ||
- if flash[:notice] | ||
#flash_notice= flash[:notice] | ||
- elsif flash[:error] | ||
#flash_error= flash[:error] | ||
= yield |
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,19 @@ | ||
- form_for(@movie) do |f| | ||
= f.error_messages | ||
- field_set_tag "Movie Details" do | ||
%ul | ||
%li | ||
= f.label :title, "Movie Title:" | ||
= f.text_field :title | ||
%li | ||
= f.label :rating, "Movie Rating:" | ||
= f.select :rating, options_for_select(Movie.ratings, @movie.rating) | ||
%li | ||
= f.label :released_on, "Release Date:" | ||
= f.date_select :released_on, :start_year => 1939 | ||
%li | ||
= f.label :description, "Movie Description:" | ||
= f.text_area :description, :rows => 10 | ||
%li | ||
= f.submit((@movie.new_record? ? "Create Movie" : "Update Movie"), | ||
:id => "submit") |
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,16 @@ | ||
<tbody class="movie_row"> | ||
<tr> | ||
<td> | ||
<% form_for(movie) do |f| %> | ||
<%= f.hidden_field :title %> | ||
<%= f.hidden_field :description %> | ||
<%= f.hidden_field :released_on %> | ||
<%= f.hidden_field :rating %> | ||
<%= f.submit "Select" %> | ||
<% end %> | ||
</td> | ||
<td><%= movie.title %></td> | ||
<td><%= movie.rating %></td> | ||
<td><%= movie.release_date %></td> | ||
</tr> | ||
</tbody> |
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,7 @@ | ||
%h2 Editing #{@movie.title} | ||
|
||
= render :partial => "edit_form" | ||
|
||
%ul#page_nav | ||
%li= link_to 'Cancel', @movie | ||
%li= link_to 'Back to list of movies', movies_path |
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,32 @@ | ||
<h2>Select Movie</h2> | ||
|
||
|
||
<table id="movies" summary="List of all the movies."> | ||
<tr> | ||
<th>Select</th> | ||
<th>Movie Title</th> | ||
<th>Rating</th> | ||
<th>Release Date</th> | ||
</tr> | ||
<% @movies.each do |movie| %> | ||
<tr> | ||
<td> | ||
<% form_for(movie) do |f| %> | ||
<%= f.hidden_field :title %> | ||
<%= f.hidden_field :description %> | ||
<%= f.hidden_field :released_on %> | ||
<%= f.hidden_field :rating %> | ||
<%= f.submit "Select" %> | ||
<% end %> | ||
</td> | ||
<td><%= movie.title %></td> | ||
<td><%= movie.rating %></td> | ||
<td><%= movie.release_date %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<ul id="page_nav"> | ||
<li>Not what you're looking for? <%= link_to "Search Again!", new_movie_path %></li> | ||
<li>Return to <%= link_to "Movies", movies_path %></li> | ||
</ul> |
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,20 @@ | ||
%h2 All Movies | ||
|
||
%table#movies{:summary => 'List of all the movies.'} | ||
%thead | ||
%tr | ||
%th Movie Title | ||
%th Rating | ||
%th Release Date | ||
%th More Info | ||
%tbody | ||
- @movies.each_with_index do |movie,count| | ||
%tr{:class => oddness(count)} | ||
%td= movie.title | ||
%td= movie.rating | ||
%td= movie.release_date | ||
%td= link_to 'More about #{movie.title}', movie | ||
|
||
%ul#page_nav | ||
%li= link_to 'Add New Movie Manually', new_movie_path | ||
|
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,6 @@ | ||
%h2 Add New Movie | ||
|
||
= render :partial => "edit_form" | ||
|
||
%ul#page_nav | ||
%li link_to 'Back to list of movies', movies_path |
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,10 @@ | ||
%h2= @movie.title | ||
|
||
%p | ||
Released on #{@movie.release_date}. Rated #{@movie.rating}. | ||
= simple_format(@movie.description) | ||
|
||
%ul#page_nav | ||
%li= link_to 'Edit', edit_movie_path(@movie) | ||
%li= link_to 'Delete', movie_path(@movie), :method => :delete, :confirm => "Really delete #{@movie.title}?" | ||
%li= link_to 'Back to list of movies', movies_path |
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,8 @@ | ||
<% | ||
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" | ||
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" | ||
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" | ||
%> | ||
default: <%= std_opts %> features | ||
wip: --tags @wip:3 --wip features | ||
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip |
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
Oops, something went wrong.