Skip to content

Commit

Permalink
root to home page, delete old home page route
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwong committed Oct 9, 2018
1 parent 6467fd1 commit b2dc267
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def members_only
def admin_only
if current_user.role != "admin"
flash[:notice] = "unauthorized"
redirect_to action: "home"
redirect_to root_path
end

end
Expand Down
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Rails.application.routes.draw do
get 'static_pages/home'
root to: "static_pages#home"

get 'static_pages/members_only'
get 'static_pages/admin_only'
root to: "static_pages#home"
devise_for :users

devise_for :users
end
18 changes: 13 additions & 5 deletions test/controllers/static_pages_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
require 'test_helper'

class StaticPagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get static_pages_home_url
include Devise::Test::IntegrationHelpers

test "should get home page" do
get root_url
assert_response :success
end

test "should get members_only" do
test "should redirect user if not signed in" do
get static_pages_members_only_url
assert_redirected_to new_user_session_path
end

test "should get members only page after sign in" do
sign_in users(:one)
get static_pages_members_only_url
assert_response :success
end

test "should get admin_only" do
sign_in users(:one)
get static_pages_admin_only_url
assert_response :success
assert_redirected_to root_path
end

end
8 changes: 3 additions & 5 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
one:
email: "[email protected]"
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

0 comments on commit b2dc267

Please sign in to comment.