Skip to content

Instantly share code, notes, and snippets.

@benoitr
Created November 12, 2012 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoitr/4058363 to your computer and use it in GitHub Desktop.
Save benoitr/4058363 to your computer and use it in GitHub Desktop.
spree_auth_devise Tests
require 'spec_helper'
describe "Reset Password" do
it "should allow the user to indicate they have forgotten their password" do
visit spree.login_path
click_link "Forgot Password?"
page.should have_content("your password will be emailed to you")
end
it "should allow a user to supply an email for the password reset" do
user = create(:user, :email => "foobar@example.com", :password => "secret", :password_confirmation => "secret")
visit spree.login_path
click_link "Forgot Password?"
fill_in "user_email", :with => "foobar@example.com"
click_button "Reset my password"
page.should have_content("You will receive an email with instructions")
end
end
require 'spec_helper'
describe "Sign In" do
before(:each) do
@user = create(:user, :email => "email@person.com", :password => "secret", :password_confirmation => "secret")
visit spree.login_path
end
it "should ask use to sign in" do
visit spree.admin_path
page.should_not have_content("Authorization Failure")
end
it "should let a user sign in successfully" do
fill_in "user_email", :with => @user.email
fill_in "user_password", :with => @user.password
click_button "Login"
page.should have_content("Logged in successfully")
page.should_not have_content("Login")
page.should have_content("Logout")
current_path.should == "/"
end
it "should show validation erros" do
fill_in "user_email", :with => @user.email
fill_in "user_password", :with => "wrong_password"
click_button "Login"
page.should have_content("Invalid email or password")
page.should have_content("Login")
end
it "should allow a user to access a restricted page after logging in" do
user = create(:admin_user, :email => "admin@person.com", :password => "password", :password_confirmation => "password")
visit spree.admin_path
fill_in "user_email", :with => user.email
fill_in "user_password", :with => user.password
click_button "Login"
page.should have_content("Logged in successfully")
current_path.should == "/admin"
end
end
require 'spec_helper'
describe "Sign Out" do
let!(:user) do
create(:user,
:email => "email@person.com",
:password => "secret",
:password_confirmation => "secret")
end
before do
visit spree.login_path
fill_in "user_email", :with => user.email
fill_in "user_password", :with => user.password
# Regression test for #1257
check "Remember me"
click_button "Login"
end
it "should allow a signed in user to logout" do
click_link "Logout"
visit spree.root_path
page.should have_content("Login")
page.should_not have_content("Logout")
end
end
require 'spec_helper'
describe "Sign Up" do
context "with valid data" do
it "should create a new user" do
visit spree.signup_path
fill_in "Email", :with => "email@person.com"
fill_in "Password", :with => "password"
fill_in "Password Confirmation", :with => "password"
click_button "Create"
page.should have_content("You have signed up successfully.")
Spree::User.count.should == 1
end
end
context "with invalid data" do
it "should not create a new user" do
visit spree.signup_path
fill_in "Email", :with => "email@person.com"
fill_in "Password", :with => "password"
fill_in "Password Confirmation", :with => ""
click_button "Create"
page.should have_css("#errorExplanation")
Spree::User.count.should == 0
end
end
end
require 'spec_helper'
describe "Users" do
before(:each) do
create(:user, :email => "a@example.com")
create(:user, :email => "b@example.com")
sign_in_as!(create(:admin_user))
visit spree.admin_path
click_link "Users"
end
context "users index page with sorting" do
before(:each) do
click_link "users_email_title"
end
it "should be able to list users with order email asc" do
page.should have_css('table#listing_users')
within("table#listing_users") do
page.should have_content("a@example.com")
page.should have_content("b@example.com")
end
end
it "should be able to list users with order email desc" do
click_link "users_email_title"
within("table#listing_users") do
page.should have_content("a@example.com")
page.should have_content("b@example.com")
end
end
end
context "searching users" do
it "should display the correct results for a user search" do
fill_in "q_email_cont", :with => "a@example.com"
click_button "Search"
within("table#listing_users") do
page.should have_content("a@example.com")
page.should_not have_content("b@example.com")
end
end
end
context "editing users" do
before(:each) do
click_link("a@example.com")
click_link("Edit")
end
it "should let me edit the user email" do
fill_in "user_email", :with => "a@example.com99"
click_button "Update"
page.should have_content("successfully updated!")
page.should have_content("a@example.com99")
end
it "should let me edit the user password" do
fill_in "user_password", :with => "welcome"
fill_in "user_password_confirmation", :with => "welcome"
click_button "Update"
page.should have_content("successfully updated!")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment