Skip to content

Commit

Permalink
moving object creation from test to factory_girl
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh committed Apr 15, 2010
1 parent 4a38cce commit a4522e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 4 additions & 0 deletions test/factories/city.rb
@@ -0,0 +1,4 @@
Factory.define :city do |f|
f.name 'mumbai'
end

8 changes: 4 additions & 4 deletions test/functional/main_controller_test.rb
Expand Up @@ -191,7 +191,7 @@ def setup
context 'get show for city' do
setup do
AdminDataConfig.set = { :find_conditions => { 'City' => lambda { |params| {:conditions => ["permanent_name =?", params[:id]] } } } }
@city = City.create(:name => 'New Delhi')
@city = Factory(:city, :name => 'New Delhi')
get :show, {:id => 'new-delhi', :klass => @city.class.name.underscore }
end
should_respond_with :success
Expand All @@ -215,7 +215,7 @@ def setup

context 'get show for door which belongs to another class' do
setup do
@door = Vehicle::Door.create(:color => 'blue', :car_id => @car.id)
@door = Factory(:door, :color => 'blue', :car_id => @car.id)
get :show, {:id => @door.id, :klass => @door.class.name.underscore }
end
should_respond_with :success
Expand All @@ -241,7 +241,7 @@ def setup
context 'destroy a car' do
setup do
grant_update_access
@door = Vehicle::Door.create(:color => 'blue', :car_id => @car.id)
@door = Factory(:door, :color => 'blue', :car => @car)
delete :destroy, {:id => @car.id, :klass => @car.class.name.underscore}
end
should_respond_with :redirect
Expand All @@ -264,7 +264,7 @@ def setup
context 'delete a car' do
setup do
grant_update_access
@door = Vehicle::Door.create(:color => 'blue', :car_id => @car.id)
@door = Factory(:door, :color => 'blue', :car => @car)
delete :del, {:id => @car.id, :klass => @car.class.name.underscore }
end
should_respond_with :redirect
Expand Down
16 changes: 4 additions & 12 deletions test/test_helper.rb
Expand Up @@ -50,7 +50,7 @@ module AdminData
gem 'will_paginate'
require 'will_paginate'

gem 'factory_girl','= 1.2.3'
gem 'factory_girl','= 1.2.4'
require 'factory_girl'

gem 'flexmock'
Expand All @@ -59,11 +59,10 @@ module AdminData
gem 'redgreen'
require 'RedGreen'

# to test helper tests
require 'action_view/test_case'

#require all factories
puts 'loading all factories'
Dir[File.join(File.dirname(__FILE__), 'factories', '*.rb')].each {|f| require f}

Dir[File.join(File.dirname(__FILE__), 'factories', '*.rb')].each { |f| require File.expand_path(f) }

class ActiveSupport::TestCase

Expand Down Expand Up @@ -92,10 +91,3 @@ def show_response

end

# to test helper tests
require 'action_view/test_case'
begin
require 'phocus'
rescue LoadError
# it's alright if you don't have phocus
end

0 comments on commit a4522e2

Please sign in to comment.