126 lines
3.3 KiB
Ruby
126 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe "Authentication", :js => true, :type => :feature, :capybara_feature => true do
|
|
|
|
subject { page }
|
|
|
|
before(:all) do
|
|
Capybara.javascript_driver = :poltergeist
|
|
Capybara.current_driver = Capybara.javascript_driver
|
|
Capybara.default_wait_time = 10
|
|
end
|
|
|
|
describe "signin page" do
|
|
before { visit signin_path }
|
|
|
|
it {
|
|
should have_selector('h1', text: 'sign in or register')
|
|
should have_title("JamKazam | Sign in")
|
|
}
|
|
end
|
|
|
|
describe "signin" do
|
|
before { visit signin_path }
|
|
|
|
describe "with invalid information" do
|
|
before { click_button "SIGN IN" }
|
|
|
|
it {
|
|
should have_title("JamKazam | Sign in")
|
|
should have_selector('div.login-error-msg', text: 'Invalid login')
|
|
}
|
|
|
|
#describe "after visiting another page" do
|
|
#before { click_link "Home" }
|
|
#it { should_not have_selector('div.alert.alert-error') }
|
|
#end
|
|
end
|
|
|
|
|
|
describe "with valid information" do
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
before do
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
end
|
|
|
|
# Successful sign-in goes to the client
|
|
it {
|
|
should have_title("JamKazam")
|
|
should have_selector('h2', text: "musicians")
|
|
}
|
|
|
|
describe "signout" do
|
|
|
|
before(:each) do
|
|
|
|
should have_selector('h2', text: "musicians")
|
|
# open menu
|
|
find('.userinfo').hover
|
|
# click signout link
|
|
find('.userinfo .sign-out a').trigger(:click)
|
|
|
|
end
|
|
# after logging out, we keep you at /client
|
|
it { find('#profile a.signin', text: 'Sign Up') }
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "authorization" do
|
|
|
|
describe "for non-signed-in users" do
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
describe "when attempting to visit a protected page" do
|
|
before do
|
|
visit edit_user_path(user)
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
end
|
|
|
|
describe "after signing in" do
|
|
|
|
describe "when attempting to sign in again, should render the signed-in client page" do
|
|
before do
|
|
visit signin_path
|
|
|
|
page.should have_title("JamKazam")
|
|
page.should have_selector('h2', text: "musicians")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "in the Users controller" do
|
|
|
|
describe "visiting the edit page" do
|
|
before { visit edit_user_path(user) }
|
|
it { page.should have_title("JamKazam | Sign in") }
|
|
end
|
|
|
|
describe "visiting user index" do
|
|
before { visit users_path }
|
|
it { page.should have_title("JamKazam | Sign in") }
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "as wrong user" do
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
|
|
before { sign_in_poltergeist user }
|
|
|
|
describe "visiting Users#edit page" do
|
|
before { visit edit_user_path(wrong_user) }
|
|
it {
|
|
pending "this should work, but right now you get redirected to ftue"
|
|
page.should have_title('Action Controller: Exception caught')
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|