Skip to content

Instantly share code, notes, and snippets.

@mallain
Created July 12, 2010 12:07
Show Gist options
  • Save mallain/472404 to your computer and use it in GitHub Desktop.
Save mallain/472404 to your computer and use it in GitHub Desktop.
require 'test_helper'
class Hr::AlertCollaboratorsControllerTest < ActionController::TestCase
context "logged in" do
setup do
UserSession.create(Factory(:user))
Factory(:agency)
Factory(:feedback)
@alert_collaborator = Factory.stub(:alert_collaborator)
@alert_collaborator.id = 1001
AlertCollaborator.stubs(:find).returns(@alert_collaborator)
AlertCollaborator.stubs(:find).with(:all, anything).returns([@alert_collaborator])
end
should_get_action :index
should_get_action :new
context "on POST to :create (valid data)" do
setup do
AlertCollaborator.any_instance.expects(:save).returns(true).once
AlertCollaborator.any_instance.stubs(:id).returns(1001)
post :create, :alert_collaborator => {}
end
should_assign_to :alert_collaborator, :class => AlertCollaborator
should_respond_with :redirect
should_redirect_to("alert_collaborator index page"){hr_alert_collaborators_path}
end
context "on POST to :create (invalid data)" do
setup do
AlertCollaborator.any_instance.expects(:save).returns(false).once
post :create, :alert_collaborator => {}
end
should_assign_to :alert_collaborator, :class => AlertCollaborator
should_respond_with :success
should_render_with_layout
should_render_template :new
should_not_set_the_flash
end
context "on GET to :show" do
setup do
get :show, {:id => @alert_collaborator.id}
end
should_respond_with :success
should_render_with_layout
should_render_template :show
should_not_set_the_flash
end
context "on GET to :edit" do
setup do
get :edit, :id => @alert_collaborator.id
end
should_respond_with :success
should_render_with_layout
should_render_template :edit
should_not_set_the_flash
end
context "on PUT to :update (valid data)" do
setup do
@alert_collaborator.expects(:update_attributes).returns(true).once
put :update, :id => @alert_collaborator.id, :alert_collaborator => {}
end
should_assign_to :alert_collaborator, :class => AlertCollaborator
should_respond_with :redirect
should_redirect_to("alert_collaborator index page"){hr_alert_collaborators_path}
end
context "on PUT to :update (invalid data)" do
setup do
@alert_collaborator.expects(:update_attributes).returns(false).once
put :update, :id => @alert_collaborator.id, :alert_collaborator => {}
end
should_assign_to :alert_collaborator, :class => AlertCollaborator
should_respond_with :success
should_render_template :edit
end
context "on DELETE to :destroy" do
setup do
@alert_collaborator.expects(:destroy).returns(true).once
delete :destroy, :id => @alert_collaborator.id
end
should_assign_to(:alert_collaborator){@alert_collaborator}
should_respond_with :redirect
should_redirect_to("alert_collaborator index page"){hr_alert_collaborators_path}
end
end
end
<%= render :partial => '/shared/submenu_hr.html.erb' %>
<h1>Listing alert collaborator</h1>
<table>
<tr>
<th>Collaborator name</th>
</tr>
<% @alert_collaborators_agency.each do |hr_alert| %>
<tr>
<td><%=h hr_alert.collaborator.full_name %></td>
<td><%= link_to t('action_show_ERROR_TRANSLATION'), hr_alert_collaborator_path(hr_alert) %></td>
<td><%= link_to t('action_edit'), edit_hr_alert_collaborator_path(hr_alert) %></td>
<td><%= link_to t('action_destroy'), hr_alert_collaborator_path(hr_alert), :confirm => t('action_are_you_sure'), :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New alert collaborator', new_hr_alert_collaborator_path %>
mickael@mickael-laptop:~/projects/pabd/test$ ruby functional/hr/alert_collaborators_controller_test.rb
Loaded suite functional/hr/alert_collaborators_controller_test
Started
.................................
Finished in 5.876578 seconds.
33 tests, 50 assertions, 0 failures, 0 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
module I18n
def just_raise_that_exception(*args)
raise args.first
end
end
class ActionController::TestCase
setup :activate_authlogic
I18n.exception_handler = :just_raise_that_exception
Factory(:agency) unless Agency.first.nil?
Factory(:feedback) unless Feedback.first.nil?
end
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
@mallain
Copy link
Author

mallain commented Jul 12, 2010

Same files from http://gist.github.com/472395 except for "index.html.erb"

I try to translate a key which are not included in en.yml files.
Normaly, module I18n must raise an exception because I specify "I18n.exception_handler = :just_raise_that_exception" into test_helper.rb but they doesn't do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment