Skip to content
Browse files

Fixed functional tests

  • Loading branch information...
1 parent 7c5c757 commit 55140dc6c0edc291f7432d7f5c014e945702ccea @harrism committed May 25, 2011
View
11 app/controllers/fruits_controller.rb
@@ -19,7 +19,9 @@ def index
# GET /fruits/1
def show
+ logger.debug "FruitsController.show params: " + params.inspect
@fruit = Fruit.find(params[:id])
+ logger.debug "Found fruit " + @fruit.inspect
respond_to do |format|
format.html # show.html.erb
@@ -82,7 +84,7 @@ def button_press
# POST /fruits
def create
-
+
if params[:cancel_button]
return cancel
end
@@ -91,11 +93,12 @@ def create
# for the multistep form
if params[:fruit]
params[:fruit].merge!({"user_id" => current_user.id })
+ session[:fruit_params] ||= {}
session[:fruit_params].deep_merge!(params[:fruit])
end
@fruit = Fruit.new(session[:fruit_params])
- @fruit.current_step = session[:fruit_step]
+ @fruit.current_step = session[:fruit_step] if session[:fruit_step]
@fruit.save if button_press == :save
@@ -115,14 +118,15 @@ def create
# PUT /fruits/1
def update
+
@fruit = Fruit.find(params[:id])
if params[:cancel_button]
return cancel
end
@fruit.attributes = params[:fruit]
- @fruit.current_step = session[:fruit_step]
+ @fruit.current_step = session[:fruit_step] if session[:fruit_step]
respond_to do |format|
@fruits = Fruit.all
@@ -137,6 +141,7 @@ def update
end
else
if params[:fruit]
+ session[:fruit_params] ||= {}
session[:fruit_params].deep_merge!(params[:fruit])
session[:fruit_step] = @fruit.current_step
end
View
2 app/views/fruits/new.html.haml
@@ -1,4 +1,4 @@
- content_for :side do
%h1 New fruit
- = render 'form'
+ = render 'shared/form'
= link_to 'Back', fruits_path
View
1 app/views/shared/_fruit.html.haml
@@ -1,3 +1,4 @@
+- fruit = @fruit if fruit == nil
.fruit_title
- if defined? fruit_counter
- func = "gmapSelectFruitViaJson(#{fruit.to_json})"
View
3 test/fixtures/fruits.yml
@@ -7,15 +7,18 @@ mango:
you to reach over the fence and pick what you want.
lat: -27.436147
lng: 153.165328
+ user_id: 1
kaffir_lime:
title: Kaffir Lime Tree
description: This Kaffir lime is in my back yard. You have to fight the chickens for it!
lat: -27.435471
lng: 153.165817
+ user_id: 1
apple:
title: Apple Tree
description: This apple tree is in Mr. Jones' front yard, but he doesn't share.
lat: -27.433633
lng: 153.164815
+ user_id: 1
View
10 test/fixtures/users.yml
@@ -4,14 +4,16 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
-one: {
+joe: {
email: joe@test.com,
- name: Joe
+ name: Joe,
+ id: 1
}
# column: value
#
-two: {
+jill: {
email: jill@test.com,
- name: Jill
+ name: Jill,
+ id: 2
}
# column: value
View
14 test/functional/fruits_controller_test.rb
@@ -1,14 +1,22 @@
require 'test_helper'
+
class FruitsControllerTest < ActionController::TestCase
+
+ include Devise::TestHelpers
+
setup do
+ sign_in users(:jill)
+
@fruit = fruits(:mango)
+ @user = users(:joe)
@update = {
:title => 'Snozzberry Tree',
:description => 'The Snozzberries taste like snozzberries!',
:lat => 23.35,
- :lng => 95.78
-
+ :lng => 95.78,
+ :user_id => @user.id,
+ :current_step => @fruit.steps.last
}
end
@@ -32,7 +40,7 @@ class FruitsControllerTest < ActionController::TestCase
end
test "should show fruit" do
- get :show, :id => @fruit.to_param
+ get :show, :id => @fruit.id.to_param
assert_response :success
end
View
9 test/functional/market_controller_test.rb
@@ -1,11 +1,18 @@
require 'test_helper'
class MarketControllerTest < ActionController::TestCase
+
+ include Devise::TestHelpers
+
+ setup do
+ sign_in users(:joe)
+ end
+
test "should get index" do
get :index
assert_response :success
assert_select '#columns #side #fruit_list', 1
assert_select '#columns #side #address_form', 1
- assert_select '#columns #side #fruit_form', 1
+ assert_select '#columns #map', 1
end
end
View
1 test/unit/fruit_test.rb
@@ -6,6 +6,7 @@ class FruitTest < ActiveSupport::TestCase
assert fruit.invalid?
assert fruit.errors[:title].any?
assert fruit.errors[:description].any?
+ assert fruit.errors[:user_id].any?
assert fruit.errors[:lat].none? # default 0.0
assert fruit.errors[:lng].none? # default 0.0
end

0 comments on commit 55140dc

Please sign in to comment.
Something went wrong with that request. Please try again.