-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Friendly forwarding and correct user requirement
- Loading branch information
Showing
5 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ def create | |
render 'new' | ||
else | ||
sign_in user | ||
redirect_to user | ||
redirect_back_or user | ||
end | ||
end | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,15 +188,37 @@ | |
@user = Factory(:user) | ||
end | ||
|
||
it "should deny access to 'edit'" do | ||
get :edit, :id => @user | ||
response.should redirect_to(signin_path) | ||
flash[:notice].should =~ /sign in/i | ||
end | ||
describe "for non-signed-in users" do | ||
|
||
it "should deny access to 'edit'" do | ||
get :edit, :id => @user | ||
response.should redirect_to(signin_path) | ||
flash[:notice].should =~ /sign in/i | ||
end | ||
|
||
it "should deny access to 'update'" do | ||
put :update, :id => @user, :user => {} | ||
response.should redirect_to(signin_path) | ||
it "should deny access to 'update'" do | ||
put :update, :id => @user, :user => {} | ||
response.should redirect_to(signin_path) | ||
end | ||
end | ||
|
||
describe "for signed-in users" do | ||
|
||
before(:each) do | ||
wrong_user = Factory(:user, :email => "[email protected]") | ||
test_sign_in(wrong_user) | ||
end | ||
|
||
it "should require matching users for 'edit'" do | ||
get :edit, :id => @user | ||
response.should redirect_to(root_path) | ||
end | ||
|
||
it "should require matching users for 'update'" do | ||
put :update, :id => @user, :user => {} | ||
response.should redirect_to(root_path) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe "FriendlyForwardings" do | ||
|
||
it "should forward to the requested page after signin" do | ||
user = Factory(:user) | ||
visit edit_user_path(user) | ||
fill_in :email, :with => user.email | ||
fill_in :password, :with => user.password | ||
click_button | ||
response.should render_template('users/edit') | ||
visit signout_path | ||
visit signin_path | ||
fill_in :email, :with => user.email | ||
fill_in :password, :with => user.password | ||
click_button | ||
response.should render_template('users/show') | ||
end | ||
end |