Skip to content

Instantly share code, notes, and snippets.

@Antiarchitect
Created July 8, 2011 12:19
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 Antiarchitect/1071710 to your computer and use it in GitHub Desktop.
Save Antiarchitect/1071710 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe "Edit profile process" do
before(:each) do
@user = Factory.create(:user)
@user.confirm!
@login_button = I18n.t("devise.sessions.new.submit")
@edit_button = I18n.t("devise.registrations.edit.submit")
@login_link = I18n.t("devise.menu.login_items.login")
@logout_link = I18n.t("devise.menu.login_items.logout")
@edit_link = I18n.t("devise.menu.registration_items.edit")
sign_in_user!(@user.email, @user.password)
end
it "should change password with current password provided" do
within "#user_edit" do
fill_in I18n.t("activerecord.attributes.user.email"), :with => @user.email
fill_in I18n.t("activerecord.attributes.user.current_password"), :with => @user.password
fill_in I18n.t("activerecord.attributes.user.password"), :with => 'somepassword'
fill_in I18n.t("activerecord.attributes.user.password_confirmation"), :with => 'somepassword'
click_button @edit_button
end
page.should have_content I18n.t("devise.registrations.updated")
end
def sign_in_user!(email, password)
visit new_user_session_path
within "#user_new" do
fill_in I18n.t("activerecord.attributes.user.email"), :with => email
fill_in I18n.t("activerecord.attributes.user.password"), :with => password
end
click_button @login_button
click_link @edit_link
end
end
require 'spec_helper'
describe "Sign in process" do
before(:each) do
@user = Factory.create(:user)
@confirmed_user = Factory.create(:user)
@confirmed_user.confirm!
@login_button = I18n.t("devise.sessions.new.submit")
@login_link = I18n.t("devise.menu.login_items.login")
@logout_link = I18n.t("devise.menu.login_items.logout")
end
it "should not sign in with incorrect credentials" do
sign_in_user!('some@wrong.email', 'randompassword')
page.should have_content @login_link
page.should have_no_content @logout_link
page.should have_content I18n.t("devise.failure.invalid")
end
it "confirmed user should not sign in with incorrect password" do
sign_in_user!(@confirmed_user.email, 'wrongpass')
page.should have_content @login_link
page.should have_no_content @logout_link
page.should have_content I18n.t("devise.failure.invalid")
end
it "confirmed user should sign in with correct credentials" do
sign_in_user!(@confirmed_user.email, @confirmed_user.password)
page.should have_content @logout_link
page.should have_no_content @login_link
page.should have_content I18n.t("devise.sessions.signed_in")
end
it "unconfirmed user should not sign in with correct credentials" do
sign_in_user!(@user.email, @user.password)
page.should have_content @login_link
page.should have_no_content @logout_link
page.should have_content I18n.t("devise.failure.unconfirmed")
end
it "signed in user should be able to sign out" do
sign_in_user!(@confirmed_user.email, @confirmed_user.password)
click_link @logout_link
page.should have_content @login_link
page.should have_no_content @logout_link
page.should have_content I18n.t("devise.sessions.signed_out")
end
def sign_in_user!(email, password)
visit new_user_session_path
within("#user_new") do
fill_in I18n.t("activerecord.attributes.user.email"), :with => email
fill_in I18n.t("activerecord.attributes.user.password"), :with => password
end
click_button @login_button
end
end
require 'spec_helper'
describe "Sign up process" do
before(:each) do
@signup_button = I18n.t("devise.registrations.new.sign_up")
@email = 'some_email@example.com'
end
it "should sign up with email provided" do
sign_up_user!(@email)
page.should have_content I18n.t("devise.registrations.inactive_signed_up", :reason => :unconfirmed)
end
it "should not sign up with no email provided" do
sign_up_user!('')
page.should have_content [User.human_attribute_name(:email),
I18n.t("activerecord.errors.models.user.attributes.email.blank")].join(' ')
end
# Невозможно протестировать случай, когда введена строка не являющаяся email, т.к. <input type="email">
it "should not sign up with existing email provided" do
sign_up_user!(@email)
sign_up_user!(@email)
page.should have_content [User.human_attribute_name(:email),
I18n.t("activerecord.errors.models.user.attributes.email.taken")].join(' ')
end
it "should not sign up with existing email provided in uppercase" do
sign_up_user!(@email)
sign_up_user!(@email.upcase!)
page.should have_content [User.human_attribute_name(:email),
I18n.t("activerecord.errors.models.user.attributes.email.taken")].join(' ')
end
def sign_up_user!(email)
visit new_user_registration_path
within("#user_new") do
fill_in I18n.t("activerecord.attributes.user.email"), :with => email
end
click_button @signup_button
end
end
@ognevsky
Copy link

ognevsky commented Jul 8, 2011

require 'spec_helper'

describe "Sign in process" do

  let(:user)        { Factory(:user) }
  let(:login_link)  { I18n.t("devise.menu.login_items.login") }
  let(:logout_link) { I18n.t("devise.menu.login_items.logout") }


  context "should not be able to sign in" do

    it "with incorrect credentials" do
      sign_in_user!('some@wrong.email', 'randompassword')

      page.should have_content(login_link)
      page.should have_no_content(logout_link)
      page.should have_content I18n.t("devise.failure.invalid")
    end

    it "without confirmation" do
      sign_in_user!(user.email, user.password)

      page.should have_content(login_link)
      page.should have_no_content(logout_link)
      page.should have_content I18n.t("devise.failure.unconfirmed")
    end

    it "with confirmation, but with incorrect credentials" do
      user.confirm!; sign_in_user!(user, 'wrongpass')

      page.should have_content(login_link)
      page.should have_no_content(logout_link)
      page.should have_content I18n.t("devise.failure.invalid")
    end

  end

  context "should be able to sign in" do

    it "with confirmation and correct credentials" do
      user.confirm!; sign_in_user!(user.email, user.password)

      page.should have_content(logout_link)
      page.should have_no_content(login_link)
      page.should have_content I18n.t("devise.sessions.signed_in")
    end


  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment