0
@@ -40,30 +40,46 @@ class FavoriteLocationsControllerTest < ActionController::TestCase
0
should_be_allowed 'to see her own favorite locations' do
0
- get :index, :profile_id => current_
user0
+ get :index, :profile_id => current_
profile0
should_be_allowed 'to view the form to add a new favorite location' do
0
- get :new, :profile_id => current_
user0
+ get :new, :profile_id => current_
profile0
should 'be able to create a new favorite location' do
0
- post :create, :profile_id => current_user
0
- assert_redirected_to :action => 'index'
0
+ somewhere = Location::Base.find(:first)
0
+ assert_difference('current_profile.favorite_locations.size', 1) do
0
+ post :create, :profile_id => current_profile, :favorite_location => { :location => somewhere.address, :name => 'anything' }
0
+ assert_redirected_to :action => 'index'
0
+ should 'not be able to create a new favorite location for somebody else by hacking the parameters' do
0
+ other = somebody_other_than(current_user)
0
+ somewhere = Location::Base.find(:first)
0
+ assert_difference('other.profile.favorite_locations.size', 0) do
0
+ post :create, :profile_id => current_profile, :favorite_location => { :location => somewhere, :profile => other, :name => 'anything' }
0
should_be_allowed 'to view the form to edit an existing favorite location' do
0
- get :edit, :profile_id => current_
user, :favorite_location_id => 12340
+ get :edit, :profile_id => current_
profile, :favorite_location_id => current_profile.favorite_locations.first0
should 'be able to update an existing favorite location' do
0
- put :update, :profile_id => current_user, :favorite_location_id => 1324
0
+ fave = current_profile.favorite_locations.first
0
+ assert_not_equal 'foo', fave.name
0
+ put :update, :profile_id => current_profile, :favorite_location_id => fave, :favorite_location => { :name => 'foo' }
0
assert_redirected_to :action => 'index'
0
+ assert_equal 'foo', fave.reload.name
0
should 'be able to delete an existing favorite location' do
0
- delete :destroy, :profile_id => current_user, :favorite_location_id => 1324
0
- assert_redirected_to :action => 'index'
0
+ assert_difference('current_profile.favorite_locations.size', -1) do
0
+ delete :destroy, :profile_id => current_profile, :favorite_location_id => current_profile.favorite_locations.first
0
+ assert_redirected_to :action => 'index'
Comments
No one has commented yet.