From 93fc0e74bc2b3d9fc457439789136b1c70825832 Mon Sep 17 00:00:00 2001
From: Chris Hunt <c@chrishunt.co>
Date: Wed, 5 Jun 2013 18:21:19 -0700
Subject: [PATCH] Test correct login behavior when pending approval

---
 spec/controllers/session_controller_spec.rb | 27 ++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/spec/controllers/session_controller_spec.rb b/spec/controllers/session_controller_spec.rb
index 6ec78a592..857fad1d5 100644
--- a/spec/controllers/session_controller_spec.rb
+++ b/spec/controllers/session_controller_spec.rb
@@ -76,21 +76,42 @@ describe SessionController do
           it "doesn't log in the user" do
             session[:current_user_id].should be_blank
           end
+
+          it "shows the 'not approved' error message" do
+            expect(JSON.parse(response.body)['error']).to eq(
+              I18n.t('login.not_approved')
+            )
+          end
         end
       end
     end
 
     context 'when email has not been confirmed' do
-      before do
+      def post_login
         xhr :post, :create, login: user.email, password: 'myawesomepassword'
       end
 
       it "doesn't log in the user" do
+        post_login
         session[:current_user_id].should be_blank
       end
 
-      it 'returns an error message' do
-        ::JSON.parse(response.body)['error'].should be_present
+      it "shows the 'not activated' error message" do
+        post_login
+        expect(JSON.parse(response.body)['error']).to eq(
+          I18n.t 'login.not_activated'
+        )
+      end
+
+      context "and the 'must approve users' site setting is enabled" do
+        before { SiteSetting.expects(:must_approve_users?).returns(true) }
+
+        it "shows the 'not approved' error message" do
+          post_login
+          expect(JSON.parse(response.body)['error']).to eq(
+            I18n.t 'login.not_approved'
+          )
+        end
       end
     end
   end