Created
March 1, 2012 21:16
-
-
Save Veejay/1953285 to your computer and use it in GitHub Desktop.
Test for StaffPlansController#show action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe StaffplansController do | |
before(:each) do | |
@current_user = login_user | |
@company = Factory(:company) | |
@current_user.update_attributes(current_company_id: @company.id) | |
end | |
describe 'GET#show' do | |
it "should redirect to root_url if a user can't be found" do | |
get :show, :id => "bogus" | |
response.should be_redirect | |
response.should redirect_to(root_url) | |
end | |
it "should find the targeted user and populate some instance variables when the ID is valid" do | |
target_user = user_with_clients_and_projects | |
@company.users << target_user | |
target_user.update_attributes(current_company_id: @company.id) | |
get :show, :id => target_user.id | |
response.should be_success | |
response.should render_template("staffplans/show") | |
assigns[:target_user].should == target_user | |
assigns[:clients].should_not be_nil | |
end | |
it "should show only clients and projects for the current user's current company when I go to my staff plan page" do | |
# Let's create three clients with 2 projects each | |
3.times do |i| | |
c = Factory(:client) | |
2.times do |j| | |
c.projects << Factory(:project) | |
end | |
instance_variable_set("@client_#{i+1}", c) | |
end | |
@company.clients << @client_1 | |
@other_company = Factory(:company) | |
@other_company.clients << [@client_2, @client_3] | |
@current_user.current_company.clients.should == [@client_1] | |
get :show, :id => @current_user.id | |
# Current company is @company, which has one client (@client1), which has two projects | |
assigns[:clients].should_not be_nil | |
assigns[:clients].size.should == 1 | |
# The target user is the current_user in this case | |
assigns[:target_user].should == @current_user | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment