Permalink
Browse files

Create test suite and passing all tests

  • Loading branch information...
KentonWhite committed May 30, 2010
1 parent a5be1bd commit 07f2d2e4dbb2137574ed69018b1fd272f7ae61e0
View
@@ -5,7 +5,7 @@ source 'http://rubygems.org'
# Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'
-# gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'pg'
# Use unicorn as the web server
@@ -25,6 +25,7 @@ gem 'pg'
# group :test do
# gem 'webrat'
# end
+gem 'mocha'
gem 'mongrel'
@@ -12,4 +12,5 @@ def get_maze
def get_node
@node = @maze.nodes.find params[:node_id]
end
+
end
@@ -8,7 +8,6 @@ def index
def show
@maze = current_user.mazes.find(params[:id])
- @nodes = @maze.nodes.all
end
def new
@@ -27,6 +26,7 @@ def create
def edit
@maze = current_user.mazes.find(params[:id])
+ @nodes = @maze.nodes.all
end
def update
@@ -27,7 +27,7 @@ def create
end
def edit
- @node = @maze.nodes.new.find(params[:id])
+ @node = @maze.nodes.find(params[:id])
end
def update
@@ -2,6 +2,19 @@
<%= render 'form' %>
+<p>
+ <strong>Nodes:</strong>
+ <% @nodes.each do |node| %>
+ <p>
+ <%= node.title %>
+ <%= link_to "Show", maze_node_path(@maze, node)%> |
+ <%= link_to "Edit", edit_maze_node_path(@maze, node) %> |
+ <%= link_to "Destroy", [@maze, node], :confirm => 'Are you sure?', :method => :delete %>
+ </p>
+ <% end unless @nodes.nil? %>
+
+</p>
+
<p>
<%= link_to "Show", @maze %> |
<%= link_to "View All", mazes_path %>
@@ -7,7 +7,7 @@
<% for maze in @mazes %>
<tr>
<td><%= maze.title %></td>
- <td><%= link_to "Show", maze %></td>
+ <td><%= link_to "Play", maze %></td>
<td><%= link_to "Edit", edit_maze_path(maze) %></td>
<td><%= link_to "Destroy", maze, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
@@ -4,16 +4,6 @@
<strong>Title:</strong>
<%= @maze.title %>
</p>
-<p>
- <strong>Nodes:</strong>
- <% @nodes.each do |node| %>
- <p>
- <%= node.title %>
- <%= link_to "Show", maze_node_path(@maze, node.id)%>
- </p>
- <% end %>
-
-</p>
<p>
<%= link_to "Edit", edit_maze_path(@maze) %> |
@@ -11,9 +11,3 @@
<p>
<%= render :partial => 'show_links' %>
</p>
-
-<p>
- <%= link_to "Edit", edit_maze_node_path(@maze, @node) %> |
- <%= link_to "Destroy", [@maze, @node], :confirm => 'Are you sure?', :method => :delete %> |
- <%= link_to "View All", maze_nodes_path(@maze) %>
-</p>
View
@@ -27,7 +27,7 @@ def logged_in?
current_user
end
- def login_required
+ def login_required
unless logged_in?
flash[:error] = "You must first log in or sign up before accessing this page."
store_target_location
@@ -43,6 +43,6 @@ def redirect_to_target_or_default(default)
private
def store_target_location
- session[:return_to] = request.request_uri
+ session[:return_to] = request.url
end
end
View
@@ -1,7 +1,11 @@
one:
+ id: 1
text: MyString
node_id: 1
+ to_node_id: 2
-two:
+two:
+ id: 2
text: MyString
- node_id: 1
+ node_id: 2
+ to_node_id: 1
View
@@ -1,7 +1,9 @@
one:
+ id: 1
title: MyString
user_id: 1
-two:
+two:
+ id: 2
title: MyString
user_id: 1
View
@@ -1,9 +1,11 @@
one:
+ id: 1
title: MyString
- text: MyText
+ content: MyText
maze_id: 1
two:
+ id: 2
title: MyString
- text: MyText
+ content: MyText
maze_id: 1
View
@@ -1,11 +1,13 @@
# password: "secret"
foo:
+ id: 1
username: foo
email: foo@example.com
password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
password_salt: bef65e058905c379436d80d1a32e7374b139e7b0
bar:
+ id: 2
username: bar
email: bar@example.com
password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
@@ -1,44 +1,49 @@
require 'test_helper'
class LinksControllerTest < ActionController::TestCase
+ def setup
+ login_as users(:foo)
+ end
+
+
def test_new
- get :new
+ get :new, :maze_id => mazes(:one), :node_id => nodes(:one)
assert_template 'new'
end
def test_create_invalid
Link.any_instance.stubs(:valid?).returns(false)
- post :create
+ post :create, :maze_id => mazes(:one), :node_id => nodes(:one)
assert_template 'new'
end
def test_create_valid
Link.any_instance.stubs(:valid?).returns(true)
- post :create
+ post :create, :maze_id => mazes(:one), :node_id => nodes(:one)
assert_redirected_to root_url
end
def test_edit
- get :edit, :id => Link.first
+ get :edit, :maze_id => mazes(:one), :node_id => nodes(:one), :id => Link.first
assert_template 'edit'
end
def test_update_invalid
Link.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Link.first
+ put :update, :maze_id => mazes(:one), :node_id => nodes(:one), :id => Link.first
assert_template 'edit'
end
def test_update_valid
Link.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Link.first
+ put :update, :maze_id => mazes(:one), :node_id => nodes(:one), :id => Link.first
assert_redirected_to root_url
end
def test_destroy
link = Link.first
- delete :destroy, :id => link
- assert_redirected_to root_url
+ delete :destroy, :maze_id => mazes(:one), :node_id => nodes(:one), :id => link
+ assert_redirected_to maze_node_path mazes(:one), nodes(:one)
assert !Link.exists?(link.id)
end
end
@@ -1,6 +1,11 @@
require 'test_helper'
class MazesControllerTest < ActionController::TestCase
+ def setup
+ login_as users(:foo)
+ end
+
+
def test_index
get :index
assert_template 'index'
@@ -1,54 +1,59 @@
require 'test_helper'
class NodesControllerTest < ActionController::TestCase
+ def setup
+ login_as users(:foo)
+ end
+
+
def test_index
- get :index
+ get :index, :maze_id => mazes(:one)
assert_template 'index'
end
def test_show
- get :show, :id => Node.first
+ get :show, :maze_id => mazes(:one), :id => Node.first
assert_template 'show'
end
def test_new
- get :new
+ get :new, :maze_id => mazes(:one)
assert_template 'new'
end
def test_create_invalid
Node.any_instance.stubs(:valid?).returns(false)
- post :create
+ post :create, :maze_id => mazes(:one)
assert_template 'new'
end
def test_create_valid
Node.any_instance.stubs(:valid?).returns(true)
- post :create
- assert_redirected_to node_url(assigns(:node))
+ post :create, :maze_id => mazes(:one)
+ assert_redirected_to maze_node_url(mazes(:one), assigns(:node))
end
def test_edit
- get :edit, :id => Node.first
+ get :edit, :maze_id => mazes(:one), :id => Node.first
assert_template 'edit'
end
def test_update_invalid
Node.any_instance.stubs(:valid?).returns(false)
- put :update, :id => Node.first
+ put :update, :maze_id => mazes(:one), :id => Node.first
assert_template 'edit'
end
def test_update_valid
Node.any_instance.stubs(:valid?).returns(true)
- put :update, :id => Node.first
- assert_redirected_to node_url(assigns(:node))
+ put :update, :maze_id => mazes(:one), :id => Node.first
+ assert_redirected_to maze_node_url(mazes(:one), assigns(:node))
end
def test_destroy
node = Node.first
- delete :destroy, :id => node
- assert_redirected_to nodes_url
+ delete :destroy, :maze_id => mazes(:one), :id => node
+ assert_redirected_to maze_nodes_url(mazes(:one))
assert !Node.exists?(node.id)
end
end
View
@@ -1,13 +1,18 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
+require 'mocha'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
+
+ def login_as(user)
+ session[:user_id] = user.id
+ end
# Add more helper methods to be used by all tests here...
end

0 comments on commit 07f2d2e

Please sign in to comment.