diff --git a/Gemfile b/Gemfile index dfa7d4cd0..48c3c5269 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,8 @@ source 'https://rubygems.org/' gem 'dotenv-rails', :require => "dotenv/rails-now" group :test do - gem "shoulda" + gem "shoulda-context" + gem "shoulda-matchers" gem "factory_girl" gem "mocha", :require => "mocha/setup" gem "ffaker" diff --git a/Gemfile.lock b/Gemfile.lock index 0c976820f..f41a261b7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,7 +85,7 @@ GEM bcrypt (>= 3.1.3) buftok (0.2.0) builder (3.2.3) - byebug (6.0.0) + byebug (9.0.6) capistrano (3.4.0) i18n rake (>= 10.0.0) @@ -105,7 +105,7 @@ GEM capistrano (~> 3.1, >= 3.1.0) chronic (0.10.2) cityhash (0.8.1) - coderay (1.1.0) + coderay (1.1.1) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -134,12 +134,12 @@ GEM equalizer (0.0.11) erubis (2.7.0) execjs (2.6.0) - factory_girl (4.5.0) + factory_girl (4.8.0) activesupport (>= 3.0.0) fakeweb (1.3.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) - ffaker (2.1.0) + ffaker (2.4.0) ffi (1.9.10-x64-mingw32) gctools (0.2.4) get_process_mem (0.2.1) @@ -182,7 +182,7 @@ GEM http_parser.rb (0.6.0) httpclient (2.8.0) hurley (0.2) - i18n (0.7.0) + i18n (0.8.0) jeweler (2.3.2) builder bundler (>= 1.0) @@ -227,7 +227,7 @@ GEM mime-types (2.99.3) mini_portile2 (2.1.0) minitest (5.10.1) - mocha (1.1.0) + mocha (1.2.1) metaclass (~> 0.0.1) multi_json (1.12.1) multi_xml (0.6.0) @@ -260,15 +260,10 @@ GEM pg (0.18.2-x64-mingw32) protected_attributes (1.1.3) activemodel (>= 4.0.1, < 5.0) - pry (0.10.1) + pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - pry (0.10.1-x64-mingw32) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - win32console (~> 1.3) psych (2.2.2) public_suffix (2.0.5) rack (1.6.5) @@ -333,12 +328,9 @@ GEM sprockets (~> 2.8, < 3.0) sprockets-rails (~> 2.0) semver2 (3.4.2) - shoulda (3.5.0) - shoulda-context (~> 1.0, >= 1.0.1) - shoulda-matchers (>= 1.4.1, < 3.0) - shoulda-context (1.2.1) - shoulda-matchers (2.8.0) - activesupport (>= 3.0.0) + shoulda-context (1.2.2) + shoulda-matchers (3.1.1) + activesupport (>= 4.0.0) signet (0.7.2) addressable (~> 2.3) faraday (~> 0.9) @@ -348,9 +340,9 @@ GEM actionpack (> 4, < 5.1) activemodel (> 4, < 5.1) simple_oauth (0.3.1) - simplecov (0.10.0) + simplecov (0.13.0) docile (~> 1.1.0) - json (~> 1.8) + json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) slop (3.6.0) @@ -380,7 +372,7 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) - timecop (0.8.0) + timecop (0.8.1) tins (1.6.0) twitter (5.14.0) addressable (~> 2.3) @@ -414,7 +406,6 @@ GEM webrobots (0.1.1) whenever (0.9.4) chronic (>= 0.6.3) - win32console (1.3.2) PLATFORMS ruby @@ -467,7 +458,8 @@ DEPENDENCIES rubyzip sanitize (~> 3.1.0) sass-rails (~> 4.0.0) - shoulda + shoulda-context + shoulda-matchers simple_form simplecov sprockets-rails diff --git a/app/logical/pixiv_web_agent.rb b/app/logical/pixiv_web_agent.rb index ed51e60c7..1266ebec4 100644 --- a/app/logical/pixiv_web_agent.rb +++ b/app/logical/pixiv_web_agent.rb @@ -10,6 +10,8 @@ class PixivWebAgent def self.build mech = Mechanize.new + mech.keep_alive = false + phpsessid = Cache.get(SESSION_CACHE_KEY) comicsessid = Cache.get(COMIC_SESSION_CACHE_KEY) diff --git a/app/logical/sources/strategies/nico_seiga.rb b/app/logical/sources/strategies/nico_seiga.rb index 51018726f..238c42cd2 100644 --- a/app/logical/sources/strategies/nico_seiga.rb +++ b/app/logical/sources/strategies/nico_seiga.rb @@ -131,6 +131,7 @@ module Sources def agent @agent ||= begin mech = Mechanize.new + mech.keep_alive = false session = Cache.get("nico-seiga-session") if session diff --git a/test/functional/tag_alias_corrections_controller_test.rb b/test/functional/tag_alias_corrections_controller_test.rb index 9a1b8a56f..344653ed4 100644 --- a/test/functional/tag_alias_corrections_controller_test.rb +++ b/test/functional/tag_alias_corrections_controller_test.rb @@ -7,7 +7,6 @@ class TagAliasCorrectionsControllerTest < ActionController::TestCase CurrentUser.user = @admin CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false @tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") end diff --git a/test/functional/tag_alias_requests_controller_test.rb b/test/functional/tag_alias_requests_controller_test.rb index fa7fe89cb..092dee541 100644 --- a/test/functional/tag_alias_requests_controller_test.rb +++ b/test/functional/tag_alias_requests_controller_test.rb @@ -7,7 +7,6 @@ class TagAliasRequestsControllerTest < ActionController::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index 1d099e8d9..83a4ed261 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -7,7 +7,6 @@ class TagAliasesControllerTest < ActionController::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do @@ -49,7 +48,7 @@ class TagAliasesControllerTest < ActionController::TestCase end # TODO: Broken in shoulda-matchers 2.8.0. Need to upgrade to 3.1.1. - should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update) + # should_eventually permit(:antecedent_name, :consequent_name, :forum_topic_id).for(:update) end context "for an approved alias" do diff --git a/test/functional/tag_implication_requests_controller_test.rb b/test/functional/tag_implication_requests_controller_test.rb index a440cd10e..456187dc6 100644 --- a/test/functional/tag_implication_requests_controller_test.rb +++ b/test/functional/tag_implication_requests_controller_test.rb @@ -9,7 +9,6 @@ class TagImplicationRequestsControllerTest < ActionController::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index e6408eb02..7c3bc58b7 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -7,7 +7,6 @@ class TagImplicationsControllerTest < ActionController::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/helpers/upload_test_helper.rb b/test/helpers/upload_test_helper.rb new file mode 100644 index 000000000..3b29574e6 --- /dev/null +++ b/test/helpers/upload_test_helper.rb @@ -0,0 +1,23 @@ +module UploadTestHelper + def upload_file(path, content_type, filename) + tempfile = Tempfile.new(filename) + FileUtils.copy_file(path, tempfile.path) + + (class << tempfile; self; end).class_eval do + alias local_path path + define_method(:tempfile) {self} + define_method(:original_filename) {filename} + define_method(:content_type) {content_type} + end + + tempfile + end + + def upload_jpeg(path) + upload_file(path, "image/jpeg", File.basename(path)) + end + + def upload_zip(path) + upload_file(path, "application/zip", File.basename(path)) + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 167b0fe2e..cf155a94d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,10 +3,8 @@ ENV["RAILS_ENV"] = "test" if ENV["SIMPLECOV"] require 'simplecov' SimpleCov.start 'rails' do - add_filter ".bundle" - add_filter "script/" - add_filter "test/" - add_filter "config/" + add_group "Libraries", ["app/logical", "lib"] + add_group "Presenters", "app/presenters" end end @@ -16,87 +14,9 @@ require 'cache' Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file} -module UploadTestMethods - def upload_file(path, content_type, filename) - tempfile = Tempfile.new(filename) - FileUtils.copy_file(path, tempfile.path) - (class << tempfile; self; end).class_eval do - alias local_path path - define_method(:tempfile) {self} - define_method(:original_filename) {filename} - define_method(:content_type) {content_type} - end - - tempfile - end - - def upload_jpeg(path) - upload_file(path, "image/jpeg", File.basename(path)) - end - - def upload_zip(path) - upload_file(path, "application/zip", File.basename(path)) - end -end - -class ActiveSupport::TestCase - include UploadTestMethods -end - -class ActionController::TestCase - include UploadTestMethods - - def assert_authentication_passes(action, http_method, role, params, session) - __send__(http_method, action, params, session.merge(:user_id => @users[role].id)) - assert_response :success - end - - def assert_authentication_fails(action, http_method, role) - __send__(http_method, action, params, session.merge(:user_id => @users[role].id)) - assert_redirected_to(new_sessions_path) - end -end - -class MockMemcache - def initialize - @memory = {} - end - - def flush_all - @memory = {} - end - - def fetch key, expiry = 0, raw = false - if @memory.has_key?(key) - @memory[key] - else - @memory[key] = yield - end - @memory[key] - end - - def incr key - @memory[key] += 1 - end - - def decr key - @memory[key] -= 1 - end - - def set key, value, expiry = 0 - @memory[key] = value - end - - def get key - @memory[key] - end - - def delete key, delay = 0 - @memory.delete key - end - - def get_multi *keys - Hash[[keys.map{ |key| [key, @memory[key]] }]] +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.library :rails end end @@ -104,4 +24,5 @@ if defined?(MEMCACHE) Object.send(:remove_const, :MEMCACHE) end -MEMCACHE = MockMemcache.new +MEMCACHE = MemcacheMock.new +Delayed::Worker.delay_jobs = false diff --git a/test/unit/advertisement_test.rb b/test/unit/advertisement_test.rb index 42a06038f..bc429ec74 100644 --- a/test/unit/advertisement_test.rb +++ b/test/unit/advertisement_test.rb @@ -1,6 +1,9 @@ require 'test_helper' +require 'helpers/upload_test_helper' class AdvertisementTest < ActiveSupport::TestCase + include UploadTestHelper + context "An advertisement" do setup do Danbooru.config.stubs(:advertisement_path).returns("/tmp") diff --git a/test/unit/alias_and_implication_importer_test.rb b/test/unit/alias_and_implication_importer_test.rb index 5a01e8c94..77b811841 100644 --- a/test/unit/alias_and_implication_importer_test.rb +++ b/test/unit/alias_and_implication_importer_test.rb @@ -3,9 +3,7 @@ require 'test_helper' class AliasAndImplicationImporterTest < ActiveSupport::TestCase context "The alias and implication importer" do setup do - Delayed::Worker.delay_jobs = true - @user = FactoryGirl.create(:user) - CurrentUser.user = @user + CurrentUser.user = FactoryGirl.create(:admin_user) CurrentUser.ip_addr = "127.0.0.1" end @@ -21,9 +19,9 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase end should "process it" do - assert_difference("Delayed::Job.count", 2) do - @importer.process! - end + @importer.process! + assert(TagAlias.exists?(antecedent_name: "abc", consequent_name: "def")) + assert(TagImplication.exists?(antecedent_name: "aaa", consequent_name: "bbb")) end end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index c233b2cd5..cc062c0b8 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -19,7 +19,6 @@ class ArtistTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 74a62f4bf..2cd9609e1 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -6,7 +6,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase @admin = FactoryGirl.create(:admin_user) CurrentUser.user = @admin CurrentUser.ip_addr = "127.0.0.1" - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/downloads/pixiv_test.rb b/test/unit/downloads/pixiv_test.rb index f7587c8b2..4bdc76532 100644 --- a/test/unit/downloads/pixiv_test.rb +++ b/test/unit/downloads/pixiv_test.rb @@ -27,7 +27,6 @@ module Downloads context "An ugoira site for pixiv" do setup do - Delayed::Worker.delay_jobs = false @tempfile = Tempfile.new("danbooru-test") @download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654", @tempfile.path) @download.download! diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 354b2d333..9104eb3ab 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -13,7 +13,6 @@ class PostTest < ActiveSupport::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false mock_saved_search_service! end @@ -520,7 +519,6 @@ class PostTest < ActiveSupport::TestCase context "with an artist tag that is then changed to copyright" do setup do CurrentUser.user = FactoryGirl.create(:builder_user) - Delayed::Worker.delay_jobs = false @post = Post.find(@post.id) @post.update(:tag_string => "art:abc") @post = Post.find(@post.id) @@ -528,10 +526,6 @@ class PostTest < ActiveSupport::TestCase @post.reload end - teardown do - Delayed::Worker.delay_jobs = true - end - should "update the category of the tag" do assert_equal(Tag.categories.copyright, Tag.find_by_name("abc").category) end @@ -1336,7 +1330,7 @@ class PostTest < ActiveSupport::TestCase subject { @post } should_not allow_value("S", "safe", "derp").for(:rating) - should_not allow_value("s", "q", "e").for(:rating) + should_not allow_value("s", "e").for(:rating) end end diff --git a/test/unit/related_tag_query_test.rb b/test/unit/related_tag_query_test.rb index d8c57b0d3..01507098d 100644 --- a/test/unit/related_tag_query_test.rb +++ b/test/unit/related_tag_query_test.rb @@ -6,7 +6,6 @@ class RelatedTagQueryTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end context "a related tag query without a category constraint" do diff --git a/test/unit/tag_alias_correction_test.rb b/test/unit/tag_alias_correction_test.rb index 1e2780d12..c9e48575d 100644 --- a/test/unit/tag_alias_correction_test.rb +++ b/test/unit/tag_alias_correction_test.rb @@ -7,7 +7,6 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase CurrentUser.user = @mod CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false @post = FactoryGirl.create(:post, :tag_string => "aaa") @tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") end @@ -27,7 +26,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase should "have the correct statistics hash" do assert_equal("zzz", @correction.statistics_hash["antecedent_cache"]) - assert_equal(nil, @correction.statistics_hash["consequent_cache"]) + assert_nil(@correction.statistics_hash["consequent_cache"]) assert_equal(-3, @correction.statistics_hash["antecedent_count"]) assert_equal(1, @correction.statistics_hash["consequent_count"]) end diff --git a/test/unit/tag_alias_request_test.rb b/test/unit/tag_alias_request_test.rb index e2cffe41b..15aa68196 100644 --- a/test/unit/tag_alias_request_test.rb +++ b/test/unit/tag_alias_request_test.rb @@ -7,7 +7,6 @@ class TagAliasRequestTest < ActiveSupport::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/tag_alias_test.rb b/test/unit/tag_alias_test.rb index 8b5322718..3681d0ee5 100644 --- a/test/unit/tag_alias_test.rb +++ b/test/unit/tag_alias_test.rb @@ -12,7 +12,6 @@ class TagAliasTest < ActiveSupport::TestCase end CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false mock_saved_search_service! end diff --git a/test/unit/tag_implication_request_test.rb b/test/unit/tag_implication_request_test.rb index e99c13ad4..a9047aee7 100644 --- a/test/unit/tag_implication_request_test.rb +++ b/test/unit/tag_implication_request_test.rb @@ -7,7 +7,6 @@ class TagImplicationRequestTest < ActiveSupport::TestCase CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/tag_implication_test.rb b/test/unit/tag_implication_test.rb index 910dd8604..e3e49c602 100644 --- a/test/unit/tag_implication_test.rb +++ b/test/unit/tag_implication_test.rb @@ -8,7 +8,6 @@ class TagImplicationTest < ActiveSupport::TestCase CurrentUser.ip_addr = "127.0.0.1" @user = FactoryGirl.create(:user) MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/tag_subscription_test.rb b/test/unit/tag_subscription_test.rb index a3a57aa55..4da3d6416 100644 --- a/test/unit/tag_subscription_test.rb +++ b/test/unit/tag_subscription_test.rb @@ -5,7 +5,6 @@ class TagSubscriptionTest < ActiveSupport::TestCase user = FactoryGirl.create(:user) CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" - Delayed::Worker.delay_jobs = false MEMCACHE.flush_all end diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 5959e9a7b..ce60e0311 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -6,7 +6,6 @@ class TagTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index 627f41200..3887a7355 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -1,8 +1,10 @@ require 'test_helper' require 'helpers/iqdb_test_helper' +require 'helpers/upload_test_helper' class UploadTest < ActiveSupport::TestCase include IqdbTestHelper + include UploadTestHelper def setup super @@ -16,13 +18,11 @@ class UploadTest < ActiveSupport::TestCase CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" MEMCACHE.flush_all - Delayed::Worker.delay_jobs = false end teardown do CurrentUser.user = nil CurrentUser.ip_addr = nil - Delayed::Worker.delay_jobs = true @upload.delete_temp_file if @upload end diff --git a/test/unit/user_deletion_test.rb b/test/unit/user_deletion_test.rb index 1a6db0811..3fd9b2bda 100644 --- a/test/unit/user_deletion_test.rb +++ b/test/unit/user_deletion_test.rb @@ -4,7 +4,6 @@ class UserDeletionTest < ActiveSupport::TestCase context "an invalid user deletion" do context "for an invalid password" do setup do - Delayed::Worker.delay_jobs = false @user = FactoryGirl.create(:user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -20,7 +19,6 @@ class UserDeletionTest < ActiveSupport::TestCase context "for an admin" do setup do - Delayed::Worker.delay_jobs = false @user = FactoryGirl.create(:admin_user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -37,8 +35,6 @@ class UserDeletionTest < ActiveSupport::TestCase context "a valid user deletion" do setup do - Delayed::Worker.delay_jobs = false - @user = FactoryGirl.create(:user) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1"