Created
July 8, 2011 12:19
-
-
Save Antiarchitect/1071710 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
This file contains hidden or 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
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!('[email protected]', '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 |
This file contains hidden or 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
require 'spec_helper' | |
describe "Sign up process" do | |
before(:each) do | |
@signup_button = I18n.t("devise.registrations.new.sign_up") | |
@email = '[email protected]' | |
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
commented
Jul 8, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment