public
Last active

  • Download Gist
OUTPUT
1 2 3 4 5 6 7
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
alert_collaborators_controller_test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
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
index.html.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<%= 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 %>
test_helper.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
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

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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.