Browse code

Presmerovanie do chatu zo vsetkych url

Cinan Rakosnik authored on 07/03/2013 at 10:29:44
Showing 6 changed files
... ...
@@ -5,6 +5,10 @@ class ApplicationController < ActionController::Base
5 5
 	def require_login
6 6
 		if authenticated?
7 7
 			create_new_authentification()
8
+
9
+            unless controller_name == 'chat'
10
+                redirect_to chat_path
11
+            end
8 12
 		else
9 13
 			unless controller_name == 'sessions' && (action_name == 'new' || action_name == 'create')
10 14
                 redirect_to root_url, flash: {error: I18n.t('login.access-denied')}
... ...
@@ -1,6 +1,10 @@
1 1
 - content_for :title, t("chat.title")
2 2
 - content_for :javascript, javascript_include_tag("application")
3 3
 
4
+- if flash[:notice]
5
+  %div.alert.alert-notice
6
+    = flash[:notice]
7
+
4 8
 .container
5 9
   .leftside.left
6 10
     .roster.border.no-top-border.top-border#height-setter-1
... ...
@@ -12,4 +12,7 @@ en:
12 12
 
13 13
     new:
14 14
       form-header: "Login form"
15
-      form-send: "Login"
16 15
\ No newline at end of file
16
+      form-send: "Login"
17
+
18
+  chat:
19
+    title: "Chat"
17 20
\ No newline at end of file
... ...
@@ -1,12 +1,12 @@
1 1
 Xmpp::Application.routes.draw do
2
-  get "chat/index"
2
+    get "chat/index"
3 3
 
4
-	resources :sessions, only: [:new, :create, :destroy]
4
+    resources :sessions, only: [:new, :create, :destroy]
5 5
 
6
-  	root :to => 'sessions#new'
6
+    root :to => 'sessions#new'
7 7
 
8
-	match '/signin',  to: 'sessions#new'
9
-	match '/signout', to: 'sessions#destroy', via: :delete
8
+    match '/signin',  to: 'sessions#new'
9
+    match '/signout', to: 'sessions#destroy', via: :delete
10 10
 
11
-	match '/chat', to: 'chat#index'
11
+    match '/chat', to: 'chat#index'
12 12
 end
... ...
@@ -22,18 +22,24 @@ describe "Authentication" do
22 22
 		end
23 23
 
24 24
 		describe "with valid information" do
25
-			before do
26
-				fill_in "jid",      with: 'bakalar@jabbim.cz'
27
-				fill_in "password", with: 'tralala'
28
-				click_button I18n.t("sessions.new.form-send")
29
-			end
25
+			before { signin }
30 26
 
31
-			#it { should have_title(user.name) }
27
+			it { should have_title(I18n.t("chat.title")) }
32 28
 			#it { should have_link('Profile', href: user_path(user)) }
33 29
 			#it { should have_link('Logout', href: signout_path) }
34
-			#it { should_not have_link('Login', href: signin_path) }
30
+			it { should_not have_link('Login', href: signin_path) }
35 31
 
36
-			it {should have_selector('div.alert.alert-notice', text: 'Success')}
37
-		end
32
+			it {should have_selector('div.alert.alert-notice', text: I18n.t("login.success"))}
33
+        end
34
+
35
+        describe "remember and redirect" do
36
+            before do
37
+                signin
38
+                visit root_path
39
+            end
40
+
41
+            it { should have_title(I18n.t("chat.title")) }
42
+            it { should_not have_link('Login', href: signin_path) }
43
+        end
38 44
 	end
39 45
 end
40 46
\ No newline at end of file
... ...
@@ -42,3 +42,9 @@ RSpec.configure do |config|
42 42
   #     --seed 1234
43 43
   config.order = "random"
44 44
 end
45
+
46
+def signin
47
+    fill_in "jid",      with: 'bakalar@jabbim.cz'
48
+    fill_in "password", with: 'tralala'
49
+    click_button I18n.t("sessions.new.form-send")
50
+end
45 51
\ No newline at end of file