diff --git a/app/controllers/dashboard/dashboard_controller.rb b/app/controllers/dashboard/dashboard_controller.rb index 32cd1b05..87660d97 100644 --- a/app/controllers/dashboard/dashboard_controller.rb +++ b/app/controllers/dashboard/dashboard_controller.rb @@ -1,5 +1,7 @@ class Dashboard::DashboardController < ApplicationController + before_action :authenticate_user! + def index @videos = Video.count @playlists = Playlist.count diff --git a/app/views/layouts/dashboard/_header.html.erb b/app/views/layouts/dashboard/_header.html.erb index 9e251715..c210b60e 100644 --- a/app/views/layouts/dashboard/_header.html.erb +++ b/app/views/layouts/dashboard/_header.html.erb @@ -18,7 +18,8 @@ <%= navigation_link t('.users'), [:dashboard, :users] %> diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 9af9d488..43c554e6 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,3 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_makigas_session' +Rails.application.config.session_store :cookie_store, key: '_makigas_session', secure: Rails.env.production? \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index df7ecc68..0e494465 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,20 +1,13 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - # Application error routes get '/404', to: 'error#not_found', via: :all get '/422', to: 'error#unprocessable_entity', via: :all get '/500', to: 'error#internal_server_error', via: :all - devise_for :users, controllers: { - sessions: 'users/sessions', - passwords: 'users/passwords' - } - root to: 'front#index' - - # Routes for the dashboard - authenticate :user do - namespace :dashboard do + # Dashboard routes + constraints subdomain: 'dashboard' do + devise_for :users, controllers: { sessions: 'users/sessions', passwords: 'users/passwords' } + namespace :dashboard, path: '' do root to: 'dashboard#index', as: '' resources :topics resources :videos, only: [:index, :new, :create] @@ -29,18 +22,19 @@ end end - get :terms, to: 'pages#terms' - get :privacy, to: 'pages#privacy' - get :disclaimer, to: 'pages#disclaimer' - get :cookies, to: 'pages#cookies' - + # Main application routes + root to: 'front#index' + resources :topics, only: [:index, :show], constraints: { format: :html } resources :videos, only: :index, constraints: { format: :html } resources :playlists, path: 'series', only: [:index, :show], constraints: { format: :html } do resources :videos, path: '/', only: [:show], constraints: { format: :html } end - resources :topics, only: [:index, :show], constraints: { format: :html } + get :terms, to: 'pages#terms' + get :privacy, to: 'pages#privacy' + get :disclaimer, to: 'pages#disclaimer' + get :cookies, to: 'pages#cookies' - # Redirect old routes. + # Legacy routes (redirect only). get '/videos/:topic/:playlist/episodio/:video' => redirect('/series/%{playlist}/%{video}') get '/videos/:topic/:playlist' => redirect('/series/%{playlist}') get '/videos/:playlist' => redirect('/series/%{playlist}') diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb new file mode 100644 index 00000000..1c453bff --- /dev/null +++ b/spec/features/dashboard/dashboard_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.feature "Dashboard", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + + context "when not logged in" do + it "should not be success" do + visit dashboard_path + expect(page.current_path).not_to eq dashboard_topics_path + end + end + + context "when logged in" do + it "should be success" do + visit dashboard_path + expect(page.status_code).to eq 200 + end + end +end \ No newline at end of file diff --git a/spec/features/dashboard/opinions_spec.rb b/spec/features/dashboard/opinions_spec.rb index 3d1bf273..f5ca88b4 100644 --- a/spec/features/dashboard/opinions_spec.rb +++ b/spec/features/dashboard/opinions_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' RSpec.feature "Dashboard opinions", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + context "when not logged in" do it "should not be success" do visit dashboard_opinions_path diff --git a/spec/features/dashboard/playlist_videos_spec.rb b/spec/features/dashboard/playlist_videos_spec.rb index e774160a..705e64ba 100644 --- a/spec/features/dashboard/playlist_videos_spec.rb +++ b/spec/features/dashboard/playlist_videos_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' RSpec.feature "Dashboard playlist videos", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + before(:each) { @playlist = FactoryGirl.create(:playlist) @videos = [ diff --git a/spec/features/dashboard/playlists_spec.rb b/spec/features/dashboard/playlists_spec.rb index 9eff89d4..3a1b2798 100644 --- a/spec/features/dashboard/playlists_spec.rb +++ b/spec/features/dashboard/playlists_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' RSpec.feature "Dashboard playlists", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + context "when not logged in" do it "should not be success" do visit dashboard_playlists_path diff --git a/spec/features/dashboard/topics_spec.rb b/spec/features/dashboard/topics_spec.rb index 32854953..3bb402e7 100644 --- a/spec/features/dashboard/topics_spec.rb +++ b/spec/features/dashboard/topics_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' RSpec.feature "Dashboard topics", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + context "when not logged in" do it "should not be success" do visit dashboard_topics_path diff --git a/spec/features/dashboard/videos_spec.rb b/spec/features/dashboard/videos_spec.rb index 86a08b20..a390e918 100644 --- a/spec/features/dashboard/videos_spec.rb +++ b/spec/features/dashboard/videos_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' RSpec.feature "Dashboard videos", type: :feature do + before { Capybara.default_host = "http://dashboard.example.com" } + after { Capybara.default_host = "http://www.example.com" } + context "when not logged in" do it "should not be success" do visit dashboard_videos_path @@ -59,6 +62,8 @@ click_button 'Crear VĂ­deo' }.to change { Video.count }.by 1 + # Test the video does not appear + Capybara.default_host = "http://www.example.com" visit root_path within '.recent-videos' do expect(page).not_to have_link 'My video title'