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

Turns out is was a bug in my code. My tests were not updated to account for a new schema in the Contacts model.

Up vote 1 down vote favorite share g+ share fb share tw.

I am running functional tests with Test::Unit against my rails 3 application that uses Devise and CanCan to help manage users. However, I am hitting a weird issue in my requests when I make a POST or PUT to my contacts_controller. The request fails when the controller loads the User from the database, and then stops, which then results in a failed test.

Would anyone have an idea of why this is 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`. * FROM `users` WHERE (`users`.

`id` = 292811013) LIMIT 1 SQL (0.4ms) SELECT COUNT(*) FROM `contacts` Camp Load (0.3ms) SELECT `camps`. * FROM `camps` WHERE (`camps`. `id` = 665138414) LIMIT 1 Processing by Camp::ContactsController#create as HTML Parameters: {"contact"=>{"first_name"=>"John", "last_name"=>"Doe", "email_address"=>"[email protected]", "phone_number"=>"1234567890"}, "camp_id"=>"bolo"} User Load (0.4ms) SELECT `users`.

* FROM `users` WHERE (`users`. `id` = 292811013) LIMIT 1 Completed in 24ms SQL (0.3ms) SELECT COUNT(*) FROM `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 by 1. Expected but was .

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" do assert_difference('Contact. Count') do post :create, :contact => { :first_name => "John", :last_name => "Doe", :email_address => "[email protected]", :phone_number => "1234567890" }, :camp_id => camps(:bolo). Uri end assert_response :created assert_not_nil assigns(:contact) get :show, :id => assigns(:contact).

To_param, :camp_id => camps(:bolo). Uri assert_response :success end Contact Controller class Camp::ContactsController "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 :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 do |camp| user. Is_linked_to_camp?(camp) end can :manage, Contact do |contact| user. Is_obj_linked_to_camp?(contact) end else cannot :manage, :all end end ruby-on-rails ruby-on-rails-3 http devise cancan link|improve this question asked Apr 28 '11 at 22:47strife25680311 100% accept rate.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions