Add some forum testing

This commit is contained in:
Ari Timonen 2020-03-22 14:22:10 +02:00
parent 9c4b3d85d1
commit 8c812df99c
9 changed files with 96 additions and 24 deletions

View file

@ -6,7 +6,7 @@ class DirectoriesController < ApplicationController
@files = @directory.files
render partial: 'data_files/list', layout: true
else
@directories = Directory.ordered.filtered.all conditions: { parent_id: 1 }
@directories = Directory.ordered.filtered.where(parent_id: 1)
end
end

View file

@ -1,26 +1,26 @@
require 'rails_helper'
RSpec.describe AboutController, type: :controller do
it "renders the staff template" do
get :staff
expect(response).to render_template("staff")
it "renders the staff template" do
get :staff
expect(response).to render_template("staff")
end
context 'as an admin' do
let!(:admin) { create(:user, :admin) }
before do
login_admin
end
context 'as an admin' do
let!(:admin) { create(:user, :admin) }
before do
login_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
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

View file

@ -1,9 +1,11 @@
require 'rails_helper'
RSpec.describe ShoutmsgsController, type: :controller do
context 'GET #index' do
it "renders the index template" do
get :index
expect(response).to have_http_status(200)
expect(response).to render_template("index")
get :index
expect(response).to have_http_status(200)
expect(response).to render_template("index")
end
end
end

View file

@ -11,4 +11,8 @@ FactoryBot.define do
trait :game do
domain Category::DOMAIN_GAMES
end
trait :forums do
domain Category::DOMAIN_FORUMS
end
end

View file

@ -2,5 +2,20 @@ FactoryBot.define do
factory :forum do
sequence(:title) { |n| "Forum Title #{n}" }
sequence(:description) { |n| "Forum Description #{n}" }
before :create do |forum|
cat = create(:category, :forums)
forum.category = cat
end
trait :with_content do
after :create do |forum|
(rand(30..100)).times do
topic = build :topic, :with_content
topic.forum = forum
topic.save
end
end
end
end
end

View file

@ -3,5 +3,9 @@ FactoryBot.define do
sequence(:text) { |n| "Post Body #{n}" }
topic
user
trait :with_content do
text { (0..100).map { (0...8).map { (65 + rand(26)).chr }.join }.join(" ") }
end
end
end

View file

@ -6,5 +6,15 @@ FactoryBot.define do
before(:create) do |topic|
topic.first_post = "My first post on the topic"
end
trait :with_content do
after :create do |topic|
(rand(1..30)).times do
post = build :post
post.topic = topic
post.save
end
end
end
end
end

View file

@ -0,0 +1,36 @@
require 'rails_helper'
feature 'User reads forums', js: :true do
before :all do
create_list(:forum, 5, :with_content)
end
context 'as a basic user' do
let!(:user) { create(:user) }
before do
sign_in_as(user)
end
it 'has forum header' do
visit forums_path
expect(page).to have_selector("td.forum h5")
end
#it 'has forum description' do
# visit forums_path
# expect("td.forum").to have_content()
#end
it 'can click last post' do
find('td.last>a').click
expect(response).to have_http_status(200)
end
end
private
def long_text(len = 10_000)
(0..len).map{ (0...8).map { (65 + rand(26)).chr }.join }.join(" ") # 90008
end
end

View file

@ -9,6 +9,7 @@ feature "Visitor signs up", js: :true do
scenario "with valid Username, Email, Password and Steam ID" do
within registration_form do
fill_form(:user, user.slice(*sign_up_attributes))
click_button submit(:user, :create)
end