Skip to content

Instantly share code, notes, and snippets.

@mallain
Created July 22, 2010 15:45
Show Gist options
  • Save mallain/486139 to your computer and use it in GitHub Desktop.
Save mallain/486139 to your computer and use it in GitHub Desktop.
65) Error:
test: (locale=FR) logged in on PUT to :update (valid data) should redirect to alert_collaborator index page. (Hr::AlertCollaboratorsControllerTest):
NoMethodError: undefined method `users' for #<Hr::AlertCollaboratorsControllerTest:0x7f4ce9161ab0>
/test_helper.rb:117:in `generate_setup'
functional/hr/alert_collaborators_controller_test.rb:7:in `__bind_1279813364_526452'
shoulda (2.10.3) lib/shoulda/context.rb:380:in `call'
shoulda (2.10.3) lib/shoulda/context.rb:380:in `run_current_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:379:in `each'
shoulda (2.10.3) lib/shoulda/context.rb:379:in `run_current_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:371:in `run_all_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:375:in `run_parent_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:359:in `test: (locale=FR) logged in on PUT to :update (valid data) should redirect to alert_collaborator index page. '
66) Error:
test: (locale=FR) logged in on PUT to :update (valid data) should respond with redirect. (Hr::AlertCollaboratorsControllerTest):
NoMethodError: undefined method `users' for #<Hr::AlertCollaboratorsControllerTest:0x7f4ce9161948>
/test_helper.rb:117:in `generate_setup'
functional/hr/alert_collaborators_controller_test.rb:7:in `__bind_1279813364_609582'
shoulda (2.10.3) lib/shoulda/context.rb:380:in `call'
shoulda (2.10.3) lib/shoulda/context.rb:380:in `run_current_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:379:in `each'
shoulda (2.10.3) lib/shoulda/context.rb:379:in `run_current_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:371:in `run_all_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:375:in `run_parent_setup_blocks'
shoulda (2.10.3) lib/shoulda/context.rb:359:in `test: (locale=FR) logged in on PUT to :update (valid data) should respond with redirect. '
66 tests, 0 assertions, 0 failures, 66 errors
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'factory_girl'
require 'shoulda'
require 'faker'
require "authlogic/test_case"
require 'i18n'
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test database remains unchanged so your fixtures don't have to be reloaded
# between every test method. Fewer database queries means faster tests.
#
# Read Mike Clark's excellent walkthrough at
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
#
# Every Active Record database supports transactions except MyISAM tables
# in MySQL. Turn off transactional fixtures in this case; however, if you
# don't care one way or the other, switching from MyISAM to InnoDB tables
# is recommended.
#
# The only drawback to using transactional fixtures is when you actually
# need to test transactions. Since your test is bracketed by a transaction,
# any transactions started in your code will be automatically rolled back.
self.use_transactional_fixtures = true
# Instantiated fixtures are slow, but give you @david where otherwise you
# would need people(:david). If you don't want to migrate your existing
# test cases which use the @david style and don't mind the speed hit (each
# instantiated fixtures translates to a database query per test method),
# then set this back to true.
self.use_instantiated_fixtures = false
# 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
end
# Redefine #t method of TranslationHelper
# With this hack, all missing translation will raise a exception
module ActionView
module Helpers
module TranslationHelper
def t(key, options = {})
options[:raise] = true
I18n.translate(scope_key_by_partial(key), options)
end
end
end
end
# Define active_authlogic into all setup
class ActionController::TestCase
setup :activate_authlogic
end
# Generate an action
# param action : define the "get" action (string)
# ex : should_get_action("index")
def should_get_action(action)
context "on GET to #{action}" do
setup do
get action
end
should_respond_with :success
should_render_with_layout
should_render_template action
should_not_set_the_flash
end
end
# Return available locales for testing into ControllerTest
def available_testing_locales
I18n.available_locales
end
# Instanciate stub objects
# param name : Describe the name of model (string)
# ex : instanciate_stub_object('feedback')
def instanciate_stub_object(name)
# Instanciate objects array
objects = []
# Instanciate first object
instance_variable_set("@#{name}".to_sym, Factory.stub(name.to_sym))
# Instanciate five objects
(1..5).each do |i|
instance_variable_set("@#{name}_#{i}".to_sym, Factory.stub(name.to_sym))
instance_variable_get("@#{name}_#{i}").id = rand(3000)
objects << instance_variable_get("@#{name}_#{i}")
end
# Find method return an instanciate object
name.classify.constantize.stubs(:find).returns(instance_variable_get("@#{name}"))
# Find method with "all" parameter will return an array of instanciate objects
name.classify.constantize.stubs(:find).with(:all, anything).returns(objects)
end
# Generate setup with parameter
# param lang : Define the default_locale (string)
# param instanciate : Define the list of objects we have to instanciate in this setup Array with Hash
# ex : generate_setup(:lang => 'fr')
# ex : generate_setup(:lang => 'en', :instanciate => ['feedback', 'claim_collection')
def generate_setup(params={})
# Create at least one agency
Factory(:agency)
# Test Tips into RDOC
UserSession.create(users(:whomever))
# Feedback is need everywhere
instanciate_stub_object('feedback')
UserSession.any_instance.expects(:save).returns(true).once
UserSession.any_instance.stubs(:id).returns(1001)
# Instanciate every object included in params[:instanciate] variable
params[:instanciate].each do |object|
instanciate_stub_object(object)
end
# Define setup locale
I18n.default_locale = params[:lang]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment