diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 93e196f..2366fce 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -3,6 +3,7 @@ class AboutController < ApplicationController end def adminpanel + raise AccessError unless cuser and @cuser.admin? end def statistics diff --git a/config/routes.rb b/config/routes.rb index 54ce6d1..8d98791 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,10 +77,13 @@ Ensl::Application.routes.draw do resources :bans resources :tweets resources :issues + resources :posts resources :brackets + get 'about/action' get 'about/staff' + get 'about/adminpanel' get 'about/statistics' get 'refresh', to: "application#refresh" diff --git a/spec/controllers/about_controller_spec.rb b/spec/controllers/about_controller_spec.rb index 42bb02e..d68e7be 100644 --- a/spec/controllers/about_controller_spec.rb +++ b/spec/controllers/about_controller_spec.rb @@ -6,13 +6,22 @@ RSpec.describe AboutController, type: :controller do expect(response).to render_template("staff") end - it "renders the adminpanel template" do - get :adminpanel - expect(response).to render_template("adminpanel") - end + context 'as an admin' do + # let!(:admin) { create(:user, :admin) } + let!(:admin) { create :user, :admin } - it "renders the statistics template" do - get :statistics - expect(response).to render_template("statistics") + before do + sign_in_as(admin) + end + + it "renders the adminpanel template" do + get :adminpanel + expect(response).to render_template("adminpanel") + end + + it "renders the statistics template" do + get :statistics + expect(response).to render_template("statistics") + end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2ad2089..907f79a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,8 +1,10 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) + # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? + require 'rails_helper' require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! @@ -20,13 +22,20 @@ require 'rspec/rails' # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| print "importing " + f + "\r\n"; require f } # Checks for pending migrations before tests are run. # If you are not using ActiveRecord, you can remove this line. ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + #config.include Controllers::JsonHelpers, type: :controller + config.include Features::FormHelpers, type: :feature + config.include Features::ServerHelpers, type: :feature + config.include Features::SessionHelpers, type: :feature + config.include Features::SessionHelpers, type: :controller + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 50085f3..d2c3819 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,6 +52,9 @@ RSpec.configure do |config| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end + # Capybara + config.include Capybara::DSL + # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| @@ -63,22 +66,12 @@ RSpec.configure do |config| # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. -=begin # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with # `:focus` metadata. When nothing is tagged with `:focus`, all examples # get run. config.filter_run :focus config.run_all_when_everything_filtered = true - -RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods - config.include Controllers::JsonHelpers, type: :controller - config.include Features::FormHelpers, type: :feature - config.include Features::ServerHelpers, type: :feature - config.include Features::SessionHelpers, type: :feature - - config.fixture_path = "#{::Rails.root}/spec/fixtures" config.order = "random" config.use_transactional_fixtures = false config.color = true diff --git a/spec/support/spec_login_helper.rb b/spec/support/spec_login_helper.rb index 3ca3a4e..092cf74 100644 --- a/spec/support/spec_login_helper.rb +++ b/spec/support/spec_login_helper.rb @@ -1,14 +1,14 @@ -module SpecLoginHelper - def login_admin - login(:admin) - end - - def login(user) - user = User.where(:login => user.to_s).first if user.is_a?(Symbol) - request.session[:user] = user.id - end - - def current_user - User.find(request.session[:user]) - end - end \ No newline at end of file +module SpecLoginHelper + def login_admin + login(:admin) + end + + def login(user) + user = User.where(:login => user.to_s).first if user.is_a?(Symbol) + request.session[:user] = user.id + end + + def current_user + User.find(request.session[:user]) + end +end \ No newline at end of file