Commit 8f0ee9ad

mo khan <mo@mokhan.ca>
2013-07-20 14:11:56
create feature tests for logging in
1 parent 5b21deb
Changed files (2)
app
models
spec
app/models/user.rb
@@ -34,7 +34,7 @@ class User < ActiveRecord::Base
     creation.user == self
   end
 
-  def change_password(password, confirmation)
+  def change_password(password, confirmation=password)
     return false unless password == confirmation
     self.password = password
     self.save
spec/features/logins_spec.rb
@@ -2,9 +2,30 @@ require 'spec_helper'
 
 describe "Logins" do
   describe "GET /logins" do
-    it "works! (now write some real specs)" do
+    it "should be able to reach the login page" do
       visit '/login'
       page.should 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'
+        within('.form-inline') do
+          fill_in('user_email', :with => user.email)
+          fill_in('user_password', :with => "password")
+        end
+        click_button("Sign In")
+      end
+
+      it "should let the user signin with the proper password" do
+        page.should have_content(I18n.t('devise.sessions.signed_in'))
+      end
+
+      it "should not have an error" do
+        page.should_not have_content(I18n.t('devise.failure.invalid'))
+      end
+    end
   end
 end