Skip to content

Instantly share code, notes, and snippets.

@rdeguzman
Created November 23, 2011 03:15
Show Gist options
  • Save rdeguzman/1387797 to your computer and use it in GitHub Desktop.
Save rdeguzman/1387797 to your computer and use it in GitHub Desktop.
How to test if @fleet_group exists in rspec2 + rails3 + devise
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!, :store_location
def stored_location_for(resource)
nil
end
def after_sign_in_path_for(resource)
set_time_zone
set_schema_name
session[:fleet_group_id] = current_user.default_fleet_group.id
session[:fleet_id] = current_user.default_fleet.id
stored_location_for(resource) || to_do_path
end
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = exception.message
redirect_to access_denied_url
end
def store_location
session[:return_to] = request.referer if request.get? and controller_name != "sessions"
end
def set_time_zone
session[:time_zone] = current_user.time_zone
Time.zone = session[:time_zone]
end
def set_schema_name
session[:schema_name] = current_user.default_fleet_group.schema_name
end
end
class StatusController < ApplicationController
include PgTools
def fleet
unless params[:schema_name].blank?
PgTools.set_search_path(params[:schema_name])
else
PgTools.set_search_path(session[:schema_name])
end
unless params[:fleet_ids].blank?
fleet_id = params[:fleet_ids].split(",")
else
fleet_id = session[:fleet_id]
end
@fleet_groups = current_user.fleet_groups
@fleets = current_user.fleets
fleet = current_user.fleets.where(:id => fleet_id).first
@units = fleet.units.not_hidden.with_active_session
end
end
require 'spec_helper'
describe StatusController do
include Devise::TestHelpers
before (:each) do
@current_user = User.find_by_username('rupert')
sign_in @current_user
end
it "should have fleet groups and fleets for sidebar" do
assigns(:fleet_groups).should_not be_nil
end
#describe "GET 'fleet'" do
# it "should be successful" do
# get 'fleet', :schema_name => 'dfms_4000', :fleet_ids => [4000]
# response.should be_success
# end
#end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment