Rails 3 w/ Devise/CanCan: POST/PUT Request Fails when loading the user? -


i running functional tests test::unit against rails 3 application uses devise , cancan manage users. however, hitting weird issue in requests when make post or put contacts_controller. request fails when controller loads user database, , stops, results in failed test.

would have idea of why occurring?

console output

sql (2.8ms)  describe `roles_users` sql (2.1ms)  describe `camps_users` sql (3.4ms)  describe `camps_users` sql (2.0ms)  describe `campers_camps` sql (2.8ms)  describe `campers_camps` sql (2.1ms)  describe `roles_users` loaded suite test/functional/camp/contacts_controller_test started   sql (0.1ms)  begin   sql (0.7ms)  show tables   user load (0.3ms)  select `users`.* `users` (`users`.`id` = 292811013) limit 1   sql (0.4ms)  select count(*) `contacts`   camp load (0.3ms)  select `camps`.* `camps` (`camps`.`id` = 665138414) limit 1   processing camp::contactscontroller#create html   parameters: {"contact"=>{"first_name"=>"john", "last_name"=>"doe", "email_address"=>"test@test.com", "phone_number"=>"1234567890"}, "camp_id"=>"bolo"}   user load (0.4ms)  select `users`.* `users` (`users`.`id` = 292811013) limit 1   completed   in 24ms   sql (0.3ms)  select count(*) `contacts`   sql (0.1ms)  rollback f finished in 0.385608 seconds.  1) failure:   test_should_create_contact(camp::contactscontrollertest) [test/functional/camp/contacts_controller_test.rb:45]: "contact.count" didn't change 1. <5> expected <4>.  1 tests, 1 assertions, 1 failures, 0 errors, 0 skips  test run options: --seed 10895 --name "test_should_create_contact" 

contact test

test "should create contact"   assert_difference('contact.count')     post :create,        :contact => {         :first_name => "john",         :last_name => "doe",         :email_address => "test@test.com",         :phone_number => "1234567890"       },       :camp_id => camps(:bolo).uri   end    assert_response :created   assert_not_nil assigns(:contact)    :show,      :id => assigns(:contact).to_param,     :camp_id => camps(:bolo).uri    assert_response :success end 

contact controller

class camp::contactscontroller < authorizedcontroller   def create     @contact = @camp.contacts.build(params[:contact])      respond_to |format|       if @contact.save         format.html { render :text => "contact created!", :status => :created }         format.xml {render :xml => @contact, :status => :created, :location => @contact}       else         format.html { render :action => "new", :status => :bad_request }         format.xml  { render :xml => @contact.errors, :status => :bad_request }       end     end   end end 

authorized controller

class authorizedcontroller < applicationcontroller   before_filter :authenticate_user!   check_authorization   load_and_authorize_resource    rescue_from cancan::accessdenied |exception|     flash[:error] = exception.message     respond_to |format|       format.html { redirect_to new_user_session_path, :status => :unauthorized }       format.xml { render :xml => "...", :status => :unauthorized }     end   end end 

cancan ability

def initialize(user)     user ||= user.new # guest user (not logged in)      if user.role? :admin       can :manage, :all     elsif user.role? :account_admin       can [:show, :update, :destroy, :create], camp |camp|         user.is_linked_to_camp?(camp)       end        can :manage, contact |contact|         user.is_obj_linked_to_camp?(contact)       end     else       cannot :manage, :all     end end 

turns out bug in code. tests not updated account new schema in contacts model.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -