diff --git a/Gemfile b/Gemfile index 1f7824d9..7e9fb9f5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'sinatra', '2.2.0' +gem 'sinatra' gem 'redis' gem 'redis-namespace' gem 'sequel' @@ -11,9 +11,10 @@ gem 'puma', require: nil gem 'rmagick', require: nil gem 'sidekiq', '~> 5.2.0' gem 'mail' +gem 'net-smtp' gem 'tilt' gem 'erubis' -gem 'stripe', '~> 5.17.0' #, source: 'https://code.stripe.com/' +gem 'stripe' #, source: 'https://code.stripe.com/' gem 'terrapin' gem 'zipruby' gem 'sass', require: nil @@ -26,7 +27,7 @@ gem 'addressable', '>= 2.8.0', require: 'addressable/uri' gem 'paypal-recurring', require: 'paypal/recurring' gem 'geoip' gem 'io-extra', require: 'io/extra' -gem 'rye' +#gem 'rye' gem 'base32' gem 'coveralls', require: false gem 'sanitize' @@ -53,11 +54,11 @@ gem 'activesupport' gem 'facter', require: nil gem 'maxmind-db' gem 'json', '>= 2.3.0' -gem 'nokogiri', '1.13.6' +gem 'nokogiri' +gem 'rss' group :development, :test do gem 'pry' - gem 'pry-byebug' end group :development do @@ -67,19 +68,19 @@ end group :test do gem 'faker' - gem 'fabrication', require: 'fabrication' + gem 'fabrication', require: 'fabrication' gem 'minitest' - gem 'minitest-reporters', require: 'minitest/reporters' - gem 'rack-test', require: 'rack/test' - gem 'mocha', require: nil - gem 'rake', '>= 12.3.3', require: nil - gem 'capybara', require: nil #, '2.10.1', require: nil - gem 'rack_session_access', require: nil - gem 'webmock', '3.5.1', require: nil - gem 'stripe-ruby-mock', '2.5.8', require: 'stripe_mock' + gem 'minitest-reporters', require: 'minitest/reporters' + gem 'rack-test', require: 'rack/test' + gem 'mocha', require: nil + gem 'rake', '>= 12.3.3', require: nil + gem 'capybara', require: nil #, '2.10.1', require: nil + gem 'rack_session_access', require: nil + gem 'webmock', require: nil + gem 'stripe-ruby-mock', '~> 3.1.0.rc3', require: 'stripe_mock' gem 'timecop' gem 'mock_redis' - gem 'simplecov', require: nil + gem 'simplecov', require: nil gem 'm' gem 'apparition', github: 'twalpole/apparition', ref: 'ca86be4d54af835d531dbcd2b86e7b2c77f85f34' end diff --git a/Gemfile.lock b/Gemfile.lock index 826116cc..17b458fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,24 +22,21 @@ GIT GEM remote: https://rubygems.org/ specs: - acme-client (2.0.6) - faraday (>= 0.17, < 2.0.0) - activesupport (6.0.3.1) + acme-client (2.0.11) + faraday (>= 1.0, < 3.0.0) + faraday-retry (~> 1.0) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - annoy (0.5.6) - highline (>= 1.5.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) ansi (1.5.0) - base32 (0.3.2) - bcrypt (3.1.13) - builder (3.2.3) - byebug (11.0.1) - capybara (3.36.0) + base32 (0.3.4) + bcrypt (3.1.18) + builder (3.2.4) + capybara (3.38.0) addressable matrix mini_mime (>= 0.1.3) @@ -50,85 +47,109 @@ GEM xpath (~> 3.2) certified (1.0.0) climate_control (0.2.0) - coderay (1.1.2) - concurrent-ruby (1.1.9) - connection_pool (2.2.5) - coveralls (0.8.23) - json (>= 1.8, < 3) - simplecov (~> 0.16.1) - term-ansicolor (~> 1.3) - thor (>= 0.19.4, < 2.0) - tins (~> 1.6) - crack (0.4.3) - safe_yaml (~> 1.0.0) + coderay (1.1.3) + concurrent-ruby (1.1.10) + connection_pool (2.3.0) + coveralls (0.7.1) + multi_json (~> 1.3) + rest-client + simplecov (>= 0.7) + term-ansicolor + thor + crack (0.4.5) + rexml crass (1.0.6) dante (0.2.0) - docile (1.3.2) + docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - drydock (0.6.9) erubis (2.7.0) - exifr (1.3.6) - fabrication (2.20.2) - facter (2.5.6) - faker (2.4.0) - i18n (~> 1.6.0) - faraday (0.17.3) - multipart-post (>= 1.2, < 3) - faraday_middleware (0.14.0) - faraday (>= 0.7.4, < 1.0) + exifr (1.3.10) + fabrication (2.30.0) + facter (4.2.13) + hocon (~> 1.3) + thor (>= 1.0.1, < 2.0) + faker (3.0.0) + i18n (>= 1.8.11, < 2) + faraday (1.10.2) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + faraday_middleware (1.2.0) + faraday (~> 1.0) feedjira (2.1.4) faraday (>= 0.9) faraday_middleware (>= 0.9) loofah (>= 2.0) sax-machine (>= 1.0) - ffi (1.11.1) + ffi (1.15.5) + ffi-compiler (1.0.1) + ffi (>= 1.0.0) + rake filesize (0.2.0) fspath (3.1.2) gandi (3.3.28) hashie xmlrpc geoip (1.6.4) - hashdiff (1.0.0) - hashie (3.6.0) - highline (2.0.2) + hashdiff (1.0.1) + hashie (5.0.0) hiredis (0.6.3) - hoe (3.22.1) + hocon (1.3.1) + hoe (3.26.0) rake (>= 0.8, < 15.0) htmlentities (4.3.4) - http (4.1.1) - addressable (~> 2.3) + http (5.1.0) + addressable (~> 2.8) http-cookie (~> 1.0) - http-form_data (~> 2.0) - http_parser.rb (~> 0.6.0) + http-form_data (~> 2.2) + llhttp-ffi (~> 0.4.0) http-accept (1.7.0) - http-cookie (1.0.3) + http-cookie (1.0.5) domain_name (~> 0.5) - http-form_data (2.1.1) - http_parser.rb (0.6.0) - i18n (1.6.0) + http-form_data (2.3.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) - image_optim (0.26.5) + image_optim (0.31.1) exifr (~> 1.2, >= 1.2.2) fspath (~> 3.0) - image_size (>= 1.5, < 3) + image_size (>= 1.5, < 4) in_threads (~> 1.3) progress (~> 3.0, >= 3.0.1) - image_optim_pack (0.6.0) + image_optim_pack (0.9.1.20221104-x86_64-linux) fspath (>= 2.1, < 4) image_optim (~> 0.19) - image_optim_pack (0.6.0-x86_64-linux) - fspath (>= 2.1, < 4) - image_optim (~> 0.19) - image_size (2.0.2) - in_threads (1.5.3) - io-extra (1.3.0) + image_size (3.2.0) + in_threads (1.6.0) + io-extra (1.4.0) ipaddress (0.8.3) - json (2.3.1) - loofah (2.5.0) + json (2.6.2) + llhttp-ffi (0.4.0) + ffi-compiler (~> 1.0) + rake (~> 13.0) + loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - m (1.5.1) + m (1.6.0) method_source (>= 0.6.7) rake (>= 0.9.2.2) magic (0.2.9) @@ -136,170 +157,156 @@ GEM mail (2.7.1) mini_mime (>= 0.1.1) matrix (0.4.2) - maxmind-db (1.0.0) - metaclass (0.0.4) - method_source (0.9.2) - mime-types (3.3) + maxmind-db (1.1.1) + method_source (1.0.0) + mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0904) + mime-types-data (3.2022.0105) mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.11.3) - minitest-reporters (1.3.8) + minitest (5.16.3) + minitest-reporters (1.5.0) ansi builder minitest (>= 5.0) ruby-progressbar - mocha (1.9.0) - metaclass (~> 0.0.1) - mock_redis (0.21.0) - monetize (1.9.2) + mocha (2.0.1) + ruby2_keywords (>= 0.0.5) + mock_redis (0.34.0) + ruby2_keywords + monetize (1.12.0) money (~> 6.12) - money (6.13.4) + money (6.16.0) i18n (>= 0.6.4, <= 2) - msgpack (1.3.1) - multi_json (1.13.1) - multipart-post (2.1.1) - mustermann (1.1.1) + msgpack (1.6.0) + multi_json (1.15.0) + multipart-post (2.2.3) + mustermann (3.0.0) ruby2_keywords (~> 0.0.1) - net-scp (2.0.0) - net-ssh (>= 2.6.5, < 6.0.0) - net-ssh (5.2.0) + net-protocol (0.1.3) + timeout + net-smtp (0.3.3) + net-protocol netrc (0.11.0) nio4r (2.5.8) - nokogiri (1.13.6) - mini_portile2 (~> 2.8.0) + nokogiri (1.13.9-x86_64-linux) racc (~> 1.4) - nokogiri (1.13.6-x86_64-linux) - racc (~> 1.4) - nokogumbo (2.0.2) - nokogiri (~> 1.8, >= 1.8.4) - ox (2.11.0) + ox (2.14.11) paypal-recurring (1.1.0) - pg (1.1.4) - progress (3.5.2) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.7.0) - byebug (~> 11.0) - pry (~> 0.10) - public_suffix (4.0.6) - puma (5.6.4) + pg (1.4.4) + progress (3.6.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (5.0.0) + puma (6.0.0) nio4r (~> 2.0) racc (1.6.0) - rack (2.2.3.1) - rack-cache (1.9.0) + rack (2.2.4) + rack-cache (1.13.0) rack (>= 0.4) - rack-protection (2.2.0) + rack-protection (3.0.2) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) + rack-test (2.0.2) + rack (>= 1.3) rack_session_access (0.2.0) builder (>= 2.0.0) rack (>= 1.0.0) - rake (13.0.1) - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rake (13.0.6) + rb-fsevent (0.11.2) + rb-inotify (0.10.1) ffi (~> 1.0) - redis (3.3.5) - redis-namespace (1.6.0) - redis (>= 3.0.4) - regexp_parser (2.1.1) + redis (4.5.1) + redis-namespace (1.9.0) + redis (>= 4) + regexp_parser (2.6.0) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + rexml (3.2.5) rinku (2.0.6) - rmagick (4.1.2) - ruby-progressbar (1.10.1) + rmagick (5.0.0) + rss (0.2.9) + rexml + ruby-progressbar (1.11.0) ruby2_keywords (0.0.5) - rye (0.9.13) - annoy - docile (>= 1.0.1) - highline (>= 1.5.1) - net-scp (>= 1.0.2) - net-ssh (>= 2.0.13) - sysinfo (>= 0.8.1) - safe_yaml (1.0.5) - sanitize (5.2.1) + sanitize (6.0.0) crass (~> 1.0.2) - nokogiri (>= 1.8.0) - nokogumbo (~> 2.0) + nokogiri (>= 1.12.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) sax-machine (1.3.2) - sequel (5.24.0) - sequel_pg (1.12.2) - pg (>= 0.18.0) + sequel (5.62.0) + sequel_pg (1.17.0) + pg (>= 0.18.0, != 1.2.0) sequel (>= 4.38.0) shotgun (0.9.2) rack (>= 1.0) - sidekiq (5.2.0) + sidekiq (5.2.10) connection_pool (~> 2.2, >= 2.2.2) + rack (~> 2.0) rack-protection (>= 1.5.0) - redis (>= 3.3.5, < 5) - simplecov (0.16.1) + redis (~> 4.5, < 4.6.0) + simplecov (0.21.2) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - simpleidn (0.1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + simpleidn (0.2.1) unf (~> 0.1.4) - sinatra (2.2.0) - mustermann (~> 1.0) - rack (~> 2.2) - rack-protection (= 2.2.0) + sinatra (3.0.2) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.0.2) tilt (~> 2.0) sinatra-flash (0.3.0) sinatra (>= 1.0.0) sinatra-xsendfile (0.4.2) sinatra (>= 0.9.1) - storable (0.8.9) - stripe (5.17.0) - stripe-ruby-mock (2.5.8) + stripe (5.55.0) + stripe-ruby-mock (3.1.0.rc3) dante (>= 0.2.0) multi_json (~> 1.0) - stripe (>= 2.0.3) - sysinfo (0.8.1) - drydock - storable + stripe (> 5, < 6) + sync (0.5.0) term-ansicolor (1.7.1) tins (~> 1.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (0.20.3) + thor (1.2.1) thread (0.2.2) - thread_safe (0.3.6) - tilt (2.0.9) - timecop (0.9.1) - tins (1.21.1) - tzinfo (1.2.7) - thread_safe (~> 0.1) + tilt (2.0.11) + timecop (0.9.5) + timeout (0.3.0) + tins (1.31.1) + sync + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext - unf_ext (0.0.7.6) + unf_ext (0.0.8.2) uuidtools (2.1.5) - webmock (3.5.1) - addressable (>= 2.3.6) + webmock (3.18.1) + addressable (>= 2.8.0) crack (>= 0.3.2) - hashdiff + hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.7.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - will_paginate (3.1.8) - xmlrpc (0.3.0) + will_paginate (3.3.1) + xmlrpc (0.3.2) + webrick xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.3.0) zipruby (0.3.6) PLATFORMS - ruby x86_64-linux DEPENDENCIES @@ -340,11 +347,11 @@ DEPENDENCIES mock_redis monetize msgpack - nokogiri (= 1.13.6) + net-smtp + nokogiri paypal-recurring pg pry - pry-byebug puma rack-cache rack-test @@ -355,7 +362,7 @@ DEPENDENCIES rest-client rinku rmagick - rye + rss sanitize sass sequel @@ -364,19 +371,19 @@ DEPENDENCIES sidekiq (~> 5.2.0) simplecov simpleidn - sinatra (= 2.2.0) + sinatra sinatra-flash sinatra-xsendfile - stripe (~> 5.17.0) - stripe-ruby-mock (= 2.5.8) + stripe + stripe-ruby-mock (~> 3.1.0.rc3) terrapin thread tilt timecop - webmock (= 3.5.1) + webmock will_paginate xmlrpc zipruby BUNDLED WITH - 2.1.4 + 2.3.10 diff --git a/environment.rb b/environment.rb index f7b02b22..54110bf3 100644 --- a/environment.rb +++ b/environment.rb @@ -12,7 +12,14 @@ Bundler.require Bundler.require :development if ENV['RACK_ENV'] == 'development' require 'tilt/erubis' -require 'active_support/core_ext/integer/time' +require 'active_support' +require 'active_support/time' + +class File + def self.exists?(val) + self.exist?(val) + end +end Dir['./ext/**/*.rb'].each {|f| require f} @@ -162,4 +169,6 @@ $gandi = Gandi::Session.new $config['gandi_api_key'], gandi_opts $image_optim = ImageOptim.new pngout: false, svgo: false -Money.locale_backend = nil \ No newline at end of file +Money.locale_backend = nil +Money.default_currency = Money::Currency.new("USD") +Money.rounding_mode = BigDecimal::ROUND_HALF_UP diff --git a/migrations/035_add_missing_indexes.rb b/migrations/035_add_missing_indexes.rb index b45688be..cf88b4c8 100644 --- a/migrations/035_add_missing_indexes.rb +++ b/migrations/035_add_missing_indexes.rb @@ -1,10 +1,10 @@ Sequel.migration do change do - alter_table(:events) { add_index :created_at } - alter_table(:sites) { add_index :updated_at } + #alter_table(:events) { add_index :created_at } + alter_table(:sites) { add_index :updated_at } alter_table(:comment_likes) { add_index :comment_id } alter_table(:comment_likes) { add_index :actioning_site_id } alter_table(:sites_tags) { add_index :tag_id } alter_table(:tags) { add_index :name } end -end \ No newline at end of file +end diff --git a/migrations/067_add_missing_stat_indexes.rb b/migrations/067_add_missing_stat_indexes.rb index df7ffca9..b1bcc97a 100644 --- a/migrations/067_add_missing_stat_indexes.rb +++ b/migrations/067_add_missing_stat_indexes.rb @@ -1,13 +1,13 @@ Sequel.migration do up { DB['create index stat_referrers_hash_multi on stat_referrers (site_id, md5(url))'].first - DB.add_index :stat_locations, :site_id - DB.add_index :stat_paths, :site_id + #DB.add_index :stat_locations, :site_id + #DB.add_index :stat_paths, :site_id } down { DB['drop index stat_referrers_hash_multi'].first - DB.drop_index :stat_locations, :site_id - DB.drop_index :stat_paths, :site_id + #DB.drop_index :stat_locations, :site_id + #DB.drop_index :stat_paths, :site_id } end diff --git a/migrations/068_add_stat_referrer_site_id_index.rb b/migrations/068_add_stat_referrer_site_id_index.rb index 8bd91a7b..64fb234c 100644 --- a/migrations/068_add_stat_referrer_site_id_index.rb +++ b/migrations/068_add_stat_referrer_site_id_index.rb @@ -1,9 +1,9 @@ Sequel.migration do up { - DB.add_index :stat_referrers, :site_id + #DB.add_index :stat_referrers, :site_id } down { - DB.drop_index :stat_referrers, :site_id + #DB.drop_index :stat_referrers, :site_id } end diff --git a/migrations/069_add_stat_created_indexes.rb b/migrations/069_add_stat_created_indexes.rb index f041c183..0cf355ce 100644 --- a/migrations/069_add_stat_created_indexes.rb +++ b/migrations/069_add_stat_created_indexes.rb @@ -1,13 +1,13 @@ Sequel.migration do up { - %i{stat_referrers stat_locations stat_paths}.each do |t| - DB.add_index t, :created_at - end + #%i{stat_referrers stat_locations stat_paths}.each do |t| + # DB.add_index t, :created_at + #end } down { - %i{stat_referrers stat_locations stat_paths}.each do |t| - DB.drop_index t, :created_at - end + #%i{stat_referrers stat_locations stat_paths}.each do |t| + # DB.drop_index t, :created_at + #end } end diff --git a/migrations/102_parent_sites_index.rb b/migrations/102_parent_sites_index.rb index 80045de7..f7a934b9 100644 --- a/migrations/102_parent_sites_index.rb +++ b/migrations/102_parent_sites_index.rb @@ -1,9 +1,9 @@ Sequel.migration do up { - DB.add_index :sites, :parent_site_id + #DB.add_index :sites, :parent_site_id } down { - DB.drop_index :sites, :parent_site_id + #DB.drop_index :sites, :parent_site_id } end diff --git a/migrations/112_sites_featured_at_index.rb b/migrations/112_sites_featured_at_index.rb index 4aadca6d..33480f12 100644 --- a/migrations/112_sites_featured_at_index.rb +++ b/migrations/112_sites_featured_at_index.rb @@ -1,9 +1,9 @@ Sequel.migration do up { - DB.add_index :sites, :featured_at + #DB.add_index :sites, :featured_at } down { - DB.drop_index :sites, :featured_at + #DB.drop_index :sites, :featured_at } end diff --git a/models/archive.rb b/models/archive.rb index 49aeacac..80de5630 100644 --- a/models/archive.rb +++ b/models/archive.rb @@ -13,6 +13,7 @@ class Archive < Sequel::Model end def unpin + return nil # Not ideal. An SoA version is in progress. if ENV['RACK_ENV'] == 'production' && $config['ipfs_ssh_host'] && $config['ipfs_ssh_user'] rbox = Rye::Box.new $config['ipfs_ssh_host'], :user => $config['ipfs_ssh_user'] diff --git a/models/site.rb b/models/site.rb index cb46d0fb..55b8d85a 100644 --- a/models/site.rb +++ b/models/site.rb @@ -766,10 +766,11 @@ class Site < Sequel::Model purge_cache path end - Rye::Cmd.add_command :ipfs + #Rye::Cmd.add_command :ipfs def add_to_ipfs # Not ideal. An SoA version is in progress. + return nil if archives_dataset.count > Archive::MAXIMUM_ARCHIVES_PER_SITE archives_dataset.order(:updated_at).first.destroy @@ -836,7 +837,7 @@ class Site < Sequel::Model path = scrubbed_path path relative_path = files_path path - if Dir.exists?(relative_path) || File.exist?(relative_path) + if Dir.exist?(relative_path) || File.exist?(relative_path) return 'Directory (or file) already exists.' end diff --git a/rainbows_config.rb b/rainbows_config.rb index e30fd79a..e0f66bd5 100644 --- a/rainbows_config.rb +++ b/rainbows_config.rb @@ -35,7 +35,7 @@ Rainbows! do before_fork do |server, worker| old_pid = "/var/run/neocities/neocities.pid.oldbin" - if File.exists?(old_pid) && server.pid != old_pid + if File.exist?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH diff --git a/tests/acceptance/admin_tests.rb b/tests/acceptance/admin_tests.rb index 62a3ebe5..0a49831f 100644 --- a/tests/acceptance/admin_tests.rb +++ b/tests/acceptance/admin_tests.rb @@ -15,13 +15,13 @@ describe '/admin' do include Capybara::DSL it 'works for admin site' do - page.body.must_match /Administration/ + _(page.body).must_match /Administration/ end it 'fails for site without admin' do page.set_rack_session id: @site.id visit '/admin' - page.current_path.must_equal '/' + _(page.current_path).must_equal '/' end end @@ -29,9 +29,10 @@ describe '/admin' do include Capybara::DSL before do - @stripe_helper = StripeMock.create_test_helper + stripe_helper = StripeMock.create_test_helper StripeMock.start - @plan = @stripe_helper.create_plan id: 'special', amount: 0 + stripe_helper.create_product(id: 'supporter', name: 'Supporter Plan') + @plan = stripe_helper.create_plan(product: 'supporter', amount: 0) end after do @@ -43,10 +44,10 @@ describe '/admin' do fill_in 'username', with: @site.username click_button 'Upgrade to Supporter' @site.reload - @site.stripe_customer_id.wont_be_nil - @site.stripe_subscription_id.wont_be_nil - @site.values[:plan_type].must_equal 'special' - @site.supporter?.must_equal true + _(@site.stripe_customer_id).wont_be_nil + _(@site.stripe_subscription_id).wont_be_nil + _(@site.values[:plan_type]).must_equal 'special' + _(@site.supporter?).must_equal true end end @@ -82,20 +83,20 @@ describe '/admin' do click_button 'Send' relevant_jobs = EmailWorker.jobs.select{|j| relevant_emails.include?(j['args'].first['to']) } - relevant_jobs.length.must_equal sites_emailed_count + _(relevant_jobs.length).must_equal sites_emailed_count relevant_jobs.each do |job| args = job['args'].first - args['from'].must_equal 'Kyle from Neocities ' - args['subject'].must_equal 'Subject Test' - args['body'].must_equal 'Body Test' + _(args['from']).must_equal 'Kyle from Neocities ' + _(args['subject']).must_equal 'Subject Test' + _(args['body']).must_equal 'Body Test' end - relevant_jobs.select {|j| j['at'].nil? || j['at'] == Time.now.to_f}.length.must_equal 1 - relevant_jobs.select {|j| j['at'] == (Time.now + 0.5).to_f}.length.must_equal 1 + _(relevant_jobs.select {|j| j['at'].nil? || j['at'] == Time.now.to_f}.length).must_equal 1 + _(relevant_jobs.select {|j| j['at'] == (Time.now + 0.5).to_f}.length).must_equal 1 - relevant_jobs.select {|j| j['at'] == (time+1.day.to_i).to_f}.length.must_equal 1 - relevant_jobs.select {|j| j['at'] == (time+1.day.to_i+0.5).to_f}.length.must_equal 1 + _(relevant_jobs.select {|j| j['at'] == (time+1.day.to_i).to_f}.length).must_equal 1 + _(relevant_jobs.select {|j| j['at'] == (time+1.day.to_i+0.5).to_f}.length).must_equal 1 end end end diff --git a/tests/acceptance/dashboard_tests.rb b/tests/acceptance/dashboard_tests.rb index 86dd1c9c..6856523b 100644 --- a/tests/acceptance/dashboard_tests.rb +++ b/tests/acceptance/dashboard_tests.rb @@ -14,9 +14,9 @@ describe 'dashboard' do end it 'records a dashboard access' do - @site.reload.dashboard_accessed.must_equal false + _(@site.reload.dashboard_accessed).must_equal false visit '/dashboard' - @site.reload.dashboard_accessed.must_equal true + _(@site.reload.dashboard_accessed).must_equal true end it 'creates a base directory' do @@ -25,8 +25,8 @@ describe 'dashboard' do fill_in 'name', with: 'testimages' #click_button 'Create' all('#createDir button[type=submit]').first.click - page.must_have_content /testimages/ - File.directory?(@site.files_path('testimages')).must_equal true + _(page).must_have_content /testimages/ + _(File.directory?(@site.files_path('testimages'))).must_equal true end it 'creates a new file' do @@ -36,8 +36,8 @@ describe 'dashboard' do fill_in 'filename', with: "#{random}.html" #click_button 'Create' all('#createFile button[type=submit]').first.click - page.must_have_content /#{random}\.html/ - File.exist?(@site.files_path("#{random}.html")).must_equal true + _(page).must_have_content /#{random}\.html/ + _(File.exist?(@site.files_path("#{random}.html"))).must_equal true end end end diff --git a/tests/acceptance/education_tests.rb b/tests/acceptance/education_tests.rb index d2e609bb..5d45f4ef 100644 --- a/tests/acceptance/education_tests.rb +++ b/tests/acceptance/education_tests.rb @@ -16,7 +16,7 @@ describe 'signup' do Capybara.default_driver = :apparition Capybara.reset_sessions! visit '/education' - page.must_have_content 'Neocities' # Used to force load wait + _(page).must_have_content 'Neocities' # Used to force load wait end after do @@ -31,30 +31,30 @@ describe 'signup' do fill_in 'email', with: @site[:email] fill_in 'new_tags_string', with: 'nope' click_button 'Create My Site' - page.wont_have_content /Let's Get Started/ + _(page).wont_have_content /Let's Get Started/ end it 'succeeds with valid data' do fill_in_valid click_button 'Create My Site' - page.must_have_content /Let's Get Started/ + _(page).must_have_content /Let's Get Started/ index_file_path = File.join Site::SITE_FILES_ROOT, Site.sharding_dir(@site[:username]), @site[:username], 'index.html' - File.exist?(index_file_path).must_equal true + _(File.exist?(index_file_path)).must_equal true site = Site[username: @site[:username]] - site.site_files.length.must_equal 4 - site.site_changed.must_equal false - site.site_updated_at.must_be_nil - site.is_education.must_equal true - site.tags.length.must_equal 1 - site.tags.first.name.must_equal @class_tag + _(site.site_files.length).must_equal 4 + _(site.site_changed).must_equal false + _(site.site_updated_at).must_be_nil + _(site.is_education).must_equal true + _(site.tags.length).must_equal 1 + _(site.tags.first.name).must_equal @class_tag end it 'fails for multiple tags' do fill_in_valid fill_in :new_tags_string, with: 'derp, ie' click_button 'Create My Site' - page.must_have_content 'Must only have one tag' + _(page).must_have_content 'Must only have one tag' end end diff --git a/tests/acceptance/index_tests.rb b/tests/acceptance/index_tests.rb index 97431637..469aecae 100644 --- a/tests/acceptance/index_tests.rb +++ b/tests/acceptance/index_tests.rb @@ -11,8 +11,8 @@ describe '/' do it 'loads the news feed with welcome' do visit '/' - page.body.must_match /Thanks for joining the Neocities community/i - page.body.wont_match /You aren’t following any websites yet/i + _(page.body).must_match /Thanks for joining the Neocities community/i + _(page.body).wont_match /You aren’t following any websites yet/i end it 'displays a follow and an unrelated follow' do @@ -21,7 +21,7 @@ describe '/' do @another_site = Fabricate :site @followed_site.toggle_follow @another_site visit '/' - find('.news-item', match: :first).text.must_match /#{@followed_site.username} followed #{@another_site.username}/i + _(find('.news-item', match: :first).text).must_match /#{@followed_site.username} followed #{@another_site.username}/i end it 'loads my activities only' do @@ -30,14 +30,14 @@ describe '/' do @another_site = Fabricate :site @followed_site.toggle_follow @another_site visit '/?activity=mine' - find('.news-item').text.must_match //i + _(find('.news-item').text).must_match //i end it 'loads a specific event with the id' do @followed_site = Fabricate :site @site.toggle_follow @followed_site visit "/?event_id=#{@followed_site.events.first.id}" - find('.news-item').text.must_match /you followed #{@followed_site.username}/i + _(find('.news-item').text).must_match /you followed #{@followed_site.username}/i end end @@ -57,8 +57,8 @@ describe '/' do links.each do |l| visit '/' find('a', text: l.first, match: :first).click - page.status_code.must_equal 200 - page.current_path.must_equal "/#{l.last}" + _(page.status_code).must_equal 200 + _(page.current_path).must_equal "/#{l.last}" end end end @@ -74,29 +74,29 @@ describe '/' do end it 'works for valid email' do - page.current_url.must_match /\/forgot_username$/ + _(page.current_url).must_match /\/forgot_username$/ fill_in :email, with: @site.email click_button 'Find username' - URI.parse(page.current_url).path.must_equal '/' - page.must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it' + _(URI.parse(page.current_url).path).must_equal '/' + _(page).must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it' email_args = EmailWorker.jobs.first['args'].first - email_args['to'].must_equal @site.email - email_args['subject'].must_match /username lookup/i - email_args['body'].must_match /your username is #{@site.username}/i + _(email_args['to']).must_equal @site.email + _(email_args['subject']).must_match /username lookup/i + _(email_args['body']).must_match /your username is #{@site.username}/i end it 'fails silently for unknown email' do fill_in :email, with: 'N-O-P-E@example.com' click_button 'Find username' - URI.parse(page.current_url).path.must_equal '/' - page.must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it' - EmailWorker.jobs.length.must_equal 0 + _(URI.parse(page.current_url).path).must_equal '/' + _(page).must_have_content 'If your email was valid, the Neocities Cat will send an e-mail with your username in it' + _(EmailWorker.jobs.length).must_equal 0 end it 'fails for no input' do click_button 'Find username' - URI.parse(page.current_url).path.must_equal '/forgot_username' - page.must_have_content 'Cannot use an empty email address' + _(URI.parse(page.current_url).path).must_equal '/forgot_username' + _(page).must_have_content 'Cannot use an empty email address' end end end diff --git a/tests/acceptance/password_reset_tests.rb b/tests/acceptance/password_reset_tests.rb index 1cdb9b0d..9fbe5f64 100644 --- a/tests/acceptance/password_reset_tests.rb +++ b/tests/acceptance/password_reset_tests.rb @@ -10,7 +10,7 @@ describe '/password_reset' do it 'should load the password reset page' do visit '/password_reset' - page.body.must_match /Reset Password/ + _(page.body).must_match /Reset Password/ end it 'should not load password reset if logged in' do @@ -18,14 +18,14 @@ describe '/password_reset' do page.set_rack_session id: @site.id visit '/password_reset' - URI.parse(page.current_url).path.must_equal '/' + _(URI.parse(page.current_url).path).must_equal '/' end it 'errors for missing email' do visit '/password_reset' click_button 'Send Reset Token' - URI.parse(page.current_url).path.must_equal '/password_reset' - body.must_match /You must enter a valid email address/ + _(URI.parse(page.current_url).path).must_equal '/password_reset' + _(body).must_match /You must enter a valid email address/ end it 'fails for invalid username or token' do @@ -45,8 +45,8 @@ describe '/password_reset' do ].each do |params| visit "/password_reset_confirm?#{Rack::Utils.build_query params}" - page.must_have_content 'Could not find a site with this username and token' - @site.reload.password_reset_confirmed.must_equal false + _(page).must_have_content 'Could not find a site with this username and token' + _(@site.reload.password_reset_confirmed).must_equal false end [ @@ -55,8 +55,8 @@ describe '/password_reset' do {username: '', token: ''} ].each do |params| visit "/password_reset_confirm?#{Rack::Utils.build_query params}" - page.must_have_content 'Token cannot be empty' - @site.reload.password_reset_confirmed.must_equal false + _(page).must_have_content 'Token cannot be empty' + _(@site.reload.password_reset_confirmed).must_equal false end end @@ -67,24 +67,24 @@ describe '/password_reset' do fill_in 'email', with: @site.email click_button 'Send Reset Token' - body.must_match /send an e-mail to your account with password reset instructions/ - @site.reload.password_reset_token.blank?.must_equal false - EmailWorker.jobs.first['args'].first['body'].must_match /#{Rack::Utils.build_query(username: @site.username, token: @site.password_reset_token)}/ + _(body).must_match /send an e-mail to your account with password reset instructions/ + _(@site.reload.password_reset_token.blank?).must_equal false + _(EmailWorker.jobs.first['args'].first['body']).must_match /#{Rack::Utils.build_query(username: @site.username, token: @site.password_reset_token)}/ visit "/password_reset_confirm?#{Rack::Utils.build_query username: @site.username, token: @site.reload.password_reset_token}" - page.current_url.must_match /.+\/settings#password/ + _(page.current_url).must_match /.+\/settings#password/ fill_in 'new_password', with: 'n3wp4s$' fill_in 'new_password_confirm', with: 'n3wp4s$' click_button 'Change Password' - page.current_url.must_match /.+\/settings#password/ - page.must_have_content 'Successfully changed password' - Site.valid_login?(@site.username, 'n3wp4s$').must_equal true - page.get_rack_session['id'].must_equal @site.id - @site.reload.password_reset_token.must_be_nil - @site.password_reset_confirmed.must_equal false + _(page.current_url).must_match /.+\/settings#password/ + _(page).must_have_content 'Successfully changed password' + _(Site.valid_login?(@site.username, 'n3wp4s$')).must_equal true + _(page.get_rack_session['id']).must_equal @site.id + _(@site.reload.password_reset_token).must_be_nil + _(@site.password_reset_confirmed).must_equal false end end diff --git a/tests/acceptance/settings/account_tests.rb b/tests/acceptance/settings/account_tests.rb index 2e6d0329..31a0ad8d 100644 --- a/tests/acceptance/settings/account_tests.rb +++ b/tests/acceptance/settings/account_tests.rb @@ -20,38 +20,38 @@ describe 'site/settings' do fill_in 'email', with: @new_email click_button 'Change Email' - page.must_have_content /enter the confirmation code here/ + _(page).must_have_content /enter the confirmation code here/ fill_in 'token', with: @site.reload.email_confirmation_token click_button 'Confirm Email' - page.must_have_content /Email address changed/i + _(page).must_have_content /Email address changed/i @site.reload - @site.email.must_equal @new_email - @site.password_reset_token.must_be_nil + _(@site.email).must_equal @new_email + _(@site.password_reset_token).must_be_nil - EmailWorker.jobs.length.must_equal 2 + _(EmailWorker.jobs.length).must_equal 2 args = EmailWorker.jobs.select {|job| job['args'].first['subject'] =~ /confirm your email address/i}.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}/ + _(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}/ args = EmailWorker.jobs.select {|job| job['args'].first['subject'] =~ /your email address.+changed/i}.first['args'].first - args['body'].must_match /previous email.+#{original_email}/ - args['body'].must_match /new email.+#{@site.email}/ + _(args['body']).must_match /previous email.+#{original_email}/ + _(args['body']).must_match /new email.+#{@site.email}/ 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 + _(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 + _(@site.email).wont_equal @new_email + _(EmailWorker.jobs.empty?).must_equal true end it 'should fail for existing email' do @@ -60,10 +60,10 @@ describe 'site/settings' do fill_in 'email', with: @existing_email click_button 'Change Email' - page.must_have_content /this email address already exists on neocities/i + _(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 + _(@site.email).wont_equal @new_email + _(EmailWorker.jobs.empty?).must_equal true end it 'should update email preferences' do @@ -71,15 +71,15 @@ describe 'site/settings' do uncheck 'send_comment_emails' uncheck 'send_follow_emails' - @site.send_emails.must_equal true - @site.send_comment_emails.must_equal true - @site.send_follow_emails.must_equal true + _(@site.send_emails).must_equal true + _(@site.send_comment_emails).must_equal true + _(@site.send_follow_emails).must_equal true click_button 'Update Notification Settings' @site.reload - @site.send_emails.must_equal false - @site.send_comment_emails.must_equal false - @site.send_follow_emails.must_equal false + _(@site.send_emails).must_equal false + _(@site.send_comment_emails).must_equal false + _(@site.send_follow_emails).must_equal false end end @@ -112,13 +112,13 @@ describe 'site/settings' do EmailWorker.drain email = Mail::TestMailer.deliveries.first - email.body.to_s.must_match @email_unsubscribe_url - @site.send_emails.must_equal true + _(email.body.to_s).must_match @email_unsubscribe_url + _(@site.send_emails).must_equal true visit '/settings/unsubscribe_email?'+@params_query - page.body.must_match /You have been successfully unsubscribed.+#{@site.email}/i + _(page.body).must_match /You have been successfully unsubscribed.+#{@site.email}/i - @site.reload.send_emails.must_equal false + _(@site.reload.send_emails).must_equal false end it 'should fail to subscribe for bad token' do @@ -142,12 +142,12 @@ describe 'site/settings' do fill_in 'new_password_confirm', with: 'derpie2' click_button 'Change Password' - page.must_have_content /successfully changed password/i + _(page).must_have_content /successfully changed password/i @site.reload - @site.valid_password?('derpie').must_equal false - @site.valid_password?('derpie2').must_equal true + _(@site.valid_password?('derpie')).must_equal false + _(@site.valid_password?('derpie2')).must_equal true - EmailWorker.jobs.select {|job| job['args'].first['subject'] =~ /password has been changed/i}.length.must_equal 1 + _(EmailWorker.jobs.select {|job| job['args'].first['subject'] =~ /password has been changed/i}.length).must_equal 1 end it 'should not change for invalid current password' do @@ -156,12 +156,12 @@ describe 'site/settings' do fill_in 'new_password_confirm', with: 'derpie2' click_button 'Change Password' - page.must_have_content /provided password does not match the current one/i + _(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 + _(@site.valid_password?('derpie')).must_equal true + _(@site.valid_password?('derpie2')).must_equal false - EmailWorker.jobs.length.must_equal 0 + _(EmailWorker.jobs.length).must_equal 0 end end end diff --git a/tests/acceptance/settings/site_tests.rb b/tests/acceptance/settings/site_tests.rb index 7f90afe8..78b94de0 100644 --- a/tests/acceptance/settings/site_tests.rb +++ b/tests/acceptance/settings/site_tests.rb @@ -93,13 +93,13 @@ describe 'site/settings' do page.set_rack_session id: @other_site.id visit "/settings/#{@parent_site.username}" - page.current_path.must_equal '/' # This could be better + _(page.current_path).must_equal '/' # This could be better end it 'allows child site editing from parent' do page.set_rack_session id: @parent_site.id visit "/settings/#{@child_site.username}" - page.current_path.must_equal "/settings/#{@child_site.username}" + _(page.current_path).must_equal "/settings/#{@child_site.username}" end end @@ -114,33 +114,33 @@ describe 'site/settings' do end after do - Site[username: @site[:username]].wont_equal nil + _(Site[username: @site[:username]]).wont_equal nil end it 'fails for blank username' do fill_in 'name', with: '' click_button 'Change Name' - page.must_have_content /cannot be blank/i - Site[username: ''].must_be_nil + _(page).must_have_content /cannot be blank/i + _(Site[username: '']).must_be_nil end it 'fails for subdir periods' do fill_in 'name', with: '../hack' click_button 'Change Name' - page.must_have_content /Usernames can only contain/i - Site[username: '../hack'].must_be_nil + _(page).must_have_content /Usernames can only contain/i + _(Site[username: '../hack']).must_be_nil end it 'fails for same username' do fill_in 'name', with: @site.username click_button 'Change Name' - page.must_have_content /You already have this name/ + _(page).must_have_content /You already have this name/ end it 'fails for same username with DiFfErEnT CaSiNg' do fill_in 'name', with: @site.username.upcase click_button 'Change Name' - page.must_have_content /You already have this name/ + _(page).must_have_content /You already have this name/ end end end @@ -163,8 +163,8 @@ describe 'delete' do fill_in 'username', with: 'NOPE' click_button 'Delete Site' - page.body.must_match /Site user name and entered user name did not match/i - @site.reload.is_deleted.must_equal false + _(page.body).must_match /Site user name and entered user name did not match/i + _(@site.reload.is_deleted).must_equal false end it 'succeeds' do @@ -175,19 +175,19 @@ describe 'delete' do click_button 'Delete Site' @site.reload - @site.is_deleted.must_equal true - @site.deleted_reason.must_equal deleted_reason - page.current_path.must_equal '/' + _(@site.is_deleted).must_equal true + _(@site.deleted_reason).must_equal deleted_reason + _(page.current_path).must_equal '/' - File.exist?(@site.files_path('./index.html')).must_equal false - Dir.exist?(@site.files_path).must_equal false + _(File.exist?(@site.files_path('./index.html'))).must_equal false + _(Dir.exist?(@site.files_path)).must_equal false path = File.join Site::DELETED_SITES_ROOT, Site.sharding_dir(@site.username), @site.username - Dir.exist?(path).must_equal true - File.exist?(File.join(path, 'index.html')).must_equal true + _(Dir.exist?(path)).must_equal true + _(File.exist?(File.join(path, 'index.html'))).must_equal true visit "/site/#{@site.username}" - page.status_code.must_equal 404 + _(page.status_code).must_equal 404 end it 'stops charging for supporter account' do @@ -215,10 +215,10 @@ describe 'delete' do fill_in 'deleted_reason', with: 'derp' click_button 'Delete Site' - Stripe::Customer.retrieve(@site.stripe_customer_id).subscriptions.count.must_equal 0 + _(Stripe::Customer.retrieve(@site.stripe_customer_id).subscriptions.count).must_equal 0 @site.reload - @site.stripe_subscription_id.must_be_nil - @site.is_deleted.must_equal true + _(@site.stripe_subscription_id).must_be_nil + _(@site.is_deleted).must_equal true end it 'should fail unless owned by current user' do @@ -230,16 +230,16 @@ describe 'delete' do deleted_reason: 'Dade Murphy enters Acid Burns turf' } - page.driver.status_code.must_equal 302 - URI.parse(page.driver.response_headers['Location']).path.must_equal '/' + _(page.driver.status_code).must_equal 302 + _(URI.parse(page.driver.response_headers['Location']).path).must_equal '/' someone_elses_site.reload - someone_elses_site.is_deleted.must_equal false + _(someone_elses_site.is_deleted).must_equal false end it 'should not show NSFW tab for admin NSFW flag' do owned_site = Fabricate :site, parent_site_id: @site.id, admin_nsfw: true visit "/settings/#{owned_site.username}" - page.body.wont_match /18\+/ + _(page.body).wont_match /18\+/ end it 'should succeed if you own the site' do @@ -250,15 +250,15 @@ describe 'delete' do @site.reload owned_site.reload - owned_site.is_deleted.must_equal true - @site.is_deleted.must_equal false + _(owned_site.is_deleted).must_equal true + _(@site.is_deleted).must_equal false - page.current_path.must_equal "/settings" + _(page.current_path).must_equal "/settings" end it 'fails to delete parent site if children exist' do owned_site = Fabricate :site, parent_site_id: @site.id visit "/settings/#{@site.username}#delete" - page.body.must_match /You cannot delete the parent site without deleting the children sites first/i + _(page.body).must_match /You cannot delete the parent site without deleting the children sites first/i end end diff --git a/tests/acceptance/signin_tests.rb b/tests/acceptance/signin_tests.rb index c3676dd7..a263c41d 100644 --- a/tests/acceptance/signin_tests.rb +++ b/tests/acceptance/signin_tests.rb @@ -17,26 +17,26 @@ describe 'signin' do pass = SecureRandom.hex @site = Fabricate :site, password: pass @site.destroy - Dir.exist?(@site.files_path).must_equal false - Dir.exist?(@site.deleted_files_path).must_equal true + _(Dir.exist?(@site.files_path)).must_equal false + _(Dir.exist?(@site.deleted_files_path)).must_equal true visit '/signin' fill_in 'username', with: @site.username fill_in 'password', with: pass click_button 'Sign In' - page.must_have_content 'Restore Site' + _(page).must_have_content 'Restore Site' click_button 'Restore Site' - Dir.exist?(@site.deleted_files_path).must_equal false - Dir.exist?(@site.files_path).must_equal true - @site.reload.is_deleted.must_equal false + _(Dir.exist?(@site.deleted_files_path)).must_equal false + _(Dir.exist?(@site.files_path)).must_equal true + _(@site.reload.is_deleted).must_equal false end it 'fails for invalid signin' do visit '/' click_link 'Sign In' - page.must_have_content 'Welcome Back' + _(page).must_have_content 'Welcome Back' fill_in_valid click_button 'Sign In' - page.must_have_content 'Invalid login' + _(page).must_have_content 'Invalid login' end it 'fails for missing signin' do @@ -46,7 +46,7 @@ describe 'signin' do fill_in 'username', with: auth[:username] fill_in 'password', with: auth[:password] click_button 'Sign In' - page.must_have_content 'Invalid login' + _(page).must_have_content 'Invalid login' end it 'signs in with proper credentials' do @@ -57,7 +57,7 @@ describe 'signin' do fill_in 'username', with: @site.username fill_in 'password', with: pass click_button 'Sign In' - page.must_have_content 'Your Feed' + _(page).must_have_content 'Your Feed' end it 'signs in with invalid case username' do @@ -68,7 +68,7 @@ describe 'signin' do fill_in 'username', with: @site.username.upcase fill_in 'password', with: pass click_button 'Sign In' - page.must_have_content 'Your Feed' + _(page).must_have_content 'Your Feed' end it 'signs in with email' do @@ -79,7 +79,7 @@ describe 'signin' do fill_in 'username', with: @site.email fill_in 'password', with: pass click_button 'Sign In' - page.must_have_content 'Your Feed' + _(page).must_have_content 'Your Feed' end it 'signs in with invalid case email' do @@ -90,6 +90,6 @@ describe 'signin' do fill_in 'username', with: @site.email.upcase fill_in 'password', with: pass click_button 'Sign In' - page.must_have_content 'Your Feed' + _(page).must_have_content 'Your Feed' end end diff --git a/tests/acceptance/signup_tests.rb b/tests/acceptance/signup_tests.rb index 14ad4cc5..838cc860 100644 --- a/tests/acceptance/signup_tests.rb +++ b/tests/acceptance/signup_tests.rb @@ -5,7 +5,7 @@ describe 'signup' do def fill_in_valid @site = Fabricate.attributes_for(:site) - page.must_have_content 'Sign up for free' + _(page).must_have_content 'Sign up for free' fill_in 'username', with: @site[:username] fill_in 'password', with: @site[:password] fill_in 'email', with: @site[:email] @@ -16,7 +16,7 @@ describe 'signup' do end def site_created? - page.must_have_content 'Welcome to Neocities' + _(page).must_have_content 'Welcome to Neocities' end def visit_signup @@ -41,22 +41,22 @@ describe 'signup' do site_created? click_link 'Continue' - page.must_have_content /almost ready!/ + _(page).must_have_content /almost ready!/ fill_in 'token', with: Site[username: @site[:username]].email_confirmation_token click_button 'Confirm Email' - current_path.must_equal '/tutorial' - page.must_have_content /Let's Get Started/ + _(current_path).must_equal '/tutorial' + _(page).must_have_content /Let's Get Started/ index_file_path = File.join Site::SITE_FILES_ROOT, Site.sharding_dir(@site[:username]), @site[:username], 'index.html' - File.exist?(index_file_path).must_equal true + _(File.exist?(index_file_path)).must_equal true site = Site[username: @site[:username]] - site.site_files.length.must_equal 4 - site.site_changed.must_equal false - site.site_updated_at.must_be_nil - site.is_education.must_equal false + _(site.site_files.length).must_equal 4 + _(site.site_changed).must_equal false + _(site.site_updated_at).must_be_nil + _(site.is_education).must_equal false - site.ip.must_equal '127.0.0.1' + _(site.ip).must_equal '127.0.0.1' end it 'fails if site with same ip has been banned' do @@ -65,9 +65,9 @@ describe 'signup' do fill_in_valid click_signup_button site = Site[username: @site[:username]] - Site[username: @site[:username]].must_be_nil - current_path.must_equal '/' - page.wont_have_content 'Welcome to Neocities' + _(Site[username: @site[:username]]).must_be_nil + _(current_path).must_equal '/' + _(page).wont_have_content 'Welcome to Neocities' @banned_site.update ip: nil end @@ -75,9 +75,9 @@ describe 'signup' do DB[:blocked_ips].insert(ip: '127.0.0.1', created_at: Time.now) fill_in_valid click_signup_button - Site[username: @site[:username]].must_be_nil - current_path.must_equal '/' - page.wont_have_content 'Welcome to Neocities' + _(Site[username: @site[:username]]).must_be_nil + _(current_path).must_equal '/' + _(page).wont_have_content 'Welcome to Neocities' end it 'fails to create for existing site' do @@ -85,41 +85,41 @@ describe 'signup' do fill_in_valid fill_in 'username', with: @existing_site.username click_signup_button - page.must_have_content 'already taken' + _(page).must_have_content 'already taken' end it 'fails with missing password' do fill_in_valid fill_in 'password', with: '' click_signup_button - page.must_have_content 'Password must be at least 5 characters' + _(page).must_have_content 'Password must be at least 5 characters' end it 'fails with short password' do fill_in_valid fill_in 'password', with: 'derp' click_signup_button - page.must_have_content 'Password must be at least 5 characters' + _(page).must_have_content 'Password must be at least 5 characters' end it 'fails with invalid hostname for username' do fill_in_valid fill_in 'username', with: '|\|0p|E' click_signup_button - page.must_have_content 'Usernames can only contain' + _(page).must_have_content 'Usernames can only contain' fill_in 'username', with: 'nope-' click_signup_button - page.must_have_content 'A valid user/site name is required' + _(page).must_have_content 'A valid user/site name is required' fill_in 'username', with: '-nope' click_signup_button - page.must_have_content 'A valid user/site name is required' + _(page).must_have_content 'A valid user/site name is required' end it 'fails with username greater than 32 characters' do fill_in_valid fill_in 'username', with: SecureRandom.hex+'1' click_signup_button - page.must_have_content 'cannot exceed 32 characters' + _(page).must_have_content 'cannot exceed 32 characters' end it 'fails with existing email' do @@ -127,13 +127,13 @@ describe 'signup' do fill_in_valid fill_in 'email', with: email click_signup_button - site_created?.must_equal true + _(site_created?).must_equal true Capybara.reset_sessions! visit_signup fill_in_valid fill_in 'email', with: email click_signup_button - page.must_have_content /email.+exists/ + _(page).must_have_content /email.+exists/ end it 'fails with existing email even if case sensitive' do @@ -141,71 +141,71 @@ describe 'signup' do fill_in_valid fill_in 'email', with: email click_signup_button - site_created?.must_equal true + _(site_created?).must_equal true Capybara.reset_sessions! visit_signup fill_in_valid fill_in 'email', with: email.upcase click_signup_button - page.must_have_content /email.+exists/ + _(page).must_have_content /email.+exists/ end it 'succeeds with no tags' do fill_in_valid fill_in 'new_tags_string', with: '' click_signup_button - site_created?.must_equal true + _(site_created?).must_equal true end it 'succeeds with a single tag' do fill_in_valid fill_in 'new_tags_string', with: 'derpie' click_signup_button - site_created?.must_equal true - Site.last.tags.first.name.must_equal 'derpie' + _(site_created?).must_equal true + _(Site.last.tags.first.name).must_equal 'derpie' end it 'succeeds with valid tags' do fill_in_valid fill_in 'new_tags_string', with: 'derpie, shoujo' click_signup_button - site_created?.must_equal true - Site.last.tags.collect {|t| t.name}.must_equal ['derpie', 'shoujo'] + _(site_created?).must_equal true + _(Site.last.tags.collect {|t| t.name}).must_equal ['derpie', 'shoujo'] end it 'fails with invalid tag chars' do fill_in_valid fill_in 'new_tags_string', with: '$POLICE OFFICER$$$$$, derp' click_signup_button - page.must_have_content /Tag.+can only contain/ + _(page).must_have_content /Tag.+can only contain/ end it 'fails for tag with too many spaces' do fill_in_valid fill_in 'new_tags_string', with: 'police officer, hi' click_signup_button - page.must_have_content /Tag.+cannot have spaces/ + _(page).must_have_content /Tag.+cannot have spaces/ end it 'fails for tag with too many words' do fill_in_valid fill_in 'new_tags_string', with: 'police officer' click_signup_button - page.must_have_content /Tag.+cannot be more than #{Tag::NAME_WORDS_MAX} word/ + _(page).must_have_content /Tag.+cannot be more than #{Tag::NAME_WORDS_MAX} word/ end it "fails for tag longer than #{Tag::NAME_LENGTH_MAX} characters" do fill_in_valid fill_in 'new_tags_string', with: SecureRandom.hex(Tag::NAME_LENGTH_MAX) click_signup_button - page.must_have_content /cannot be longer than #{Tag::NAME_LENGTH_MAX}/ + _(page).must_have_content /cannot be longer than #{Tag::NAME_LENGTH_MAX}/ end it 'fails for too many tags' do fill_in_valid fill_in 'new_tags_string', with: 'one, two, three, four, five, six' click_signup_button - page.must_have_content /Cannot have more than \d tags for your site/ + _(page).must_have_content /Cannot have more than \d tags for your site/ end it 'does not duplicate tags' do @@ -213,10 +213,10 @@ describe 'signup' do fill_in 'new_tags_string', with: 'one, one' click_signup_button - page.must_have_content /Welcome to Neocities/ + _(page).must_have_content /Welcome to Neocities/ site = Site[username: @site[:username]] - site.tags.length.must_equal 1 - site.tags.first.name.must_equal 'one' + _(site.tags.length).must_equal 1 + _(site.tags.first.name).must_equal 'one' end end diff --git a/tests/acceptance/site_tests.rb b/tests/acceptance/site_tests.rb index 60a75261..1368fa2b 100644 --- a/tests/acceptance/site_tests.rb +++ b/tests/acceptance/site_tests.rb @@ -19,18 +19,18 @@ describe 'site page' do it 'allows commenting' do fill_in 'message', with: 'I love your site!' click_button 'Post' - @site.profile_comments.count.must_equal 1 + _(@site.profile_comments.count).must_equal 1 profile_comment = @site.profile_comments.first - profile_comment.actioning_site.id.must_equal @commenting_site.id - profile_comment.message.must_equal 'I love your site!' + _(profile_comment.actioning_site.id).must_equal @commenting_site.id + _(profile_comment.message).must_equal 'I love your site!' end it 'does not send comment email if not wished' do @site.update send_comment_emails: false fill_in 'message', with: 'I am annoying' click_button 'Post' - @site.profile_comments.count.must_equal 1 - EmailWorker.jobs.length.must_equal 0 + _(@site.profile_comments.count).must_equal 1 + _(EmailWorker.jobs.length).must_equal 0 end it 'does not send email if there is none' do @@ -38,7 +38,7 @@ describe 'site page' do @site.save_changes validate: false fill_in 'message', with: 'DERP' click_button 'Post' - EmailWorker.jobs.length.must_equal 0 + _(EmailWorker.jobs.length).must_equal 0 end end @@ -52,15 +52,15 @@ describe 'site page' do it '404s for missing site' do visit '/site/failderp' - page.status_code.must_equal 404 - page.must_have_content /not found/i + _(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}/ + _(page.status_code).must_equal 200 + _(page).must_have_content /#{site.username}/ end =begin @@ -74,7 +74,7 @@ describe 'site page' do visit "/browse?tag=#{tag}" - page.find('.website-Gallery .username a')['href'].must_match /\/site\/#{blocked_site.username}/ + _(page.find('.website-Gallery .username a')['href']).must_match /\/site\/#{blocked_site.username}/ visit "/site/#{blocked_site.username}" @@ -83,11 +83,11 @@ describe 'site page' do visit "/browse?tag=#{tag}" - page.must_have_content /no active sites found/i + _(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 + _(site.blockings.length).must_equal 1 + _(site.blockings.first.site_id).must_equal blocked_site.id end =end @@ -95,7 +95,7 @@ describe 'site page' do site = Fabricate :site site.ban! visit "/site/#{site.username}" - page.status_code.must_equal 404 - page.must_have_content /not found/i + _(page.status_code).must_equal 404 + _(page).must_have_content /not found/i end end diff --git a/tests/acceptance/supporter_tests.rb b/tests/acceptance/supporter_tests.rb index 1b456acb..aaef44ee 100644 --- a/tests/acceptance/supporter_tests.rb +++ b/tests/acceptance/supporter_tests.rb @@ -10,9 +10,8 @@ describe '/supporter' do @site = Fabricate :site @stripe_helper = StripeMock.create_test_helper StripeMock.start - @stripe_helper.create_plan id: 'special', amount: 0 - @stripe_helper.create_plan id: 'supporter', amount: 500 - @stripe_helper.create_plan id: 'free', amount: 0 + @stripe_helper.create_product(id: 'supporter', name: 'Supporter') + @stripe_helper.create_plan product: 'supporter', amount: 500 page.set_rack_session id: @site.id EmailWorker.jobs.clear Mail::TestMailer.deliveries.clear @@ -37,17 +36,17 @@ describe '/supporter' do find('.cc-cvc').set '123' page.evaluate_script("document.getElementById('stripe_token').value = '#{@stripe_helper.generate_card_token}'") click_link 'Upgrade for $5/mo' - page.current_path.must_equal '/supporter/thanks' + _(page.current_path).must_equal '/supporter/thanks' all('.txt-Center') - page.body.must_match /You have become a Neocities Supporter/ + _(page.body).must_match /You have become a Neocities Supporter/ @site.reload - @site.stripe_customer_id.wont_be_nil - @site.stripe_subscription_id.wont_be_nil - @site.values[:plan_type].must_equal 'supporter' - @site.supporter?.must_equal true + _(@site.stripe_customer_id).wont_be_nil + _(@site.stripe_subscription_id).wont_be_nil + _(@site.values[:plan_type]).must_equal 'supporter' + _(@site.supporter?).must_equal true EmailWorker.drain mail = Mail::TestMailer.deliveries.first - mail.subject.must_match "You've become a supporter" + _(mail.subject).must_match "You've become a supporter" end end diff --git a/tests/api_tests.rb b/tests/api_tests.rb index 0f40adf2..190806b3 100644 --- a/tests/api_tests.rb +++ b/tests/api_tests.rb @@ -26,9 +26,9 @@ describe 'api' do describe 'not found' do it 'returns json for missing route' do get '/api/sdlfkjsdlfjds' - last_response.status.must_equal 404 - res[:result].must_equal 'error' - res[:error_type].must_equal 'not_found' + _(last_response.status).must_equal 404 + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'not_found' end end @@ -38,15 +38,15 @@ describe 'api' do basic_authorize @user, @pass get '/api/list' - res[:result].must_equal 'success' - res[:files].length.must_equal @site.site_files.length + _(res[:result]).must_equal 'success' + _(res[:files].length).must_equal @site.site_files.length res[:files].each do |file| site_file = @site.site_files.select {|s| s[:path] == file[:path]}.first - site_file[:is_directory].must_equal file[:is_directory] - site_file[:size].must_equal file[:size] - site_file[:updated_at].rfc2822.must_equal file[:updated_at] - site_file[:sha1_hash].must_equal file[:sha1_hash] + _(site_file[:is_directory]).must_equal file[:is_directory] + _(site_file[:size]).must_equal file[:size] + _(site_file[:updated_at].rfc2822).must_equal file[:updated_at] + _(site_file[:sha1_hash]).must_equal file[:sha1_hash] end end @@ -54,8 +54,8 @@ describe 'api' do create_site basic_authorize @user, @pass get '/api/list', path: '/fail' - res[:result].must_equal 'success' - res[:files].must_equal [] + _(res[:result]).must_equal 'success' + _(res[:files]).must_equal [] end it 'shows files in path' do @@ -65,11 +65,11 @@ describe 'api' do @site.store_files [{filename: '/derp/test.html', tempfile: tempfile}] basic_authorize @user, @pass get '/api/list', path: '/derp' - res[:result].must_equal 'success' - res[:files].length.must_equal 1 + _(res[:result]).must_equal 'success' + _(res[:files].length).must_equal 1 file = res[:files].first - file[:path].must_equal 'derp/test.html' - file[:updated_at].must_equal @site.site_files.select {|s| s.path == 'derp/test.html'}.first.updated_at.rfc2822 + _(file[:path]).must_equal 'derp/test.html' + _(file[:updated_at]).must_equal @site.site_files.select {|s| s.path == 'derp/test.html'}.first.updated_at.rfc2822 end end @@ -83,13 +83,13 @@ describe 'api' do create_site @site.update is_banned: true get '/api/info', sitename: @site.username - res[:error_type].must_equal 'site_not_found' - @site.reload.api_calls.must_equal 0 + _(res[:error_type]).must_equal 'site_not_found' + _(@site.reload.api_calls).must_equal 0 end it 'fails for nonexistent site' do get '/api/info', sitename: 'notexist' - res[:error_type].must_equal 'site_not_found' + _(res[:error_type]).must_equal 'site_not_found' end it 'succeeds for valid sitename' do @@ -97,27 +97,27 @@ describe 'api' do @site.update hits: 31337, domain: 'derp.com', new_tags_string: 'derpie, man' @site.add_archive ipfs_hash: 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU' get '/api/info', sitename: @user - res[:result].must_equal 'success' - res[:info][:sitename].must_equal @site.username - res[:info][:hits].must_equal 31337 - res[:info][:created_at].must_equal @site.created_at.rfc2822 - res[:info][:last_updated].must_be_nil - res[:info][:domain].must_equal 'derp.com' - res[:info][:tags].must_equal ['derpie', 'man'] - res[:info][:latest_ipfs_hash].must_equal 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU' - @site.reload.api_calls.must_equal 0 + _(res[:result]).must_equal 'success' + _(res[:info][:sitename]).must_equal @site.username + _(res[:info][:hits]).must_equal 31337 + _(res[:info][:created_at]).must_equal @site.created_at.rfc2822 + _(res[:info][:last_updated]).must_be_nil + _(res[:info][:domain]).must_equal 'derp.com' + _(res[:info][:tags]).must_equal ['derpie', 'man'] + _(res[:info][:latest_ipfs_hash]).must_equal 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU' + _(@site.reload.api_calls).must_equal 0 end it 'shows latest ipfs hash as nil when not present' do create_site get '/api/info', sitename: @user - res[:info][:latest_ipfs_hash].must_be_nil + _(res[:info][:latest_ipfs_hash]).must_be_nil end it 'fails for bad auth' do basic_authorize 'derp', 'fake' get '/api/info' - res[:error_type].must_equal 'invalid_auth' + _(res[:error_type]).must_equal 'invalid_auth' end it 'succeeds for api auth' do @@ -132,25 +132,25 @@ describe 'api' do describe 'delete' do it 'fails with no or bad auth' do post '/api/delete', filenames: ['hi.html'] - res[:error_type].must_equal 'invalid_auth' + _(res[:error_type]).must_equal 'invalid_auth' create_site basic_authorize 'derp', 'fake' post '/api/delete', filenames: ['hi.html'] - res[:error_type].must_equal 'invalid_auth' + _(res[:error_type]).must_equal 'invalid_auth' end it 'fails with missing filename argument' do create_site basic_authorize @user, @pass post '/api/delete' - res[:error_type].must_equal 'missing_filenames' + _(res[:error_type]).must_equal 'missing_filenames' end it 'fails to delete index.html' do create_site basic_authorize @user, @pass post '/api/delete', filenames: ['index.html'] - res[:error_type].must_equal 'cannot_delete_index' + _(res[:error_type]).must_equal 'cannot_delete_index' end it 'succeeds with weird filenames' do @@ -158,12 +158,12 @@ describe 'api' do basic_authorize @user, @pass @site.store_files [{filename: 't$st.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}] post '/api/delete', filenames: ['t$st.jpg'] - res[:result].must_equal 'success' + _(res[:result]).must_equal 'success' create_site basic_authorize @user, @pass post '/api/delete', filenames: ['./config.yml'] - res[:error_type].must_equal 'missing_files' + _(res[:error_type]).must_equal 'missing_files' end it 'fails with missing files' do @@ -171,15 +171,15 @@ describe 'api' do basic_authorize @user, @pass @site.store_files [{filename: 'test.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}] post '/api/delete', filenames: ['doesntexist.jpg'] - res[:error_type].must_equal 'missing_files' + _(res[:error_type]).must_equal 'missing_files' end it 'fails to delete site directory' do create_site basic_authorize @user, @pass post '/api/delete', filenames: ['/'] - res[:error_type].must_equal 'cannot_delete_site_directory' - File.exist?(@site.files_path).must_equal true + _(res[:error_type]).must_equal 'cannot_delete_site_directory' + _(File.exist?(@site.files_path)).must_equal true end it 'fails to delete other directories' do @@ -188,11 +188,11 @@ describe 'api' do create_site basic_authorize @user, @pass post '/api/delete', filenames: ["../#{@other_site.username}"] - File.exist?(@other_site.base_files_path).must_equal true - res[:error_type].must_equal 'missing_files' + _(File.exist?(@other_site.base_files_path)).must_equal true + _(res[:error_type]).must_equal 'missing_files' post '/api/delete', filenames: ["../#{@other_site.username}/index.html"] - File.exist?(@other_site.base_files_path+'/index.html').must_equal true - res[:error_type].must_equal 'missing_files' + _(File.exist?(@other_site.base_files_path+'/index.html')).must_equal true + _(res[:error_type]).must_equal 'missing_files' end it 'succeeds with valid filenames' do @@ -201,9 +201,9 @@ describe 'api' do @site.store_files [{filename: 'test.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}] @site.store_files [{filename: 'test2.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}] post '/api/delete', filenames: ['test.jpg', 'test2.jpg'] - res[:result].must_equal 'success' - site_file_exists?('test.jpg').must_equal false - site_file_exists?('test2.jpg').must_equal false + _(res[:result]).must_equal 'success' + _(site_file_exists?('test.jpg')).must_equal false + _(site_file_exists?('test2.jpg')).must_equal false end end @@ -212,8 +212,8 @@ describe 'api' do create_site basic_authorize @user, @pass get '/api/key' - res[:result].must_equal 'success' - res[:api_key].must_equal @site.reload.api_key + _(res[:result]).must_equal 'success' + _(res[:api_key]).must_equal @site.reload.api_key end it 'returns existing key' do @@ -221,14 +221,14 @@ describe 'api' do @site.generate_api_key! basic_authorize @user, @pass get '/api/key' - res[:api_key].must_equal @site.api_key + _(res[:api_key]).must_equal @site.api_key end it 'fails for bad login' do create_site basic_authorize 'zero', 'cool' get '/api/key' - res[:error_type].must_equal 'invalid_auth' + _(res[:error_type]).must_equal 'invalid_auth' end end @@ -245,9 +245,9 @@ describe 'api' do post '/api/upload_hash', "test.jpg" => test_hash, "test2.jpg" => Digest::SHA1.hexdigest('herpderp') - res[:result].must_equal 'success' - res[:files][:'test.jpg'].must_equal true - res[:files][:'test2.jpg'].must_equal false + _(res[:result]).must_equal 'success' + _(res[:files][:'test.jpg']).must_equal true + _(res[:files][:'test2.jpg']).must_equal false end end @@ -262,58 +262,58 @@ describe 'api' do it 'succeeds' do post '/api/rename', path: 'testdir/test.jpg', new_path: 'testdir/test2.jpg' - res[:result].must_equal 'success' + _(res[:result]).must_equal 'success' end it 'fails to overwrite index file' do post '/api/rename', path: 'testdir/test.jpg', new_path: 'index.html' - res[:result].must_equal 'error' - res[:error_type].must_equal 'rename_error' - res[:message].must_equal 'file already exists' + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'rename_error' + _(res[:message]).must_equal 'file already exists' end it 'fails to overwrite existing file' do post '/api/rename', path: 'testdir/test.jpg', new_path: 'not_found.html' - res[:result].must_equal 'error' - res[:error_type].must_equal 'rename_error' + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'rename_error' end it 'succeeds with directory' do @site.create_directory 'derpiedir' post '/api/rename', path: 'derpiedir', new_path: 'notderpiedir' - res[:result].must_equal 'success' + _(res[:result]).must_equal 'success' end end describe 'upload' do it 'fails with no auth' do post '/api/upload' - res[:result].must_equal 'error' - res[:error_type].must_equal 'invalid_auth' + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'invalid_auth' end it 'fails for bad auth' do basic_authorize 'username', 'password' post '/api/upload' - res[:error_type].must_equal 'invalid_auth' + _(res[:error_type]).must_equal 'invalid_auth' end it 'fails with missing files' do create_site basic_authorize @user, @pass post '/api/upload' - res[:error_type].must_equal 'missing_files' + _(res[:error_type]).must_equal 'missing_files' end it 'succeeds with valid api key' do create_site - @site.api_key.must_be_nil + _(@site.api_key).must_be_nil @site.generate_api_key! - @site.reload.api_key.wont_equal nil + _(@site.reload.api_key).wont_equal nil header 'Authorization', "Bearer #{@site.api_key}" post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') - res[:result].must_equal 'success' - site_file_exists?('test.jpg').must_equal true + _(res[:result]).must_equal 'success' + _(site_file_exists?('test.jpg')).must_equal true end it 'fails with bad api key' do @@ -321,8 +321,8 @@ describe 'api' do @site.generate_api_key! header 'Authorization', "Bearer zerocool" post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') - res[:result].must_equal 'error' - res[:error_type].must_equal 'invalid_auth' + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'invalid_auth' end =begin @@ -337,7 +337,7 @@ describe 'api' do post '/api/upload', { '/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:error_type].must_equal 'too_many_files' + _(res[:error_type]).must_equal 'too_many_files' end =end @@ -347,9 +347,9 @@ describe 'api' do post '/api/upload', { '../lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:result].must_equal 'success' - File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg')).must_equal true - @site.reload.api_calls.must_equal 1 + _(res[:result]).must_equal 'success' + _(File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg'))).must_equal true + _(@site.reload.api_calls).must_equal 1 end it 'scrubs root path slash' do @@ -358,8 +358,8 @@ describe 'api' do post '/api/upload', { '/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:result].must_equal 'success' - File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg')).must_equal true + _(res[:result]).must_equal 'success' + _(File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg'))).must_equal true end it 'fails for missing file name' do @@ -368,7 +368,7 @@ describe 'api' do post '/api/upload', { '/' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:error_type].must_equal 'invalid_file_type' + _(res[:error_type]).must_equal 'invalid_file_type' end it 'fails for file with no extension' do @@ -377,7 +377,7 @@ describe 'api' do post '/api/upload', { 'derpie' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:error_type].must_equal 'invalid_file_type' + _(res[:error_type]).must_equal 'invalid_file_type' end it 'creates path for file uploads' do @@ -386,8 +386,8 @@ describe 'api' do post '/api/upload', { 'derpie/derpingtons/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:result].must_equal 'success' - File.exist?(@site.files_path('derpie/derpingtons/lol.jpg')).must_equal true + _(res[:result]).must_equal 'success' + _(File.exist?(@site.files_path('derpie/derpingtons/lol.jpg'))).must_equal true end it 'records api calls that require auth' do @@ -400,7 +400,7 @@ describe 'api' do } } - @site.reload.api_calls.must_equal 2 + _(@site.reload.api_calls).must_equal 2 end it 'fails for invalid files' do @@ -410,17 +410,17 @@ describe 'api' do 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'), 'nord.avi' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'image/jpeg') } - res[:error_type].must_equal 'invalid_file_type' - site_file_exists?('test.jpg').must_equal false - site_file_exists?('nord.avi').must_equal false + _(res[:error_type]).must_equal 'invalid_file_type' + _(site_file_exists?('test.jpg')).must_equal false + _(site_file_exists?('nord.avi')).must_equal false end it 'succeeds with single file' do create_site basic_authorize @user, @pass post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') - res[:result].must_equal 'success' - site_file_exists?('test.jpg').must_equal true + _(res[:result]).must_equal 'success' + _(site_file_exists?('test.jpg')).must_equal true end it 'succeeds with two files' do @@ -430,18 +430,18 @@ describe 'api' do 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'), 'test2.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } - res[:result].must_equal 'success' - site_file_exists?('test.jpg').must_equal true - site_file_exists?('test2.jpg').must_equal true + _(res[:result]).must_equal 'success' + _(site_file_exists?('test.jpg')).must_equal true + _(site_file_exists?('test2.jpg')).must_equal true end it 'fails with unwhitelisted file' do create_site basic_authorize @user, @pass post '/api/upload', 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav') - res[:result].must_equal 'error' - res[:error_type].must_equal 'invalid_file_type' - site_file_exists?('flowercrime.wav').must_equal false + _(res[:result]).must_equal 'error' + _(res[:error_type]).must_equal 'invalid_file_type' + _(site_file_exists?('flowercrime.wav')).must_equal false end it 'succeeds for unwhitelisted file on supported plans' do @@ -450,8 +450,8 @@ describe 'api' do create_site plan_type: plan_type basic_authorize @user, @pass post '/api/upload', 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav') - res[:result].must_equal 'success' - site_file_exists?('flowercrime.wav').must_equal true + _(res[:result]).must_equal 'success' + _(site_file_exists?('flowercrime.wav')).must_equal true end end end diff --git a/tests/ext_tests.rb b/tests/ext_tests.rb index f61e3987..3c2da8e5 100644 --- a/tests/ext_tests.rb +++ b/tests/ext_tests.rb @@ -3,7 +3,7 @@ require_relative './environment.rb' describe Time do describe 'ago' do it 'should return the modified value' do - Time.now.ago.must_equal 'just now' + _(Time.now.ago).must_equal 'just now' end end end \ No newline at end of file diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index 77e1b5fd..c8052de5 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -34,11 +34,11 @@ describe 'site_files' do upload 'files[]' => uploaded_file testfile = @site.site_files_dataset.where(path: 'test.jpg').first - testfile.wont_equal nil + _(testfile).wont_equal nil testfile.rename 'derp.jpg' - @site.site_files_dataset.where(path: 'derp.jpg').first.wont_equal nil - PurgeCacheWorker.jobs.first['args'].last.must_equal '/test.jpg' - File.exist?(@site.files_path('derp.jpg')).must_equal true + _(@site.site_files_dataset.where(path: 'derp.jpg').first).wont_equal nil + _(PurgeCacheWorker.jobs.first['args'].last).must_equal '/test.jpg' + _(File.exist?(@site.files_path('derp.jpg'))).must_equal true end it 'fails for bad extension change' do @@ -47,8 +47,8 @@ describe 'site_files' do testfile = @site.site_files_dataset.where(path: 'test.jpg').first res = testfile.rename('dasharezone.exe') - res.must_equal [false, 'unsupported file type'] - @site.site_files_dataset.where(path: 'test.jpg').first.wont_equal nil + _(res).must_equal [false, 'unsupported file type'] + _(@site.site_files_dataset.where(path: 'test.jpg').first).wont_equal nil end it 'renames nonstandard file type for supporters' do @@ -58,27 +58,27 @@ describe 'site_files' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav') testfile = @site.site_files_dataset.where(path: 'flowercrime.wav').first res = testfile.rename('flowercrime.exe') - res.first.must_equal true - File.exists?(@site.files_path('flowercrime.exe')).must_equal true - @site.site_files_dataset.where(path: 'flowercrime.exe').first.wont_equal nil + _(res.first).must_equal true + _(File.exists?(@site.files_path('flowercrime.exe'))).must_equal true + _(@site.site_files_dataset.where(path: 'flowercrime.exe').first).wont_equal nil end end it 'works for directory' do @site.create_directory 'dirone' - @site.site_files.select {|sf| sf.path == 'dirone'}.length.must_equal 1 + _(@site.site_files.select {|sf| sf.path == 'dirone'}.length).must_equal 1 dirone = @site.site_files_dataset.where(path: 'dirone').first - dirone.wont_equal nil - dirone.is_directory.must_equal true + _(dirone).wont_equal nil + _(dirone.is_directory).must_equal true res = dirone.rename('dasharezone') - res.must_equal [true, nil] + _(res).must_equal [true, nil] dasharezone = @site.site_files_dataset.where(path: 'dasharezone').first - dasharezone.wont_equal nil - dasharezone.is_directory.must_equal true + _(dasharezone).wont_equal nil + _(dasharezone.is_directory).must_equal true - PurgeCacheWorker.jobs.first['args'].last.must_equal 'dirone' - PurgeCacheWorker.jobs.last['args'].last.must_equal 'dasharezone' + _(PurgeCacheWorker.jobs.first['args'].last).must_equal 'dirone' + _(PurgeCacheWorker.jobs.last['args'].last).must_equal 'dasharezone' end it 'wont set an empty directory' do @@ -103,11 +103,11 @@ describe 'site_files' do ) @site.site_files.select {|s| s.path == 'test'}.first.rename('test2') - @site.site_files.select {|sf| sf.path =~ /test2\/index.html/}.length.must_equal 1 - @site.site_files.select {|sf| sf.path =~ /test2\/test.jpg/}.length.must_equal 1 - @site.site_files.select {|sf| sf.path =~ /test\/test.jpg/}.length.must_equal 0 + _(@site.site_files.select {|sf| sf.path =~ /test2\/index.html/}.length).must_equal 1 + _(@site.site_files.select {|sf| sf.path =~ /test2\/test.jpg/}.length).must_equal 1 + _(@site.site_files.select {|sf| sf.path =~ /test\/test.jpg/}.length).must_equal 0 - PurgeCacheWorker.jobs.collect {|p| p['args'].last}.sort.must_equal ["/test/test.jpg", "/test/index.html", "/test/", "test", "test2", "test/test.jpg", "test2/test.jpg", "test/index.html", "test/", "test2/index.html", "test2/"].sort + _(PurgeCacheWorker.jobs.collect {|p| p['args'].last}.sort).must_equal ["/test/test.jpg", "/test/index.html", "/test/", "test", "test2", "test/test.jpg", "test2/test.jpg", "test/index.html", "test/", "test2/index.html", "test2/"].sort end it 'doesnt wipe out existing file' do @@ -121,35 +121,35 @@ describe 'site_files' do ) res = @site.site_files_dataset.where(path: 'test/index.html').first.rename('test/test.jpg') - res.must_equal [false, 'file already exists'] + _(res).must_equal [false, 'file already exists'] end it 'doesnt wipe out existing dir' do @site.create_directory 'dirone' @site.create_directory 'dirtwo' res = @site.site_files.select{|sf| sf.path == 'dirtwo'}.first.rename 'dirone' - res.must_equal [false, 'directory already exists'] + _(res).must_equal [false, 'directory already exists'] end it 'refuses to move index.html' do res = @site.site_files.select {|sf| sf.path == 'index.html'}.first.rename('notindex.html') - res.must_equal [false, 'cannot rename or move root index.html'] + _(res).must_equal [false, 'cannot rename or move root index.html'] end it 'works with unicode characters' do uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') upload 'files[]' => uploaded_file @site.site_files_dataset.where(path: 'test.jpg').first.rename("HELL💩؋.jpg") - @site.site_files_dataset.where(path: "HELL💩؋.jpg").first.wont_equal nil + _(@site.site_files_dataset.where(path: "HELL💩؋.jpg").first).wont_equal nil end it 'scrubs weird carriage return shit characters' do uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') upload 'files[]' => uploaded_file - proc { + _(proc { @site.site_files_dataset.where(path: 'test.jpg').first.rename("\r\n\t.jpg") - }.must_raise ArgumentError - @site.site_files_dataset.where(path: 'test.jpg').first.wont_equal nil + }).must_raise ArgumentError + _(_(@site.site_files_dataset.where(path: 'test.jpg').first)).wont_equal nil end end @@ -165,26 +165,26 @@ describe 'site_files' do PurgeCacheWorker.jobs.clear - @site.reload.space_used.must_equal initial_space_used + uploaded_file.size - @site.actual_space_used.must_equal @site.space_used + _(@site.reload.space_used).must_equal initial_space_used + uploaded_file.size + _(@site.actual_space_used).must_equal @site.space_used file_path = @site.files_path 'test.jpg' - File.exists?(file_path).must_equal true + _(File.exists?(file_path)).must_equal true delete_file filename: 'test.jpg' - File.exists?(file_path).must_equal false - SiteFile[site_id: @site.id, path: 'test.jpg'].must_be_nil - @site.reload.space_used.must_equal initial_space_used - @site.actual_space_used.must_equal @site.space_used + _(File.exists?(file_path)).must_equal false + _(SiteFile[site_id: @site.id, path: 'test.jpg']).must_be_nil + _(@site.reload.space_used).must_equal initial_space_used + _(@site.actual_space_used).must_equal @site.space_used args = PurgeCacheWorker.jobs.first['args'] - args[0].must_equal @site.username - args[1].must_equal '/test.jpg' + _(args[0]).must_equal @site.username + _(args[1]).must_equal '/test.jpg' end it 'property deletes directories with regexp special chars in them' do upload 'dir' => '8)', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') delete_file filename: '8)' - @site.reload.site_files.select {|f| f.path =~ /#{Regexp.quote '8)'}/}.length.must_equal 0 + _(@site.reload.site_files.select {|f| f.path =~ /#{Regexp.quote '8)'}/}.length).must_equal 0 end it 'deletes with escaped apostrophe' do @@ -192,9 +192,9 @@ describe 'site_files' do 'dir' => "test'ing", 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) - @site.reload.site_files.select {|s| s.path == "test'ing"}.length.must_equal 1 + _(@site.reload.site_files.select {|s| s.path == "test'ing"}.length).must_equal 1 delete_file filename: "test'ing" - @site.reload.site_files.select {|s| s.path == "test'ing"}.length.must_equal 0 + _(@site.reload.site_files.select {|s| s.path == "test'ing"}.length).must_equal 0 end it 'deletes a directory and all files in it' do @@ -210,11 +210,11 @@ describe 'site_files' do space_used = @site.reload.space_used delete_file filename: 'test' - @site.reload.space_used.must_equal(space_used - File.size('./tests/files/test.jpg')) + _(@site.reload.space_used).must_equal(space_used - File.size('./tests/files/test.jpg')) - @site.site_files.select {|f| f.path == 'test'}.length.must_equal 0 - @site.site_files.select {|f| f.path =~ /^test\//}.length.must_equal 0 - @site.site_files.select {|f| f.path =~ /^test.jpg/}.length.must_equal 1 + _(@site.site_files.select {|f| f.path == 'test'}.length).must_equal 0 + _(@site.site_files.select {|f| f.path =~ /^test\//}.length).must_equal 0 + _(@site.site_files.select {|f| f.path =~ /^test.jpg/}.length).must_equal 1 end it 'deletes records for nested directories' do @@ -226,7 +226,7 @@ describe 'site_files' do expected_site_file_paths = ['derp', 'derp/ing', 'derp/ing/tons', 'derp/ing/tons/test.jpg'] expected_site_file_paths.each do |path| - @site.site_files.select {|f| f.path == path}.length.must_equal 1 + _(@site.site_files.select {|f| f.path == path}.length).must_equal 1 end delete_file filename: 'derp' @@ -234,7 +234,7 @@ describe 'site_files' do @site.reload expected_site_file_paths.each do |path| - @site.site_files.select {|f| f.path == path}.length.must_equal 0 + _(@site.site_files.select {|f| f.path == path}.length).must_equal 0 end end @@ -244,71 +244,71 @@ describe 'site_files' do 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) delete_file filename: 'test/test.jpg' - last_response.headers['Location'].must_equal "http://example.org/dashboard?dir=test" + _(last_response.headers['Location']).must_equal "http://example.org/dashboard?dir=test" upload( 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) delete_file filename: 'test.jpg' - last_response.headers['Location'].must_equal "http://example.org/dashboard" + _(last_response.headers['Location']).must_equal "http://example.org/dashboard" end end describe 'upload' do it 'works with empty files' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/empty.js', 'text/javascript') - File.exists?(@site.files_path('empty.js')).must_equal true + _(File.exists?(@site.files_path('empty.js'))).must_equal true end it 'manages files with invalid UTF8' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/invalidutf8.html', 'text/html') - File.exists?(@site.files_path('invalidutf8.html')).must_equal true + _(File.exists?(@site.files_path('invalidutf8.html'))).must_equal true end it 'works with manifest files' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/cache.manifest', 'text/cache-manifest') - File.exists?(@site.files_path('cache.manifest')).must_equal true + _(File.exists?(@site.files_path('cache.manifest'))).must_equal true end it 'works with otf fonts' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype') - File.exists?(@site.files_path('chunkfive.otf')).must_equal true + _(File.exists?(@site.files_path('chunkfive.otf'))).must_equal true end it 'succeeds with index.html file' do - @site.site_changed.must_equal false + _(@site.site_changed).must_equal false upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html') - last_response.body.must_match /successfully uploaded/i - File.exists?(@site.files_path('index.html')).must_equal true + _(last_response.body).must_match /successfully uploaded/i + _(File.exists?(@site.files_path('index.html'))).must_equal true args = ScreenshotWorker.jobs.first['args'] - args.first.must_equal @site.username - args.last.must_equal 'index.html' - @site.title.must_equal "The web site of #{@site.username}" + _(args.first).must_equal @site.username + _(args.last).must_equal 'index.html' + _(@site.title).must_equal "The web site of #{@site.username}" @site.reload - @site.site_changed.must_equal true - @site.title.must_equal 'Hello?' + _(@site.site_changed).must_equal true + _(@site.title).must_equal 'Hello?' # Purge cache needs to flush / and index.html for either scenario. - PurgeCacheWorker.jobs.length.must_equal 3 + _(PurgeCacheWorker.jobs.length).must_equal 3 first_purge = PurgeCacheWorker.jobs.first surf_purge = PurgeCacheWorker.jobs[1] dirname_purge = PurgeCacheWorker.jobs.last username, pathname = first_purge['args'] - username.must_equal @site.username - pathname.must_equal '/index.html' + _(username).must_equal @site.username + _(pathname).must_equal '/index.html' - surf_purge['args'].last.must_equal '/?surf=1' + _(surf_purge['args'].last).must_equal '/?surf=1' username, pathame = nil username, pathname = dirname_purge['args'] - username.must_equal @site.username - pathname.must_equal '/' + _(username).must_equal @site.username + _(pathname).must_equal '/' - @site.space_used.must_equal @site.actual_space_used + _(@site.space_used).must_equal @site.actual_space_used - (@site.space_used > 0).must_equal true + _((@site.space_used > 0)).must_equal true end it 'provides the correct space used after overwriting an existing file' do @@ -317,8 +317,8 @@ describe 'site_files' do upload 'files[]' => uploaded_file second_uploaded_file = Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg') upload 'files[]' => second_uploaded_file - @site.reload.space_used.must_equal initial_space_used + second_uploaded_file.size - @site.space_used.must_equal @site.actual_space_used + _(@site.reload.space_used).must_equal initial_space_used + second_uploaded_file.size + _(@site.space_used).must_equal @site.actual_space_used end it 'does not change title for subdir index.html' do @@ -327,7 +327,7 @@ describe 'site_files' do 'dir' => 'derpie', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html') ) - @site.reload.title.must_equal title + _(@site.reload.title).must_equal title end it 'purges cache for /subdir/' do # (not /subdir which is just a redirect to /subdir/) @@ -335,7 +335,7 @@ describe 'site_files' do 'dir' => 'subdir', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html') ) - PurgeCacheWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length.must_equal 1 + _(PurgeCacheWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length).must_equal 1 end it 'succeeds with multiple files' do @@ -347,51 +347,51 @@ describe 'site_files' do ] ) - @site.site_files.select {|s| s.path == 'one'}.length.must_equal 1 - @site.site_files.select {|s| s.path == 'one/test.jpg'}.length.must_equal 1 - @site.site_files.select {|s| s.path == 'two'}.length.must_equal 1 - @site.site_files.select {|s| s.path == 'two/test.jpg'}.length.must_equal 1 + _(@site.site_files.select {|s| s.path == 'one'}.length).must_equal 1 + _(@site.site_files.select {|s| s.path == 'one/test.jpg'}.length).must_equal 1 + _(@site.site_files.select {|s| s.path == 'two'}.length).must_equal 1 + _(@site.site_files.select {|s| s.path == 'two/test.jpg'}.length).must_equal 1 end it 'succeeds with valid file' do initial_space_used = @site.space_used uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') upload 'files[]' => uploaded_file - last_response.body.must_match /successfully uploaded/i - File.exists?(@site.files_path('test.jpg')).must_equal true + _(last_response.body).must_match /successfully uploaded/i + _(File.exists?(@site.files_path('test.jpg'))).must_equal true username, path = PurgeCacheWorker.jobs.first['args'] - username.must_equal @site.username - path.must_equal '/test.jpg' + _(username).must_equal @site.username + _(path).must_equal '/test.jpg' @site.reload - @site.space_used.wont_equal 0 - @site.space_used.must_equal initial_space_used + uploaded_file.size - @site.space_used.must_equal @site.actual_space_used + _(@site.space_used).wont_equal 0 + _(@site.space_used).must_equal initial_space_used + uploaded_file.size + _(@site.space_used).must_equal @site.actual_space_used - ThumbnailWorker.jobs.length.must_equal 1 + _(ThumbnailWorker.jobs.length).must_equal 1 ThumbnailWorker.drain Site::THUMBNAIL_RESOLUTIONS.each do |resolution| - File.exists?(@site.thumbnail_path('test.jpg', resolution)).must_equal true + _(File.exists?(@site.thumbnail_path('test.jpg', resolution))).must_equal true end - @site.site_changed.must_equal false + _(@site.site_changed).must_equal false end it 'sets site changed to false if index is empty' do uploaded_file = Rack::Test::UploadedFile.new('./tests/files/blankindex/index.html', 'text/html') upload 'files[]' => uploaded_file - last_response.body.must_match /successfully uploaded/i - @site.empty_index?.must_equal true - @site.site_changed.must_equal false + _(last_response.body).must_match /successfully uploaded/i + _(@site.empty_index?).must_equal true + _(@site.site_changed).must_equal false end it 'fails with unsupported file' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav') - last_response.body.must_match /only supported by.+supporter account/i - File.exists?(@site.files_path('flowercrime.wav')).must_equal false - @site.site_changed.must_equal false + _(last_response.body).must_match /only supported by.+supporter account/i + _(File.exists?(@site.files_path('flowercrime.wav'))).must_equal false + _(@site.site_changed).must_equal false end it 'succeeds for unwhitelisted file on supporter plans' do @@ -399,20 +399,20 @@ describe 'site_files' do no_file_restriction_plans.each do |plan_type,hash| @site = Fabricate :site, plan_type: plan_type upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav') - last_response.body.must_match /successfully uploaded/i - File.exists?(@site.files_path('flowercrime.wav')).must_equal true + _(last_response.body).must_match /successfully uploaded/i + _(File.exists?(@site.files_path('flowercrime.wav'))).must_equal true end end it 'overwrites existing file with new file' do upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') - last_response.body.must_match /successfully uploaded/i + _(last_response.body).must_match /successfully uploaded/i digest = @site.reload.site_files.first.sha1_hash upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg') - last_response.body.must_match /successfully uploaded/i - @site.reload.changed_count.must_equal 2 - @site.site_files.select {|f| f.path == 'test.jpg'}.length.must_equal 1 - digest.wont_equal @site.site_files_dataset.where(path: 'test.jpg').first.sha1_hash + _(last_response.body).must_match /successfully uploaded/i + _(@site.reload.changed_count).must_equal 2 + _(@site.site_files.select {|f| f.path == 'test.jpg'}.length).must_equal 1 + _(digest).wont_equal @site.site_files_dataset.where(path: 'test.jpg').first.sha1_hash end it 'works with directory path' do @@ -420,24 +420,24 @@ describe 'site_files' do 'dir' => 'derpie/derptest', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) - last_response.body.must_match /successfully uploaded/i - File.exists?(@site.files_path('derpie/derptest/test.jpg')).must_equal true + _(last_response.body).must_match /successfully uploaded/i + _(File.exists?(@site.files_path('derpie/derptest/test.jpg'))).must_equal true - PurgeCacheWorker.jobs.length.must_equal 1 + _(PurgeCacheWorker.jobs.length).must_equal 1 username, path = PurgeCacheWorker.jobs.first['args'] - username.must_equal @site.username - path.must_equal '/derpie/derptest/test.jpg' + _(username).must_equal @site.username + _(path).must_equal '/derpie/derptest/test.jpg' - ThumbnailWorker.jobs.length.must_equal 1 + _(ThumbnailWorker.jobs.length).must_equal 1 ThumbnailWorker.drain - @site.site_files_dataset.where(path: 'derpie').count.must_equal 1 - @site.site_files_dataset.where(path: 'derpie/derptest').count.must_equal 1 - @site.site_files_dataset.where(path: 'derpie/derptest/test.jpg').count.must_equal 1 + _(@site.site_files_dataset.where(path: 'derpie').count).must_equal 1 + _(@site.site_files_dataset.where(path: 'derpie/derptest').count).must_equal 1 + _(@site.site_files_dataset.where(path: 'derpie/derptest/test.jpg').count).must_equal 1 Site::THUMBNAIL_RESOLUTIONS.each do |resolution| - File.exists?(@site.thumbnail_path('derpie/derptest/test.jpg', resolution)).must_equal true - @site.thumbnail_url('derpie/derptest/test.jpg', resolution).must_equal( + _(File.exists?(@site.thumbnail_path('derpie/derptest/test.jpg', resolution))).must_equal true + _(@site.thumbnail_url('derpie/derptest/test.jpg', resolution)).must_equal( File.join "#{Site::THUMBNAILS_URL_ROOT}", Site.sharding_dir(@site.username), @site.username, "/derpie/derptest/test.jpg.#{resolution}.jpg" ) end @@ -448,13 +448,13 @@ describe 'site_files' do 'dir' => 'derpie/derptest', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) - @site.reload.site_changed.must_equal false + _(@site.reload.site_changed).must_equal false upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html') - @site.reload.site_changed.must_equal true + _(@site.reload.site_changed).must_equal true upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype') - @site.reload.site_changed.must_equal true + _(@site.reload.site_changed).must_equal true end it 'does not store new file if hash matches' do @@ -462,22 +462,22 @@ describe 'site_files' do 'dir' => 'derpie/derptest', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) - @site.reload.changed_count.must_equal 1 + _(@site.reload.changed_count).must_equal 1 upload( 'dir' => 'derpie/derptest', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') ) - @site.reload.changed_count.must_equal 1 + _(@site.reload.changed_count).must_equal 1 upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html') - @site.reload.changed_count.must_equal 2 + _(@site.reload.changed_count).must_equal 2 end describe 'directory create' do it 'scrubs ../ from directory' do @site.create_directory '../../test' - @site.site_files.select {|site_file| site_file.path =~ /\.\./}.length.must_equal 0 + _(@site.site_files.select {|site_file| site_file.path =~ /\.\./}.length).must_equal 0 end end @@ -496,9 +496,9 @@ describe 'site_files' do @site.train 'spam.html', 'spam' @site.train 'phishing.html', 'phishing' - @site.classify('ham.html').must_equal 'ham' - @site.classify('spam.html').must_equal 'spam' - @site.classify('phishing.html').must_equal 'phishing' + _(@site.classify('ham.html')).must_equal 'ham' + _(@site.classify('spam.html')).must_equal 'spam' + _(@site.classify('phishing.html')).must_equal 'phishing' end =end end diff --git a/tests/site_tests.rb b/tests/site_tests.rb index 44b2a0f2..45149078 100644 --- a/tests/site_tests.rb +++ b/tests/site_tests.rb @@ -9,8 +9,8 @@ describe Site do it 'still makes files available' do site = Fabricate :site site.ban! - File.exist?(site.current_files_path('index.html')).must_equal true - site.current_files_path('index.html').must_equal File.join(Site::DELETED_SITES_ROOT, Site.sharding_dir(site.username), site.username, 'index.html') + _(File.exist?(site.current_files_path('index.html'))).must_equal true + _(site.current_files_path('index.html')).must_equal File.join(Site::DELETED_SITES_ROOT, Site.sharding_dir(site.username), site.username, 'index.html') end end @@ -19,13 +19,13 @@ describe Site do site = Fabricate :site index_path = File.join site.base_files_path, 'index.html' site.ban! - File.exist?(index_path).must_equal false + _(File.exist?(index_path)).must_equal false site.unban! site.reload - site.is_banned.must_equal false - site.banned_at.must_be_nil - site.blackbox_whitelisted.must_equal true - File.exist?(index_path).must_equal true + _(site.is_banned).must_equal false + _(site.banned_at).must_be_nil + _(site.blackbox_whitelisted).must_equal true + _(File.exist?(index_path)).must_equal true end end @@ -35,9 +35,9 @@ describe Site do site = Fabricate :site site_file_count = site.site_files_dataset.count site.create_directory path - site.site_files.select {|s| s.path == '' || s.path == '.'}.length.must_equal 0 - site.site_files.select {|s| s.path == path.gsub('/', '')}.first.wont_be_nil - site.site_files_dataset.count.must_equal site_file_count+1 + _(site.site_files.select {|s| s.path == '' || s.path == '.'}.length).must_equal 0 + _(site.site_files.select {|s| s.path == path.gsub('/', '')}.first).wont_be_nil + _(site.site_files_dataset.count).must_equal site_file_count+1 end end end @@ -45,24 +45,24 @@ describe Site do describe 'custom_max_space' do it 'should use the custom max space if it is more' do site = Fabricate :site - site.maximum_space.must_equal Site::PLAN_FEATURES[:free][:space] + _(site.maximum_space).must_equal Site::PLAN_FEATURES[:free][:space] site.custom_max_space = 10**9 site.save_changes - site.maximum_space.must_equal 10**9 + _(site.maximum_space).must_equal 10**9 end end describe 'can_email' do it 'should fail if send_emails is false' do site = Fabricate :site - site.can_email?.must_equal true + _(site.can_email?).must_equal true site.update send_emails: false - site.can_email?.must_equal false - site.can_email?(:send_comment_emails).must_equal false + _(site.can_email?).must_equal false + _(site.can_email?(:send_comment_emails)).must_equal false site.update send_emails: true - site.can_email?(:send_comment_emails).must_equal true + _(site.can_email?(:send_comment_emails)).must_equal true site.update send_comment_emails: false - site.can_email?(:send_comment_emails).must_equal false + _(site.can_email?(:send_comment_emails)).must_equal false end end @@ -74,12 +74,12 @@ describe Site do it 'works' do @site.send_email(subject: 'Subject', body: 'Body') - EmailWorker.jobs.length.must_equal 1 + _(EmailWorker.jobs.length).must_equal 1 args = EmailWorker.jobs.first['args'].first - args['from'].must_equal Site::FROM_EMAIL - args['to'].must_equal @site.email - args['subject'].must_equal 'Subject' - args['body'].must_equal 'Body' + _(args['from']).must_equal Site::FROM_EMAIL + _(args['to']).must_equal @site.email + _(args['subject']).must_equal 'Subject' + _(args['body']).must_equal 'Body' end it 'fails if send_emails is false' do @@ -91,21 +91,21 @@ describe Site do describe 'plan_name' do it 'should set to free for missing stripe_customer_id' do site = Fabricate :site - site.reload.plan_type.must_equal 'free' + _(site.reload.plan_type).must_equal 'free' end it 'should be free for no plan_type entry' do site = Fabricate :site, stripe_customer_id: 'cust_derp' - site.plan_type.must_equal 'free' + _(site.plan_type).must_equal 'free' end it 'should match plan_type' do %w{supporter free}.each do |plan_type| site = Fabricate :site, plan_type: plan_type - site.plan_type.must_equal plan_type + _(site.plan_type).must_equal plan_type end site = Fabricate :site, plan_type: nil - site.plan_type.must_equal 'free' + _(site.plan_type).must_equal 'free' end end @@ -114,16 +114,18 @@ describe Site do site = Fabricate :site, new_tags_string: 'vegetables' Site::SUGGESTIONS_LIMIT.times { Fabricate :site, new_tags_string: 'vegetables' } - site.suggestions.length.must_equal Site::SUGGESTIONS_LIMIT + _(site.suggestions.length).must_equal Site::SUGGESTIONS_LIMIT - site.suggestions.each {|s| s.tags.first.name.must_equal 'vegetables'} + site.suggestions.each do |suggestion| + _(suggestion.tags.first.name).must_equal 'vegetables' + end site = Fabricate :site, new_tags_string: 'gardening' (Site::SUGGESTIONS_LIMIT-5).times { Fabricate :site, new_tags_string: 'gardening', views: Site::SUGGESTIONS_VIEWS_MIN } - site.suggestions.length.must_equal(Site::SUGGESTIONS_LIMIT - 5) + _(site.suggestions.length).must_equal(Site::SUGGESTIONS_LIMIT - 5) end end end diff --git a/tests/stat_tests.rb b/tests/stat_tests.rb index 30a70217..f23b99c3 100644 --- a/tests/stat_tests.rb +++ b/tests/stat_tests.rb @@ -33,9 +33,9 @@ describe 'stats' do end Stat.parse_logfiles STAT_LOGS_PATH stat = @site_one.stats.first - stat.hits.must_equal 8 - stat.bandwidth.must_equal 40000 - stat.views.must_equal 2 + _(stat.hits).must_equal 8 + _(stat.bandwidth).must_equal 40000 + _(stat.views).must_equal 2 end it 'deals with spaces in paths' do @@ -48,9 +48,9 @@ describe 'stats' do Stat.parse_logfiles STAT_LOGS_PATH - @site.stats.first.bandwidth.must_equal 612917*2 - #@site.stat_referrers.first.url.must_equal 'http://derp.com' - #@site.stat_locations.first.city_name.must_equal 'Menlo Park' + _(@site.stats.first.bandwidth).must_equal 612917*2 + #_(@site.stat_referrers.first.url).must_equal 'http://derp.com' + #_(@site.stat_locations.first.city_name).must_equal 'Menlo Park' end it 'takes accout for log hit time' do @@ -63,15 +63,15 @@ describe 'stats' do Stat.parse_logfiles STAT_LOGS_PATH - @site.stats.length.must_equal 2 + _(@site.stats.length).must_equal 2 [Date.new(2015, 5, 2), Date.new(2015, 5, 1)].each do |date| stats = @site.stats.select {|stat| stat.created_at == date} - stats.length.must_equal 1 + _(stats.length).must_equal 1 stat = stats.first - stat.hits.must_equal 1 - stat.views.must_equal 1 - stat.bandwidth.must_equal 612917 + _(stat.hits).must_equal 1 + _(stat.views).must_equal 1 + _(stat.bandwidth).must_equal 612917 end end @@ -101,20 +101,20 @@ describe 'stats' do count_site_ids = [@free_site.id, @supporter_site.id] expected_stat_count = (Stat::FREE_RETAINMENT_DAYS+1)*2 - Stat.where(site_id: count_site_ids).count.must_equal expected_stat_count + _(Stat.where(site_id: count_site_ids).count).must_equal expected_stat_count Stat.prune! - Stat.where(site_id: count_site_ids).count.must_equal expected_stat_count-1 - Stat.where(site_id: @supporter_site.id).count.must_equal expected_stat_count/2 + _(Stat.where(site_id: count_site_ids).count).must_equal expected_stat_count-1 + _(Stat.where(site_id: @supporter_site.id).count).must_equal expected_stat_count/2 end it 'prunes referrers' do stat_referrer_now = @site_one.add_stat_referrer created_at: Date.today, url: 'http://example.com/now' stat_referrer = @site_one.add_stat_referrer created_at: (StatReferrer::RETAINMENT_DAYS-1).days.ago, url: 'http://example.com' - StatReferrer[stat_referrer.id].wont_be_nil - @site_one.stat_referrers_dataset.count.must_equal 2 + _(StatReferrer[stat_referrer.id]).wont_be_nil + _(@site_one.stat_referrers_dataset.count).must_equal 2 StatReferrer.prune! - @site_one.stat_referrers_dataset.count.must_equal 1 - StatReferrer[stat_referrer.id].must_be_nil + _(@site_one.stat_referrers_dataset.count).must_equal 1 + _(StatReferrer[stat_referrer.id]).must_be_nil end it 'prunes locations' do @@ -124,9 +124,9 @@ describe 'stats' do region_name: 'Minnesota', city_name: 'Minneapolis' ) - StatLocation[stat_location.id].wont_be_nil + _(StatLocation[stat_location.id]).wont_be_nil StatLocation.prune! - StatLocation[stat_location.id].must_be_nil + _(StatLocation[stat_location.id]).must_be_nil end it 'prunes paths' do @@ -134,9 +134,9 @@ describe 'stats' do created_at: (StatPath::RETAINMENT_DAYS-1).days.ago, name: '/derpie.html' ) - StatPath[stat_path.id].wont_be_nil + _(StatPath[stat_path.id]).wont_be_nil StatPath.prune! - StatPath[stat_path.id].must_be_nil + _(StatPath[stat_path.id]).must_be_nil end it 'parses logfile' do @@ -144,57 +144,57 @@ describe 'stats' do Stat.parse_logfiles STAT_LOGS_PATH @site_one.reload - @site_one.hits.must_equal 4 - @site_one.views.must_equal 2 + _(@site_one.hits).must_equal 4 + _(@site_one.views).must_equal 2 stat = @site_one.stats.first - stat.hits.must_equal 4 - stat.views.must_equal 2 - stat.bandwidth.must_equal 20_000 + _(stat.hits).must_equal 4 + _(stat.views).must_equal 2 + _(stat.bandwidth).must_equal 20_000 - #@site_one.stat_referrers.count.must_equal 1 + #@site_one.stat_referrers.count).must_equal 1 #stat_referrer = @site_one.stat_referrers.first - #stat_referrer.url.must_equal 'http://example.com' - #stat_referrer.created_at.must_equal @time.to_date - #stat_referrer.views.must_equal 2 + #stat_referrer.url).must_equal 'http://example.com' + #stat_referrer.created_at).must_equal @time.to_date + #stat_referrer.views).must_equal 2 - #@site_one.stat_paths.length.must_equal 1 + #@site_one.stat_paths.length).must_equal 1 #stat_path = @site_one.stat_paths.first - #stat_path.name.must_equal '/' - #stat_path.views.must_equal 4 + #stat_path.name).must_equal '/' + #stat_path.views).must_equal 4 - #@site_one.stat_locations.length.must_equal 2 + #@site_one.stat_locations.length).must_equal 2 #stat_location = @site_one.stat_locations.first - #stat_location.country_code2.must_equal 'US' - #stat_location.region_name.must_equal 'CA' - #stat_location.city_name.must_equal 'Menlo Park' - #stat_location.views.must_equal 1 + #stat_location.country_code2).must_equal 'US' + #stat_location.region_name).must_equal 'CA' + #stat_location.city_name).must_equal 'Menlo Park' + #stat_location.views).must_equal 1 @site_two.reload - @site_two.hits.must_equal 3 - @site_two.views.must_equal 3 + _(@site_two.hits).must_equal 3 + _(@site_two.views).must_equal 3 stat = @site_two.stats.first - stat.hits.must_equal 3 - stat.views.must_equal 3 - stat.bandwidth.must_equal 15_000 - #@site_two.stat_referrers.count.must_equal 2 + _(stat.hits).must_equal 3 + _(stat.views).must_equal 3 + _(stat.bandwidth).must_equal 15_000 + #@site_two.stat_referrers.count).must_equal 2 #stat_referrer = @site_two.stat_referrers.first - #stat_referrer.url.must_equal 'http://example.com' - #stat_referrer.views.must_equal 2 + #stat_referrer.url).must_equal 'http://example.com' + #stat_referrer.views).must_equal 2 #stat_paths = @site_two.stat_paths - #stat_paths.length.must_equal 2 - #stat_paths.first.name.must_equal '/' - #stat_paths.last.name.must_equal '/derp.html' + #stat_paths.length).must_equal 2 + #stat_paths.first.name).must_equal '/' + #stat_paths.last.name).must_equal '/derp.html' # [geoip.city('67.180.75.140'), geoip.city('172.56.16.152')] # Saves to daily_site_stats - DailySiteStat.count.must_equal 1 + _(DailySiteStat.count).must_equal 1 d = DailySiteStat.first - d.created_at.must_equal Date.new(@time.year, @time.month, @time.day) - d.hits.must_equal 7 - d.views.must_equal 5 - d.bandwidth.must_equal 35000 + _(d.created_at).must_equal Date.new(@time.year, @time.month, @time.day) + _(d.hits).must_equal 7 + _(d.views).must_equal 5 + _(d.bandwidth).must_equal 35000 end end diff --git a/tests/tag_tests.rb b/tests/tag_tests.rb index 83dc662f..f23761e7 100644 --- a/tests/tag_tests.rb +++ b/tests/tag_tests.rb @@ -5,30 +5,30 @@ describe Tag do it 'should force downcase' do Tag.where(name: 'derp').delete Tag.create_unless_exists 'derp' - Tag[name: 'derp'].wont_be_nil + _(Tag[name: 'derp']).wont_be_nil Tag.create_unless_exists 'DERP' - Tag.filter(name: 'DERP').count.must_equal 0 - Tag.filter(name: 'derp').count.must_equal 1 + _(Tag.filter(name: 'DERP').count).must_equal 0 + _(Tag.filter(name: 'derp').count).must_equal 1 end it 'prohibits junk tags' do Tag.where(name: '').delete tag = Tag.create_unless_exists '' - Tag.where(name: '').count.must_equal 0 + _(Tag.where(name: '').count).must_equal 0 end it 'strips tags' do badname = ' derp ' Tag.where(name: 'derp').delete Tag.create_unless_exists badname - Tag[name: badname].must_be_nil - Tag[name: badname.strip].wont_be_nil + _(Tag[name: badname]).must_be_nil + _(Tag[name: badname.strip]).wont_be_nil end it 'does not duplicate' do 2.times { Tag.create_unless_exists 'DERP' } - Tag.where(name: 'DERP').count.must_equal 0 - Tag.where(name: 'derp').count.must_equal 1 + _(Tag.where(name: 'DERP').count).must_equal 0 + _(Tag.where(name: 'derp').count).must_equal 1 end end -end \ No newline at end of file +end diff --git a/tests/tempfile_tests.rb b/tests/tempfile_tests.rb index ade275f6..86c418a7 100644 --- a/tests/tempfile_tests.rb +++ b/tests/tempfile_tests.rb @@ -5,6 +5,6 @@ describe Tempfile do tmp = Tempfile.new tmp.write '' tmp.close - tmp.size.must_equal 0 + _(tmp.size).must_equal 0 end end diff --git a/tests/webhook_tests.rb b/tests/webhook_tests.rb index 4c88fea2..5aa837be 100644 --- a/tests/webhook_tests.rb +++ b/tests/webhook_tests.rb @@ -28,20 +28,20 @@ describe 'tipping' do post '/webhooks/paypal/tipping_notify', paypal_hash - @site.tips.length.must_equal 1 + _(@site.tips.length).must_equal 1 tip = @site.tips.first - tip.site.id.must_equal @site.id - tip.actioning_site.id.must_equal @actioning_site.id - tip.currency.must_equal 'USD' - tip.amount_string.must_equal '$5.00' - tip.fee_string.must_equal '$0.45' - tip.message.must_equal 'I like your site' - tip.paypal_payer_email.must_equal @actioning_site.email - tip.paypal_receiver_email.must_equal @site.email - tip.paypal_txn_id.must_equal 'TXID' - tip.created_at.must_equal Time.parse("2017-02-03 21:39:51 -0800") + _(tip.site.id).must_equal @site.id + _(tip.actioning_site.id).must_equal @actioning_site.id + _(tip.currency).must_equal 'USD' + _(tip.amount_string).must_equal '$5.00' + _(tip.fee_string).must_equal '$0.45' + _(tip.message).must_equal 'I like your site' + _(tip.paypal_payer_email).must_equal @actioning_site.email + _(tip.paypal_receiver_email).must_equal @site.email + _(tip.paypal_txn_id).must_equal 'TXID' + _(tip.created_at).must_equal Time.parse("2017-02-03 21:39:51 -0800") - EmailWorker.jobs.length.must_equal 2 + _(EmailWorker.jobs.length).must_equal 2 end it 'adds a tip even if there is no actioning site id' do @@ -60,8 +60,8 @@ describe 'tipping' do post '/webhooks/paypal/tipping_notify', paypal_hash - @site.tips.length.must_equal 1 - @site.tips.first.actioning_site_id.must_be_nil + _(@site.tips.length).must_equal 1 + _(@site.tips.first.actioning_site_id).must_be_nil end end diff --git a/tests/workers/archive_worker_tests.rb b/tests/workers/archive_worker_tests.rb index 90a748e2..f6b0036d 100644 --- a/tests/workers/archive_worker_tests.rb +++ b/tests/workers/archive_worker_tests.rb @@ -6,23 +6,23 @@ describe ArchiveWorker do site = Fabricate :site ipfs_hash = site.add_to_ipfs ArchiveWorker.new.perform site.id - site.archives.length.must_equal 1 + _(site.archives.length).must_equal 1 archive_one = site.archives.first - archive_one.ipfs_hash.must_equal ipfs_hash - archive_one.updated_at.wont_be_nil + _(archive_one.ipfs_hash).must_equal ipfs_hash + _(archive_one.updated_at).wont_be_nil new_updated_at = Time.now - 500 archive_one.update updated_at: new_updated_at ArchiveWorker.new.perform site.id - archive_one.reload.updated_at.wont_equal new_updated_at + _(archive_one.reload.updated_at).wont_equal new_updated_at site.store_files [{filename: 'test.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}] ArchiveWorker.new.perform site.id site.reload - site.archives.length.must_equal 2 + _(site.archives.length).must_equal 2 archive_two = site.archives_dataset.exclude(ipfs_hash: archive_one.ipfs_hash).first - archive_two.ipfs_hash.wont_be_nil + _(archive_two.ipfs_hash).wont_be_nil end end diff --git a/tests/workers/email_worker_tests.rb b/tests/workers/email_worker_tests.rb index fd77f76d..b2da85ce 100644 --- a/tests/workers/email_worker_tests.rb +++ b/tests/workers/email_worker_tests.rb @@ -15,12 +15,12 @@ describe EmailWorker do }) mail = Mail::TestMailer.deliveries.first - mail.from.first.must_equal 'from@example.com' - mail.to.first.must_equal 'to@example.com' - mail.subject.must_equal 'Hello World' + _(mail.from.first).must_equal 'from@example.com' + _(mail.to.first).must_equal 'to@example.com' + _(mail.subject).must_equal 'Hello World' body = mail.body.to_s - body.must_match /testing/ - body.must_match /unsubscribe/ + _(body).must_match /testing/ + _(body).must_match /unsubscribe/ end it 'sends an email without a footer' do @@ -33,7 +33,7 @@ describe EmailWorker do 'body' => 'testing' }) body = Mail::TestMailer.deliveries.first.body.to_s - body.must_match /testing/ - body.wont_match /unsubscribe/ + _(body).must_match /testing/ + _(body).wont_match /unsubscribe/ end end diff --git a/tests/workers/screenshot_worker_tests.rb b/tests/workers/screenshot_worker_tests.rb index 0dc97d53..b0259070 100644 --- a/tests/workers/screenshot_worker_tests.rb +++ b/tests/workers/screenshot_worker_tests.rb @@ -19,8 +19,8 @@ describe ScreenshotWorker do ScreenshotWorker.new.perform site.username, path Site::SCREENSHOT_RESOLUTIONS.each do |r| - File.exists?(File.join(Site::SCREENSHOTS_ROOT, Site.sharding_dir(site.username), site.username, "#{path}.#{r}.jpg")).must_equal true - site.screenshot_url(path, r).must_equal( + _(File.exists?(File.join(Site::SCREENSHOTS_ROOT, Site.sharding_dir(site.username), site.username, "#{path}.#{r}.jpg"))).must_equal true + _(site.screenshot_url(path, r)).must_equal( File.join(Site::SCREENSHOTS_URL_ROOT, Site.sharding_dir(site.username), site.username, "#{path}.#{r}.jpg") ) end diff --git a/workers/screenshot_worker.rb b/workers/screenshot_worker.rb index afaa8344..c3187e13 100644 --- a/workers/screenshot_worker.rb +++ b/workers/screenshot_worker.rb @@ -50,14 +50,14 @@ class ScreenshotWorker return false end - img_list.new_image(img_list.first.columns, img_list.first.rows) { self.background_color = "white" } + img_list.new_image(img_list.first.columns, img_list.first.rows) {|i| i.background_color = "white" } img = img_list.reverse.flatten_images img_list.destroy! user_screenshots_path = File.join SCREENSHOTS_PATH, Site.sharding_dir(username), username screenshot_path = File.join user_screenshots_path, File.dirname(path) - FileUtils.mkdir_p screenshot_path unless Dir.exists?(screenshot_path) + FileUtils.mkdir_p screenshot_path unless Dir.exist?(screenshot_path) Site::SCREENSHOT_RESOLUTIONS.each do |res| width, height = res.split('x').collect {|r| r.to_i} @@ -72,7 +72,7 @@ class ScreenshotWorker tmpfile_path = "/tmp/#{SecureRandom.uuid}.jpg" begin - new_img.write(tmpfile_path) { self.quality = 92 } + new_img.write(tmpfile_path) { |i| i.quality = 92 } new_img.destroy! $image_optim.optimize_image! tmpfile_path File.open(full_screenshot_path, 'wb') {|file| file.write File.read(tmpfile_path)} diff --git a/workers/thumbnail_worker.rb b/workers/thumbnail_worker.rb index b845338f..1aa311a1 100644 --- a/workers/thumbnail_worker.rb +++ b/workers/thumbnail_worker.rb @@ -43,8 +43,8 @@ class ThumbnailWorker full_thumbnail_path = File.join(user_thumbnails_path, "#{path}.#{res}.#{save_ext}") - resimg.write(full_thumbnail_path) { - self.quality = 75 + resimg.write(full_thumbnail_path) { |i| + i.quality = 75 } resimg.destroy! #$image_optim.optimize_image! full_thumbnail_path