diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-01 20:59:01 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-01 20:59:01 -0700 |
| commit | e59f15cc9682380a1844e332b4854d287e579c5a (patch) | |
| tree | b1ace9e73c744830a44d5d6549ce07381716d302 /spec | |
| parent | 5959ca39a647f42f834cb253acb85c1c69409364 (diff) | |
extract page model for login page.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/features/logins_spec.rb | 46 | ||||
| -rw-r--r-- | spec/features/sessions_spec.rb | 70 |
2 files changed, 70 insertions, 46 deletions
diff --git a/spec/features/logins_spec.rb b/spec/features/logins_spec.rb deleted file mode 100644 index 26fa43da..00000000 --- a/spec/features/logins_spec.rb +++ /dev/null @@ -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 diff --git a/spec/features/sessions_spec.rb b/spec/features/sessions_spec.rb new file mode 100644 index 00000000..dfd236dc --- /dev/null +++ b/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 |
