mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Add authentication with devise, fix tests
This commit is contained in:
parent
b281f56d11
commit
f162225195
@ -2,4 +2,5 @@ class ApplicationController < ActionController::Base
|
|||||||
# Prevent CSRF attacks by raising an exception.
|
# Prevent CSRF attacks by raising an exception.
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
before_action :authenticate_admin!
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class ProblemsController < ApplicationController
|
class ProblemsController < ApplicationController
|
||||||
|
skip_before_action :authenticate_admin!, only: [:index, :show]
|
||||||
before_action :set_problem, only: [:show]
|
before_action :set_problem, only: [:show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class TranslationsController < ApplicationController
|
class TranslationsController < ApplicationController
|
||||||
|
skip_before_action :authenticate_admin!, only: [:new, :create]
|
||||||
before_action :set_translation, only: :show
|
before_action :set_translation, only: :show
|
||||||
before_action :set_problem, only: [:new, :create]
|
before_action :set_problem, only: [:new, :create]
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,9 @@
|
|||||||
<%= horizontal do %>
|
<%= horizontal do %>
|
||||||
<%= nav class: 'navbar-left' do %>
|
<%= nav class: 'navbar-left' do %>
|
||||||
<%= link_to Problem.model_name.human(count: 2), problems_path %>
|
<%= link_to Problem.model_name.human(count: 2), problems_path %>
|
||||||
<%= link_to Translation.model_name.human(count: 2), translations_path %>
|
<% if admin_signed_in? %>
|
||||||
|
<%= link_to Translation.model_name.human(count: 2), translations_path %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= nav class: 'navbar-right' do %>
|
<%= nav class: 'navbar-right' do %>
|
||||||
<% if admin_signed_in? %>
|
<% if admin_signed_in? %>
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ProblemsControllerTest < ActionController::TestCase
|
class ProblemsControllerTest < ActionController::TestCase
|
||||||
|
include Devise::TestHelpers
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TranslationsControllerTest < ActionController::TestCase
|
class TranslationsControllerTest < ActionController::TestCase
|
||||||
|
include Devise::TestHelpers
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@translation = translations(:translation_one)
|
@translation = translations(:translation_one)
|
||||||
@update = {
|
@update = {
|
||||||
title: 'New title',
|
title: 'New title',
|
||||||
content: 'This is the new content',
|
content: 'This is the new content',
|
||||||
}
|
}
|
||||||
|
@admin = admins(:admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
|
sign_in @admin
|
||||||
get :index
|
get :index
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_not_nil assigns(:translations)
|
assert_not_nil assigns(:translations)
|
||||||
@ -29,6 +33,7 @@ class TranslationsControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should show translation" do
|
test "should show translation" do
|
||||||
|
sign_in @admin
|
||||||
get :show, id: @translation
|
get :show, id: @translation
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
4
test/fixtures/admins.yml
vendored
4
test/fixtures/admins.yml
vendored
@ -4,3 +4,7 @@
|
|||||||
# model remove the '{}' from the fixture names and add the columns immediately
|
# model remove the '{}' from the fixture names and add the columns immediately
|
||||||
# below each fixture, per the syntax in the comments below
|
# below each fixture, per the syntax in the comments below
|
||||||
#
|
#
|
||||||
|
|
||||||
|
admin:
|
||||||
|
email: admin@example.com
|
||||||
|
encrypted_password: <%= Devise.bcrypt(Admin, 'password') %>
|
||||||
Loading…
Reference in New Issue
Block a user