From c00c110cf953009a5be765ad0d8505933d821562 Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Mon, 9 Jul 2018 12:15:18 +0300 Subject: [PATCH] Make test run, use appraisal, cleanup --- .gitignore | 4 ++- Appraisals | 15 +++++++++ Gemfile | 11 ++++++- Rakefile | 2 +- gemfiles/rails_40.gemfile | 15 +++++++++ gemfiles/rails_41.gemfile | 15 +++++++++ gemfiles/rails_42.gemfile | 15 +++++++++ gemfiles/rails_5.gemfile | 15 +++++++++ paperclip.gemspec | 18 +---------- test/attachment_test.rb | 7 ++-- test/geometry_test.rb | 2 +- test/integration_test.rb | 2 +- test/interpolations_test.rb | 2 +- test/iostream_test.rb | 2 +- .../have_attached_file_matcher_test.rb | 2 +- ...te_attachment_content_type_matcher_test.rb | 2 +- ...lidate_attachment_presence_matcher_test.rb | 2 +- .../validate_attachment_size_matcher_test.rb | 2 +- test/paperclip_test.rb | 2 +- test/processor_test.rb | 2 +- .../shoulda_macros}/paperclip.rb | 0 test/storage_test.rb | 2 +- test/{helper.rb => test_helper.rb} | 32 ++++++------------- test/thumbnail_test.rb | 2 +- 24 files changed, 114 insertions(+), 59 deletions(-) create mode 100644 Appraisals create mode 100644 gemfiles/rails_40.gemfile create mode 100644 gemfiles/rails_41.gemfile create mode 100644 gemfiles/rails_42.gemfile create mode 100644 gemfiles/rails_5.gemfile rename {shoulda_macros => test/shoulda_macros}/paperclip.rb (100%) rename test/{helper.rb => test_helper.rb} (80%) diff --git a/.gitignore b/.gitignore index 6ca246e..2650159 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -Gemfile.lock .ruby-version +Gemfile.lock +gemfiles/*.lock +tmp/ diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..3f9e10c --- /dev/null +++ b/Appraisals @@ -0,0 +1,15 @@ +appraise 'rails_40' do + gem 'rails', '~> 4.0.0' +end + +appraise 'rails_41' do + gem 'rails', '~> 4.1.0' +end + +appraise 'rails_42' do + gem 'rails', '~> 4.2.0' +end + +appraise 'rails_5' do + gem 'rails', '~> 5.2.0' +end diff --git a/Gemfile b/Gemfile index 16ef4c1..9e8c6bd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,15 @@ # coding: utf-8 source 'http://rubygems.org' +gemspec + +gem 'appraisal' gem 'fastimage' +gem 'sqlite3' -gemspec +gem 'test-unit' +gem 'thoughtbot-shoulda', '>= 2.9.0' +gem 'mocha' + +gem 'pry' +gem 'pry-byebug' diff --git a/Rakefile b/Rakefile index f9b9ca8..f745f1c 100644 --- a/Rakefile +++ b/Rakefile @@ -12,7 +12,7 @@ task :default => [:clean, :test] desc 'Test the paperclip plugin.' Rake::TestTask.new(:test) do |t| - t.libs << 'lib' << 'profile' + t.libs << 'lib' << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end diff --git a/gemfiles/rails_40.gemfile b/gemfiles/rails_40.gemfile new file mode 100644 index 0000000..253ada9 --- /dev/null +++ b/gemfiles/rails_40.gemfile @@ -0,0 +1,15 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal" +gem "fastimage" +gem "sqlite3" +gem "test-unit" +gem "thoughtbot-shoulda", ">= 2.9.0" +gem "mocha" +gem "pry" +gem "pry-byebug" +gem "rails", "~> 4.0.0" + +gemspec path: "../" diff --git a/gemfiles/rails_41.gemfile b/gemfiles/rails_41.gemfile new file mode 100644 index 0000000..20cf287 --- /dev/null +++ b/gemfiles/rails_41.gemfile @@ -0,0 +1,15 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal" +gem "fastimage" +gem "sqlite3" +gem "test-unit" +gem "thoughtbot-shoulda", ">= 2.9.0" +gem "mocha" +gem "pry" +gem "pry-byebug" +gem "rails", "~> 4.1.0" + +gemspec path: "../" diff --git a/gemfiles/rails_42.gemfile b/gemfiles/rails_42.gemfile new file mode 100644 index 0000000..ef071b0 --- /dev/null +++ b/gemfiles/rails_42.gemfile @@ -0,0 +1,15 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal" +gem "fastimage" +gem "sqlite3" +gem "test-unit" +gem "thoughtbot-shoulda", ">= 2.9.0" +gem "mocha" +gem "pry" +gem "pry-byebug" +gem "rails", "~> 4.2.0" + +gemspec path: "../" diff --git a/gemfiles/rails_5.gemfile b/gemfiles/rails_5.gemfile new file mode 100644 index 0000000..e0eef65 --- /dev/null +++ b/gemfiles/rails_5.gemfile @@ -0,0 +1,15 @@ +# This file was generated by Appraisal + +source "http://rubygems.org" + +gem "appraisal" +gem "fastimage" +gem "sqlite3" +gem "test-unit" +gem "thoughtbot-shoulda", ">= 2.9.0" +gem "mocha" +gem "pry" +gem "pry-byebug" +gem "rails", "~> 5.2.0" + +gemspec path: "../" diff --git a/paperclip.gemspec b/paperclip.gemspec index 25aeb12..7e5117c 100644 --- a/paperclip.gemspec +++ b/paperclip.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |s| s.date = %q{2009-06-18} s.email = %q{jyurek@thoughtbot.com} s.extra_rdoc_files = ["README.rdoc"] - s.files = ["README.rdoc", "LICENSE", "Rakefile", "init.rb", "generators/paperclip", "generators/paperclip/paperclip_generator.rb", "generators/paperclip/templates", "generators/paperclip/templates/paperclip_migration.rb.erb", "generators/paperclip/USAGE", "lib/paperclip", "lib/paperclip/attachment.rb", "lib/paperclip/callback_compatability.rb", "lib/paperclip/geometry.rb", "lib/paperclip/interpolations.rb", "lib/paperclip/iostream.rb", "lib/paperclip/matchers", "lib/paperclip/matchers/have_attached_file_matcher.rb", "lib/paperclip/matchers/validate_attachment_content_type_matcher.rb", "lib/paperclip/matchers/validate_attachment_presence_matcher.rb", "lib/paperclip/matchers/validate_attachment_size_matcher.rb", "lib/paperclip/matchers.rb", "lib/paperclip/processor.rb", "lib/paperclip/storage.rb", "lib/paperclip/thumbnail.rb", "lib/paperclip/upfile.rb", "lib/paperclip.rb", "tasks/paperclip_tasks.rake", "test/attachment_test.rb", "test/database.yml", "test/fixtures", "test/fixtures/12k.png", "test/fixtures/50x50.png", "test/fixtures/5k.png", "test/fixtures/bad.png", "test/fixtures/s3.yml", "test/fixtures/text.txt", "test/fixtures/twopage.pdf", "test/geometry_test.rb", "test/helper.rb", "test/integration_test.rb", "test/interpolations_test.rb", "test/iostream_test.rb", "test/matchers", "test/matchers/have_attached_file_matcher_test.rb", "test/matchers/validate_attachment_content_type_matcher_test.rb", "test/matchers/validate_attachment_presence_matcher_test.rb", "test/matchers/validate_attachment_size_matcher_test.rb", "test/paperclip_test.rb", "test/processor_test.rb", "test/storage_test.rb", "test/thumbnail_test.rb", "shoulda_macros/paperclip.rb"] + s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|gemfiles)/}) } s.has_rdoc = true s.homepage = %q{http://www.thoughtbot.com/projects/paperclip} s.rdoc_options = ["--line-numbers", "--inline-source"] @@ -19,20 +19,4 @@ Gem::Specification.new do |s| s.summary = %q{File attachments as attributes for ActiveRecord} s.add_dependency('sidekiq', ["~> 2.0"]) - - if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 2 - - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, [">= 0"]) - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - end - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - end end diff --git a/test/attachment_test.rb b/test/attachment_test.rb index 1c13f6f..05e6781 100644 --- a/test/attachment_test.rb +++ b/test/attachment_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class Dummy # This is a dummy class @@ -105,12 +105,11 @@ class AttachmentTest < Test::Unit::TestCase @dummy.stubs(:id).returns(@id) @file = StringIO.new(".") @dummy.avatar = @file + Rails.stub(:env) { @rails_env } end should "return the proper path" do - temporary_rails_env(@rails_env) { - assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path - } + assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path end end diff --git a/test/geometry_test.rb b/test/geometry_test.rb index 4b31a10..abf7a5f 100644 --- a/test/geometry_test.rb +++ b/test/geometry_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class GeometryTest < Test::Unit::TestCase context "Paperclip::Geometry" do diff --git a/test/integration_test.rb b/test/integration_test.rb index 2ab4493..5ead913 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class IntegrationTest < Test::Unit::TestCase context "Many models at once" do diff --git a/test/interpolations_test.rb b/test/interpolations_test.rb index 8ff4451..f0cd089 100644 --- a/test/interpolations_test.rb +++ b/test/interpolations_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class InterpolationsTest < Test::Unit::TestCase should "return all methods but the infrastructure when sent #all" do diff --git a/test/iostream_test.rb b/test/iostream_test.rb index 97030b5..37b0d9a 100644 --- a/test/iostream_test.rb +++ b/test/iostream_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class IOStreamTest < Test::Unit::TestCase context "IOStream" do diff --git a/test/matchers/have_attached_file_matcher_test.rb b/test/matchers/have_attached_file_matcher_test.rb index b29ec37..a2a6512 100644 --- a/test/matchers/have_attached_file_matcher_test.rb +++ b/test/matchers/have_attached_file_matcher_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class HaveAttachedFileMatcherTest < Test::Unit::TestCase context "have_attached_file" do diff --git a/test/matchers/validate_attachment_content_type_matcher_test.rb b/test/matchers/validate_attachment_content_type_matcher_test.rb index 241eb5f..b12dd4e 100644 --- a/test/matchers/validate_attachment_content_type_matcher_test.rb +++ b/test/matchers/validate_attachment_content_type_matcher_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase context "validate_attachment_content_type" do diff --git a/test/matchers/validate_attachment_presence_matcher_test.rb b/test/matchers/validate_attachment_presence_matcher_test.rb index 860a760..450253c 100644 --- a/test/matchers/validate_attachment_presence_matcher_test.rb +++ b/test/matchers/validate_attachment_presence_matcher_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase context "validate_attachment_presence" do diff --git a/test/matchers/validate_attachment_size_matcher_test.rb b/test/matchers/validate_attachment_size_matcher_test.rb index 7e4c9b4..75bf1bb 100644 --- a/test/matchers/validate_attachment_size_matcher_test.rb +++ b/test/matchers/validate_attachment_size_matcher_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase context "validate_attachment_size" do diff --git a/test/paperclip_test.rb b/test/paperclip_test.rb index 4b43037..b643199 100644 --- a/test/paperclip_test.rb +++ b/test/paperclip_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class PaperclipTest < Test::Unit::TestCase [:image_magick_path, :convert_path].each do |path| diff --git a/test/processor_test.rb b/test/processor_test.rb index a05f0a9..7ffc011 100644 --- a/test/processor_test.rb +++ b/test/processor_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class ProcessorTest < Test::Unit::TestCase should "instantiate and call #make when sent #make to the class" do diff --git a/shoulda_macros/paperclip.rb b/test/shoulda_macros/paperclip.rb similarity index 100% rename from shoulda_macros/paperclip.rb rename to test/shoulda_macros/paperclip.rb diff --git a/test/storage_test.rb b/test/storage_test.rb index 5cf666d..5b3b7c6 100644 --- a/test/storage_test.rb +++ b/test/storage_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class StorageTest < Test::Unit::TestCase context "Parsing S3 credentials" do diff --git a/test/helper.rb b/test/test_helper.rb similarity index 80% rename from test/helper.rb rename to test/test_helper.rb index 8ae6201..6e21342 100644 --- a/test/helper.rb +++ b/test/test_helper.rb @@ -1,23 +1,20 @@ require 'rubygems' require 'test/unit' -gem 'thoughtbot-shoulda', ">= 2.9.0" require 'shoulda' -require 'mocha' +require 'mocha/test_unit' +require 'pry' require 'tempfile' - -gem 'sqlite3-ruby' +require 'sqlite3' require 'active_record' require 'active_support' -begin - require 'ruby-debug' -rescue LoadError - puts "ruby-debug not loaded" -end +require 'rails' -ROOT = File.join(File.dirname(__FILE__), '..') -Rails.root = ROOT -Rails.env = "test" +ROOT = File.expand_path('../', __dir__) + +ENV['RAILS_ENV'] = 'test' +class TestRailsApp < Rails::Application; end +Rails.application.config.root = "#{ROOT}/tmp/rails" $LOAD_PATH << File.join(ROOT, 'lib') $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip') @@ -69,17 +66,6 @@ def rebuild_class options = {} end end -def temporary_rails_env(new_env) - old_env = Object.const_defined?("Rails.env") ? Rails.env : nil - silence_warnings do - Object.const_set("Rails.env", new_env) - end - yield - silence_warnings do - Object.const_set("Rails.env", old_env) - end -end - class FakeModel attr_accessor :avatar_file_name, :avatar_file_size, diff --git a/test/thumbnail_test.rb b/test/thumbnail_test.rb index 11d8083..bdd0d83 100644 --- a/test/thumbnail_test.rb +++ b/test/thumbnail_test.rb @@ -1,4 +1,4 @@ -require 'test/helper' +require 'test_helper' class ThumbnailTest < Test::Unit::TestCase