mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
email settings tests, code cleanup
This commit is contained in:
parent
2dd3a34961
commit
5bb1b4f5b6
7 changed files with 136 additions and 28 deletions
33
app.rb
33
app.rb
|
@ -56,6 +56,7 @@ error do
|
||||||
erb :'error'
|
erb :'error'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
get '/newindex_mockup' do
|
get '/newindex_mockup' do
|
||||||
if SimpleCache.expired?(:sites_count)
|
if SimpleCache.expired?(:sites_count)
|
||||||
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes
|
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes
|
||||||
|
@ -79,6 +80,15 @@ get '/profile_mockup' do
|
||||||
erb :'profile_mockup', locals: {site: current_site}
|
erb :'profile_mockup', locals: {site: current_site}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/browse_mockup' do
|
||||||
|
erb :'browse_mockup'
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/tips_mockup' do
|
||||||
|
erb :'tips_mockup'
|
||||||
|
end
|
||||||
|
# :nocov:
|
||||||
|
|
||||||
get '/site/:username.rss' do |username|
|
get '/site/:username.rss' do |username|
|
||||||
site = Site[username: username]
|
site = Site[username: username]
|
||||||
content_type :xml
|
content_type :xml
|
||||||
|
@ -87,10 +97,7 @@ end
|
||||||
|
|
||||||
get '/site/:username/?' do |username|
|
get '/site/:username/?' do |username|
|
||||||
site = Site[username: username]
|
site = Site[username: username]
|
||||||
not_found if site.nil?
|
not_found if site.nil? || site.is_banned
|
||||||
if current_site && (site.is_blocking?(current_site) || current_site.is_blocking?(site))
|
|
||||||
not_found
|
|
||||||
end
|
|
||||||
|
|
||||||
@title = site.title
|
@title = site.title
|
||||||
|
|
||||||
|
@ -131,24 +138,14 @@ post '/site/:username/comment' do |username|
|
||||||
redirect "/site/#{username}"
|
redirect "/site/#{username}"
|
||||||
end
|
end
|
||||||
|
|
||||||
DB.transaction do
|
site.add_profile_comment(
|
||||||
site.add_profile_comment(
|
actioning_site_id: current_site.id,
|
||||||
actioning_site_id: current_site.id,
|
message: params[:message]
|
||||||
message: params[:message]
|
)
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect "/site/#{username}"
|
redirect "/site/#{username}"
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/browse_mockup' do
|
|
||||||
erb :'browse_mockup'
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/tips_mockup' do
|
|
||||||
erb :'tips_mockup'
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/stats/?' do
|
get '/stats/?' do
|
||||||
require_admin
|
require_admin
|
||||||
|
|
||||||
|
|
|
@ -333,9 +333,7 @@ class Site < Sequel::Model
|
||||||
|
|
||||||
def block!(site)
|
def block!(site)
|
||||||
block = blockings_dataset.filter(site_id: site.id).first
|
block = blockings_dataset.filter(site_id: site.id).first
|
||||||
DB.transaction do
|
add_blocking site: site
|
||||||
add_blocking site: site
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_blocking?(site)
|
def is_blocking?(site)
|
||||||
|
|
|
@ -216,17 +216,65 @@ describe 'site/settings' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'email' do
|
||||||
|
include Capybara::DSL
|
||||||
|
|
||||||
|
before do
|
||||||
|
EmailWorker.jobs.clear
|
||||||
|
@email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||||
|
@site = Fabricate :site, email: @email
|
||||||
|
page.set_rack_session id: @site.id
|
||||||
|
visit '/settings'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should change email' do
|
||||||
|
@new_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||||
|
fill_in 'email', with: @new_email
|
||||||
|
click_button 'Change Email'
|
||||||
|
page.must_have_content /successfully changed email/i
|
||||||
|
@site.reload
|
||||||
|
@site.email.must_equal @new_email
|
||||||
|
EmailWorker.jobs.length.must_equal 1
|
||||||
|
args = EmailWorker.jobs.first['args'].first
|
||||||
|
args['to'].must_equal @new_email
|
||||||
|
args['subject'].must_match /confirm your email address/i
|
||||||
|
args['body'].must_match /hello #{@site.username}/i
|
||||||
|
args['body'].must_match /#{@site.email_confirmation_token}/
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail for invalid email address' do
|
||||||
|
@new_email = SecureRandom.uuid.gsub '-', ''
|
||||||
|
fill_in 'email', with: @new_email
|
||||||
|
click_button 'Change Email'
|
||||||
|
page.must_have_content /a valid email address is required/i
|
||||||
|
@site.reload
|
||||||
|
@site.email.wont_equal @new_email
|
||||||
|
EmailWorker.jobs.empty?.must_equal true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail for existing email' do
|
||||||
|
@existing_email = "#{SecureRandom.uuid.gsub('-', '')}@example.com"
|
||||||
|
@existing_site = Fabricate :site, email: @existing_email
|
||||||
|
|
||||||
|
fill_in 'email', with: @existing_email
|
||||||
|
click_button 'Change Email'
|
||||||
|
page.must_have_content /this email address already exists on neocities/i
|
||||||
|
@site.reload
|
||||||
|
@site.email.wont_equal @new_email
|
||||||
|
EmailWorker.jobs.empty?.must_equal true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'change password' do
|
describe 'change password' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@site = Fabricate :site, password: 'derpie'
|
@site = Fabricate :site, password: 'derpie'
|
||||||
page.set_rack_session id: @site.id
|
page.set_rack_session id: @site.id
|
||||||
|
visit '/settings'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should change correctly' do
|
it 'should change correctly' do
|
||||||
visit '/settings'
|
|
||||||
|
|
||||||
fill_in 'current_password', with: 'derpie'
|
fill_in 'current_password', with: 'derpie'
|
||||||
fill_in 'new_password', with: 'derpie2'
|
fill_in 'new_password', with: 'derpie2'
|
||||||
fill_in 'new_password_confirm', with: 'derpie2'
|
fill_in 'new_password_confirm', with: 'derpie2'
|
||||||
|
@ -237,5 +285,17 @@ describe 'site/settings' do
|
||||||
@site.valid_password?('derpie').must_equal false
|
@site.valid_password?('derpie').must_equal false
|
||||||
@site.valid_password?('derpie2').must_equal true
|
@site.valid_password?('derpie2').must_equal true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not change for invalid current password' do
|
||||||
|
fill_in 'current_password', with: 'dademurphy'
|
||||||
|
fill_in 'new_password', with: 'derpie2'
|
||||||
|
fill_in 'new_password_confirm', with: 'derpie2'
|
||||||
|
click_button 'Change Password'
|
||||||
|
|
||||||
|
page.must_have_content /provided password does not match the current one/i
|
||||||
|
@site.reload
|
||||||
|
@site.valid_password?('derpie').must_equal true
|
||||||
|
@site.valid_password?('derpie2').must_equal false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
56
tests/acceptance/site_tests.rb
Normal file
56
tests/acceptance/site_tests.rb
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
require_relative './environment.rb'
|
||||||
|
|
||||||
|
describe 'site page' do
|
||||||
|
include Capybara::DSL
|
||||||
|
|
||||||
|
after do
|
||||||
|
Capybara.default_driver = :rack_test
|
||||||
|
end
|
||||||
|
|
||||||
|
it '404s for missing site' do
|
||||||
|
visit '/site/failderp'
|
||||||
|
page.status_code.must_equal 404
|
||||||
|
page.must_have_content /not found/i
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'loads site page' do
|
||||||
|
site = Fabricate :site
|
||||||
|
visit "/site/#{site.username}"
|
||||||
|
page.status_code.must_equal 200
|
||||||
|
page.must_have_content /#{site.username}/
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'allows site blocking' do
|
||||||
|
Capybara.default_driver = :poltergeist
|
||||||
|
tag = SecureRandom.hex 10
|
||||||
|
blocked_site = Fabricate :site, new_tags_string: tag, created_at: 2.weeks.ago, site_changed: true
|
||||||
|
site = Fabricate :site
|
||||||
|
|
||||||
|
page.set_rack_session id: site.id
|
||||||
|
|
||||||
|
visit "/browse?tag=#{tag}"
|
||||||
|
|
||||||
|
page.find('.website-Gallery .title a')['href'].must_match /#{blocked_site.host}/
|
||||||
|
|
||||||
|
visit "/site/#{blocked_site.username}"
|
||||||
|
|
||||||
|
click_link 'Block'
|
||||||
|
click_button 'Block Site'
|
||||||
|
|
||||||
|
visit "/browse?tag=#{tag}"
|
||||||
|
|
||||||
|
page.must_have_content /no active sites found/i
|
||||||
|
|
||||||
|
site.reload
|
||||||
|
site.blockings.length.must_equal 1
|
||||||
|
site.blockings.first.site_id.must_equal blocked_site.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it '404s if site is banned' do
|
||||||
|
site = Fabricate :site
|
||||||
|
site.ban!
|
||||||
|
visit "/site/#{site.username}"
|
||||||
|
page.status_code.must_equal 404
|
||||||
|
page.must_have_content /not found/i
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,8 @@ include WebMock::API
|
||||||
require 'webmock/minitest'
|
require 'webmock/minitest'
|
||||||
require 'sidekiq/testing'
|
require 'sidekiq/testing'
|
||||||
|
|
||||||
|
WebMock.disable_net_connect! allow_localhost: true
|
||||||
|
|
||||||
Sinatra::Application.configure do |app|
|
Sinatra::Application.configure do |app|
|
||||||
app.use RackSessionAccess::Middleware
|
app.use RackSessionAccess::Middleware
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
<meta property="og:image" content=""/>
|
<meta property="og:image" content=""/>
|
||||||
<meta property="og:url" content="//www.neocities.org"/>
|
<meta property="og:url" content="//www.neocities.org"/>
|
||||||
<meta property="og:description" content="Neocities is the new Geocities. Create your own free home page, and do whatever you want with it."/>
|
<meta property="og:description" content="Neocities is the new Geocities. Create your own free home page, and do whatever you want with it."/>
|
||||||
<meta content="pBkqwF1U/KpuF2+f0ZhSf8BnpxYgeU0boCTdnB3joGc=" name="csrf-token" />
|
|
||||||
|
|
||||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
|
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
|
||||||
<link rel="apple-touch-icon-precomposed" href="#apple-icon-144.png" />
|
<link rel="apple-touch-icon-precomposed" href="#apple-icon-144.png" />
|
||||||
|
|
|
@ -14,10 +14,6 @@
|
||||||
<meta property="og:url" content="https://www.neocities.org">
|
<meta property="og:url" content="https://www.neocities.org">
|
||||||
<meta property="og:description" content="Neocities is the new Geocities. Create your own free home page, and do whatever you want with it.">
|
<meta property="og:description" content="Neocities is the new Geocities. Create your own free home page, and do whatever you want with it.">
|
||||||
|
|
||||||
<!--
|
|
||||||
<meta content="<%= csrf_token %>" name="csrf-token" />
|
|
||||||
-->
|
|
||||||
|
|
||||||
<link href="/css/neo.css" rel="stylesheet" type="text/css" media="all"/>
|
<link href="/css/neo.css" rel="stylesheet" type="text/css" media="all"/>
|
||||||
|
|
||||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
|
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue