Skip to content

Commit

Permalink
Include tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Blaichinger committed Jan 25, 2011
1 parent 58fc32e commit 736dd55
Show file tree
Hide file tree
Showing 20 changed files with 1,174 additions and 49 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -23,7 +23,6 @@ group :test do
gem 'webrat', '0.7.1'
gem 'factory_girl_rails', '1.0'
gem 'faker'

end


Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Expand Up @@ -48,7 +48,6 @@ GEM
rest-client (>= 1.4.0, < 1.7.0)
i18n (0.5.0)
json (1.4.6-x86-mingw32)
json_pure (1.4.6)
koala (0.10.0)
json (>= 1.0)
launchy (0.3.7)
Expand Down
10 changes: 0 additions & 10 deletions app/controllers/pages_controller.rb
@@ -1,18 +1,8 @@
class PagesController < ApplicationController

before_filter :authenticate, :only => [:about, :help]

def home
@title = "Home"
end

def about
@title = "About"
end

def help
@title = "Help"
end

def imprint
@title = "Imprint"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -28,7 +28,7 @@ def create
if signed_in?
redirect_to current_user
else
@user = User.register_new(params[:user], false)
@user = User.register_new(params, false)

if @user.save
sign_in(@user)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/sessions_helper.rb
Expand Up @@ -51,9 +51,9 @@ def correct_user

def admin_user
if (current_user)
redirect_to(home_path) unless current_user.admin?
redirect_to(current_user) unless current_user.admin?
else
redirect_to(home_path)
redirect_to(root_path)
end
end

Expand Down
7 changes: 3 additions & 4 deletions app/helpers/users_helper.rb
@@ -1,9 +1,8 @@
module UsersHelper

def gravatar_for(user, options = { :size => 150})
gravatar_image_tag(user.email.downcase, :alt => user.name,
:class => 'gravatar',
:gravatar => options)
def gravatar_for(user, options = { :size => 150, :default => 'identicon'})
gravatar_image_tag(user.email.downcase, :alt => user.name, :class => 'gravatar',
:gravatar => options)
end

end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -13,7 +13,7 @@
load = false

elsif(params[:id])
if((request.fullpath == '/maps/' + params[:id]) || (request.fullpath == '/maps/' + params[:id] + '/'))
if((request.fullpath == '/maps/' + params[:id].to_s) || (request.fullpath == '/maps/' + params[:id].to_s + '/'))
load = false
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/views/pages/help.html.erb

This file was deleted.

10 changes: 0 additions & 10 deletions app/views/pages/home.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/users/index.html.erb
Expand Up @@ -6,7 +6,7 @@
<li class="allusers"><% if user.isFacebook %>
<img src="http://graph.facebook.com/<%= user.fbid.to_s %>/picture">
<% else %>
<%= gravatar_for user, :size => 50 %>
<%= gravatar_for user, :size => 50, :default => 'identicon' %>
<% end %>
<%= user.name %>
Expand Down
2 changes: 0 additions & 2 deletions config/routes.rb
Expand Up @@ -6,8 +6,6 @@
resources :maps, :only => [:new, :show, :create, :destroy, :protect_index, :destroy_index]

match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/home', :to => 'pages#home'
match '/imprint', :to => 'pages#imprint'

match '/signup', :to => 'users#new'
Expand Down
Binary file added db/development.sqlite3_test
Binary file not shown.
12 changes: 0 additions & 12 deletions public/javascripts/renderengine/lastplantgame/.project

This file was deleted.

36 changes: 36 additions & 0 deletions spec/controllers/pages_controller_spec.rb
@@ -0,0 +1,36 @@
require 'spec_helper'

describe PagesController do
render_views

before(:each) do
@base_title = "Last Plant"
end

describe "GET 'about'" do
it "should be successful" do
get 'about'
response.should be_success
end

it "should have the right title" do
get 'about'
response.should have_selector("title",
:content => @base_title + " | About")
end
end

describe "GET 'imprint'" do
it "should be successful" do
get 'imprint'
response.should be_success
end

it "should have the right title" do
get 'imprint'
response.should have_selector("title",
:content => @base_title + " | Imprint")
end
end
end

80 changes: 80 additions & 0 deletions spec/controllers/sessions_controller_spec.rb
@@ -0,0 +1,80 @@
require 'spec_helper'

describe SessionsController do
render_views

describe "GET 'new'" do

it "should be successful" do
get :new
response.should be_success
end

it "should have the right title" do
get :new
response.should have_selector("title", :content => "Sign in")
end
end


describe "POST 'create'" do

describe "invalid signin" do

before(:each) do
@attr = { :email => "email@example.com", :password => "invalid" }
end

it "should re-render the new page" do
post :create, :session => @attr
response.should redirect_to(root_path)
end

it "should have a flash.now message" do
post :create, :session => @attr
flash.now[:error].should =~ /invalid/i
end
end


describe "with valid email and password" do

before(:each) do
@user = Factory(:user)
@attr = { :email => @user.email, :password => @user.password }
end

it "should sign the user in" do
post :create, :session => @attr
controller.current_user.should == @user
controller.should be_signed_in
end

it "should redirect to the user show page" do
post :create, :session => @attr
response.should redirect_to(user_path(@user))
end
end
end


describe "DELETE 'destroy'" do

before(:each) do
@user = Factory(:user)
@attr = { :email => @user.email, :password => @user.password }
end

it "should sign the user in" do
post :create, :session => @attr
controller.current_user.should == @user
controller.should be_signed_in
end

it "should sign a user out" do
delete :destroy
controller.should_not be_signed_in
response.should redirect_to(root_path)
end
end
end

0 comments on commit 736dd55

Please sign in to comment.