mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-14 05:41:00 +00:00
Update to FactoryBot and fix admin panel spec
This commit is contained in:
parent
b35ba51910
commit
bdbdef1635
32 changed files with 66 additions and 48 deletions
2
Gemfile
2
Gemfile
|
@ -71,7 +71,7 @@ group :test do
|
||||||
gem 'capybara', '~> 2.4.4'
|
gem 'capybara', '~> 2.4.4'
|
||||||
gem 'poltergeist', '~> 1.6.0'
|
gem 'poltergeist', '~> 1.6.0'
|
||||||
gem 'selenium-webdriver', '~> 2.47.1'
|
gem 'selenium-webdriver', '~> 2.47.1'
|
||||||
gem 'factory_girl_rails', '~> 4.4.1'
|
gem 'factory_bot_rails'
|
||||||
gem 'timecop', '~> 0.7.1'
|
gem 'timecop', '~> 0.7.1'
|
||||||
gem 'rspec'
|
gem 'rspec'
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,10 +121,10 @@ GEM
|
||||||
exceptional (2.0.33)
|
exceptional (2.0.33)
|
||||||
rack
|
rack
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
factory_girl (4.4.0)
|
factory_bot (4.11.1)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
factory_girl_rails (4.4.1)
|
factory_bot_rails (4.11.1)
|
||||||
factory_girl (~> 4.4.0)
|
factory_bot (~> 4.11.1)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
faraday (0.9.2)
|
faraday (0.9.2)
|
||||||
multipart-post (>= 1.2, < 3)
|
multipart-post (>= 1.2, < 3)
|
||||||
|
@ -363,7 +363,7 @@ DEPENDENCIES
|
||||||
dotenv-rails
|
dotenv-rails
|
||||||
dynamic_form (~> 1.1.4)
|
dynamic_form (~> 1.1.4)
|
||||||
exceptional (~> 2.0.33)
|
exceptional (~> 2.0.33)
|
||||||
factory_girl_rails (~> 4.4.1)
|
factory_bot_rails
|
||||||
faraday (~> 0.9.0)
|
faraday (~> 0.9.0)
|
||||||
font-awesome-sass (~> 4.1.0.0)
|
font-awesome-sass (~> 4.1.0.0)
|
||||||
google-api-client (~> 0.10.3)
|
google-api-client (~> 0.10.3)
|
||||||
|
|
|
@ -59,7 +59,7 @@ class ApplicationController < ActionController::Base
|
||||||
def update_user
|
def update_user
|
||||||
if cuser
|
if cuser
|
||||||
Time.zone = cuser.time_zone
|
Time.zone = cuser.time_zone
|
||||||
cuser.update_attribute :lastvisit, DateTime.now if cuser.lastvisit < 2.minutes.ago
|
cuser.update_attribute :lastvisit, DateTime.now if cuser.lastvisit and cuser.lastvisit < 2.minutes.ago
|
||||||
|
|
||||||
if cuser.banned? Ban::TYPE_SITE
|
if cuser.banned? Ban::TYPE_SITE
|
||||||
session[:user] = nil
|
session[:user] = nil
|
||||||
|
|
|
@ -31,6 +31,8 @@ class User < ActiveRecord::Base
|
||||||
attr_protected :id, :created_at, :updated_at, :lastvisit, :lastip, :password, :version
|
attr_protected :id, :created_at, :updated_at, :lastvisit, :lastip, :password, :version
|
||||||
attr_accessor :raw_password
|
attr_accessor :raw_password
|
||||||
|
|
||||||
|
#attribute :lastvisit, :string, default: DateTime.now
|
||||||
|
|
||||||
belongs_to :team
|
belongs_to :team
|
||||||
has_one :profile, :dependent => :destroy
|
has_one :profile, :dependent => :destroy
|
||||||
has_many :bans, :dependent => :destroy
|
has_many :bans, :dependent => :destroy
|
||||||
|
|
|
@ -7,11 +7,10 @@ RSpec.describe AboutController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as an admin' do
|
context 'as an admin' do
|
||||||
# let!(:admin) { create(:user, :admin) }
|
let!(:admin) { create(:user, :admin) }
|
||||||
let!(:admin) { create :user, :admin }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in_as(admin)
|
login_admin
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the adminpanel template" do
|
it "renders the adminpanel template" do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :article do
|
factory :article do
|
||||||
sequence(:title) { |n| "Article #{n}" }
|
sequence(:title) { |n| "Article #{n}" }
|
||||||
sequence(:text) { (0..100).map { (0...8).map { (65 + rand(26)).chr }.join }.join(" ") }
|
sequence(:text) { (0..100).map { (0...8).map { (65 + rand(26)).chr }.join }.join(" ") }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :ban do
|
factory :ban do
|
||||||
ban_type Ban::TYPE_SITE
|
ban_type Ban::TYPE_SITE
|
||||||
expiry Time.now.utc.to_date + 1
|
expiry Time.now.utc.to_date + 1
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :category do
|
factory :category do
|
||||||
sequence(:name) { |n| "Category #{n}" }
|
sequence(:name) { |n| "Category #{n}" }
|
||||||
sequence(:sort) { |n| n }
|
sequence(:sort) { |n| n }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :contest do
|
factory :contest do
|
||||||
sequence(:name) { |n| "Contest ##{n}" }
|
sequence(:name) { |n| "Contest ##{n}" }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :contester do
|
factory :contester do
|
||||||
contest
|
contest
|
||||||
team do
|
team do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :forum do
|
factory :forum do
|
||||||
sequence(:title) { |n| "Forum Title #{n}" }
|
sequence(:title) { |n| "Forum Title #{n}" }
|
||||||
sequence(:description) { |n| "Forum Description #{n}" }
|
sequence(:description) { |n| "Forum Description #{n}" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :forumer do
|
factory :forumer do
|
||||||
forum
|
forum
|
||||||
group
|
group
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :gather do
|
factory :gather do
|
||||||
association :category, factory: [:category, :game]
|
association :category, factory: [:category, :game]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :group do
|
factory :group do
|
||||||
sequence(:id) { |n| n + 100 } # Preserve first 100
|
sequence(:id) { |n| n + 100 } # Preserve first 100
|
||||||
sequence(:name) { |n| "Group#{n}" }
|
sequence(:name) { |n| "Group#{n}" }
|
||||||
association :founder, factory: :user
|
association :founder, factory: :user
|
||||||
|
|
||||||
initialize_with { Group.find_or_create_by_id(id) }
|
# initialize_with { Group.find_or_create_by(id: id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :admin do
|
trait :admin do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :grouper do
|
factory :grouper do
|
||||||
sequence(:task) { |n| "Task#{n}" }
|
sequence(:task) { |n| "Task#{n}" }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :issue do
|
factory :issue do
|
||||||
sequence(:title) { |n| "Issue title #{n}" }
|
sequence(:title) { |n| "Issue title #{n}" }
|
||||||
sequence(:text) { |n| "Issue Text #{n}" }
|
sequence(:text) { |n| "Issue Text #{n}" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :map do
|
factory :map do
|
||||||
sequence(:name) { |n| "ns_MapName#{n}" }
|
sequence(:name) { |n| "ns_MapName#{n}" }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :match do
|
factory :match do
|
||||||
contest
|
contest
|
||||||
contester1 do
|
contester1 do
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :message do
|
factory :message do
|
||||||
association :sender, factory: :user
|
association :sender, factory: :user
|
||||||
association :recipient, factory: :user
|
association :recipient, factory: :user
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :post do
|
factory :post do
|
||||||
sequence(:text) { |n| "Post Body #{n}" }
|
sequence(:text) { |n| "Post Body #{n}" }
|
||||||
topic
|
topic
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :profile do
|
factory :profile do
|
||||||
web "ensl.org"
|
web "ensl.org"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :server do
|
factory :server do
|
||||||
sequence(:name) { |n| "ServerName#{n}" }
|
sequence(:name) { |n| "ServerName#{n}" }
|
||||||
sequence(:dns) { |n| "DNS#{n}" }
|
sequence(:dns) { |n| "DNS#{n}" }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :team do
|
factory :team do
|
||||||
sequence(:name) { |n| "Team ##{n}" }
|
sequence(:name) { |n| "Team ##{n}" }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :topic do
|
factory :topic do
|
||||||
sequence(:title) { |n| "Topic Title #{n}" }
|
sequence(:title) { |n| "Topic Title #{n}" }
|
||||||
forum
|
forum
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FactoryGirl.define do
|
FactoryBot.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
sequence(:username) { |n| "Player#{n}" }
|
sequence(:username) { |n| "Player#{n}" }
|
||||||
sequence(:email) { |n| "player#{n}@ensl.org" }
|
sequence(:email) { |n| "player#{n}@ensl.org" }
|
||||||
|
@ -8,6 +8,7 @@ FactoryGirl.define do
|
||||||
lastname "Player"
|
lastname "Player"
|
||||||
country "EU"
|
country "EU"
|
||||||
raw_password "PasswordABC123"
|
raw_password "PasswordABC123"
|
||||||
|
lastvisit "Sun, 15 Mar 2020 13:31:06 +0000"
|
||||||
|
|
||||||
after(:create) do |user|
|
after(:create) do |user|
|
||||||
create(:profile, user: user)
|
create(:profile, user: user)
|
||||||
|
|
10
spec/features/users/admin.rb
Normal file
10
spec/features/users/admin.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature "Admin logs in", js: :true do
|
||||||
|
let(:user) { attributes_for(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
visit new_user_path
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -16,6 +16,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
require 'pry'
|
||||||
|
|
||||||
describe "User" do
|
describe "User" do
|
||||||
describe "Permissions" do
|
describe "Permissions" do
|
||||||
|
|
|
@ -5,7 +5,6 @@ require File.expand_path('../../config/environment', __FILE__)
|
||||||
# Prevent database truncation if the environment is production
|
# Prevent database truncation if the environment is production
|
||||||
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
# Add additional requires below this line. Rails is not loaded until this point!
|
# Add additional requires below this line. Rails is not loaded until this point!
|
||||||
|
|
||||||
|
@ -29,12 +28,12 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| print "importing " + f +
|
||||||
ActiveRecord::Migration.maintain_test_schema!
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include FactoryGirl::Syntax::Methods
|
|
||||||
#config.include Controllers::JsonHelpers, type: :controller
|
#config.include Controllers::JsonHelpers, type: :controller
|
||||||
config.include Features::FormHelpers, type: :feature
|
config.include Features::FormHelpers, type: :feature
|
||||||
config.include Features::ServerHelpers, type: :feature
|
config.include Features::ServerHelpers, type: :feature
|
||||||
config.include Features::SessionHelpers, type: :feature
|
config.include Features::SessionHelpers, type: :feature
|
||||||
config.include Features::SessionHelpers, type: :controller
|
|
||||||
|
config.include Controllers::SessionHelpers, :type => :controller
|
||||||
|
|
||||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
ENV["RAILS_ENV"] ||= "test"
|
ENV["RAILS_ENV"] ||= "test"
|
||||||
|
|
||||||
|
require 'dotenv'
|
||||||
|
Dotenv.load('.env')
|
||||||
|
|
||||||
require "codeclimate-test-reporter"
|
require "codeclimate-test-reporter"
|
||||||
require "simplecov"
|
require "simplecov"
|
||||||
CodeClimate::TestReporter.start
|
CodeClimate::TestReporter.start
|
||||||
|
|
17
spec/support/controller/session_helpers.rb
Normal file
17
spec/support/controller/session_helpers.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Controllers
|
||||||
|
module SessionHelpers
|
||||||
|
def login_admin
|
||||||
|
user = Group.admins.first.user
|
||||||
|
login(user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
def login(username)
|
||||||
|
user = User.where(:username => username.to_s).first
|
||||||
|
request.session[:user] = user.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_user
|
||||||
|
User.find(request.session[:user])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
# spec/support/factory_girl.rb
|
# spec/support/factory_girl.rb
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include FactoryGirl::Syntax::Methods
|
config.include FactoryBot::Syntax::Methods
|
||||||
end
|
end
|
|
@ -1,14 +0,0 @@
|
||||||
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
|
|
Loading…
Reference in a new issue