105 lines
3.0 KiB
Ruby
105 lines
3.0 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe "Authentication" do
|
|
|
|
subject { page }
|
|
|
|
describe "signin page" do
|
|
before { visit signin_path }
|
|
|
|
it { should have_selector('h1', text: 'sign in or register') }
|
|
it { should have_selector('title', text: 'Sign in') }
|
|
end
|
|
|
|
describe "signin" do
|
|
before { visit signin_path }
|
|
|
|
describe "with invalid information" do
|
|
before { click_button "SIGN IN" }
|
|
|
|
it { should have_selector('title', text: 'Sign in') }
|
|
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
|
|
|
|
#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_selector('title', text: "Jamkazam") }
|
|
it { should have_selector('h1', text: "Jamkazam") }
|
|
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
|
|
|
|
it "should render the desired protected page" do
|
|
page.should have_selector('title', text: 'Edit user')
|
|
end
|
|
|
|
describe "when signing in again" do
|
|
before do
|
|
visit signin_path
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
end
|
|
|
|
it "should render the signed-in client page" do
|
|
# it now goes to /music_sessions
|
|
page.should have_selector('title', text: "Jamkazam")
|
|
page.should have_selector('h1', text: "Jamkazam")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "in the Users controller" do
|
|
|
|
describe "visiting the edit page" do
|
|
before { visit edit_user_path(user) }
|
|
it { should have_selector('title', text: 'Sign in') }
|
|
end
|
|
|
|
describe "visiting user index" do
|
|
before { visit users_path }
|
|
it { should have_selector('title', text: '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 user }
|
|
|
|
describe "visiting Users#edit page" do
|
|
before { visit edit_user_path(wrong_user) }
|
|
it { should have_selector('title', text: full_title('')) }
|
|
end
|
|
end
|
|
end
|
|
end
|