Commit e59f15cc
Changed files (2)
spec
features
spec/features/logins_spec.rb
@@ -1,46 +0,0 @@
-require 'rails_helper'
-
-describe "Logins" do
- describe "GET /login" do
- it "should be able to reach the login page" do
- visit login_path
- expect(page).to have_content("Got an account? Login!")
- end
-
- context "when an email is registered", :js => true do
- let!(:user) { create(:user, :password => "password") }
-
- before :each do
- visit login_path
- within('.form-inline') do
- fill_in('session_username', :with => user.email)
- fill_in('session_password', :with => "password")
- end
- click_button("Sign In")
- end
-
- it "should let the user signin with the proper password" do
- expect(page).to have_content("Log Out")
- end
-
- it "should not have an error" do
- expect(page).to_not have_content(I18n.t('devise.failure.invalid'))
- end
- end
-
- context "when an email is not known", js: true do
- before :each do
- visit login_path
- within('.form-inline') do
- fill_in('session_username', :with => 'test@example.com')
- fill_in('session_password', :with => 'password')
- end
- click_button "Sign In"
- end
-
- it "should display an error message" do
- expect(page).to have_content("invalid email or password.")
- end
- end
- end
-end
spec/features/sessions_spec.rb
@@ -0,0 +1,70 @@
+require 'rails_helper'
+
+class WebPage
+ include Capybara::DSL
+ include Rails.application.routes.url_helpers
+ attr_reader :page_path
+
+ def initialize(page_path)
+ @page_path = page_path
+ end
+
+ def visit_page
+ visit page_path
+ self
+ end
+
+ def on_page?
+ current_path == page_path
+ end
+end
+
+class LoginPage < WebPage
+ def initialize
+ super(new_session_path)
+ end
+
+ def login_with(email:, password: 'password')
+ within('.form-inline') do
+ fill_in('session_username', with: email)
+ fill_in('session_password', with: password)
+ end
+ click_button("Sign In")
+ end
+end
+
+describe "Logins" do
+ describe "GET /login" do
+ subject { LoginPage.new }
+
+ before :each do
+ subject.visit_page
+ end
+
+ context "when an email is registered", js: true do
+ let!(:user) { create(:user, password: "password") }
+
+ before :each do
+ subject.login_with(email: user.email, password: "password")
+ end
+
+ it "logs the user in" do
+ expect(page).to have_content("Log Out")
+ end
+
+ it "has no errors" do
+ expect(page).to_not have_content(I18n.t('devise.failure.invalid'))
+ end
+ end
+
+ context "when an email is not known", js: true do
+ before :each do
+ subject.login_with(email: 'test@example.com', password: 'password')
+ end
+
+ it "displays an error message" do
+ expect(page).to have_content("invalid email or password.")
+ end
+ end
+ end
+end