summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-11-15 18:49:31 -0700
committermo khan <mo@mokhan.ca>2014-11-15 18:49:31 -0700
commit003d45b91e6f60a27ce7418c89438eb61cab250c (patch)
tree250e933f78a9ed8b58f757c42ed7ef0dccac6cda
parent916fdef394efdb546c18b61f031dec6f620863d3 (diff)
extract login page object.
-rw-r--r--app/controllers/sessions_controller.rb2
-rw-r--r--spec/controllers/sessions_controller_spec.rb4
-rw-r--r--spec/features/login_spec.rb25
-rw-r--r--spec/support/pages/login_page.rb14
4 files changed, 24 insertions, 21 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index c50b95f..a11afab 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -16,7 +16,7 @@ class SessionsController < ApplicationController
redirect_to root_path(anchor: '')
else
flash[:error] = I18n.translate(:invalid_credentials)
- render :new
+ redirect_to new_session_path
end
end
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb
index fdfbd53..a550ef6 100644
--- a/spec/controllers/sessions_controller_spec.rb
+++ b/spec/controllers/sessions_controller_spec.rb
@@ -15,7 +15,7 @@ describe SessionsController do
it "displays an error" do
post :create, email: 'email@example.com', password: 'wrong'
expect(flash[:error]).to eql(I18n.translate(:invalid_credentials))
- expect(response).to render_template(:new)
+ expect(response).to redirect_to(new_session_path)
end
end
@@ -23,7 +23,7 @@ describe SessionsController do
it "displays an error" do
post :create, email: 'unknown@example.com'
expect(flash[:error]).to eql(I18n.translate(:invalid_credentials))
- expect(response).to render_template(:new)
+ expect(response).to redirect_to(new_session_path)
end
end
diff --git a/spec/features/login_spec.rb b/spec/features/login_spec.rb
index f74d140..3eb9ad4 100644
--- a/spec/features/login_spec.rb
+++ b/spec/features/login_spec.rb
@@ -2,40 +2,29 @@ require 'rails_helper'
describe "the signin process", type: :feature do
let!(:user) { create(:user, password: 'password') }
+ let(:login_page) { LoginPage.new }
context "when the credentials are correct" do
it 'signs the user in' do
- visit root_path
- within ".form-signin" do
- fill_in 'email', with: user.email
- fill_in 'password', with: 'password'
- end
- click_button "Sign in"
+ login_page.login_with(email: user.email, password: 'password')
expect(page).to have_content("Dashboard")
+ expect(current_path).to eql(root_path)
end
end
context "when the password is incorrect" do
it 'displays an error' do
- visit root_path
- within ".form-signin" do
- fill_in 'email', with: user.email
- fill_in 'password', with: 'wrong'
- end
- click_button "Sign in"
+ login_page.login_with(email: user.email, password: 'wrong')
expect(page).to have_content(I18n.translate(:invalid_credentials))
+ expect(current_path).to eql(new_session_path)
end
end
context "when the email is unknown" do
it 'displays an error' do
- visit root_path
- within ".form-signin" do
- fill_in 'email', with: "test@example.com"
- fill_in 'password', with: 'password'
- end
- click_button "Sign in"
+ login_page.login_with(email: 'test@example.com', password: 'password')
expect(page).to have_content(I18n.translate(:invalid_credentials))
+ expect(current_path).to eql(new_session_path)
end
end
end
diff --git a/spec/support/pages/login_page.rb b/spec/support/pages/login_page.rb
new file mode 100644
index 0000000..616603a
--- /dev/null
+++ b/spec/support/pages/login_page.rb
@@ -0,0 +1,14 @@
+class LoginPage
+ include Capybara::DSL
+ include Rails.application.routes.url_helpers
+
+ def login_with(email:, password:)
+ visit root_path
+ within ".form-signin" do
+ fill_in 'email', with: email
+ fill_in 'password', with: password
+ end
+ click_button "Sign in"
+ end
+end
+