Commit ae3ec237 by soramugi Committed by Jon Yurek

Fast to slowly spec

```
 paperclip $ rspec spec/paperclip/integration_spec.rb --profile 1
Testing against version 4.1.7
.........................[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
.........

Finished in 15.19 seconds (files took 0.60155 seconds to load)
34 examples, 0 failures

Top 1 slowest examples (9.54 seconds, 62.8% of total time):
  Paperclip Many models at once does not exceed the open file limit
    9.54 seconds ./spec/paperclip/integration_spec.rb:18
```

to

```
 paperclip $ rspec spec/paperclip/integration_spec.rb --profile 1
Testing against version 4.1.7
.........................[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
.........

Finished in 10.95 seconds (files took 0.59585 seconds to load)
34 examples, 0 failures

Top 1 slowest examples (5.33 seconds, 48.7% of total time):
  Paperclip Many models at once does not exceed the open file limit
    5.33 seconds ./spec/paperclip/integration_spec.rb:18
```

at trim indent
parent 3a76abef
...@@ -48,4 +48,5 @@ Gem::Specification.new do |s| ...@@ -48,4 +48,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('actionmailer', '>= 3.0.0') s.add_development_dependency('actionmailer', '>= 3.0.0')
s.add_development_dependency('generator_spec') s.add_development_dependency('generator_spec')
s.add_development_dependency('timecop') s.add_development_dependency('timecop')
s.add_development_dependency('activerecord-import')
end end
...@@ -7,17 +7,16 @@ describe 'Paperclip' do ...@@ -7,17 +7,16 @@ describe 'Paperclip' do
before do before do
rebuild_model rebuild_model
@file = File.new(fixture_file("5k.png"), 'rb') @file = File.new(fixture_file("5k.png"), 'rb')
300.times do |i| dummys = 300.times.map { |i| Dummy.new avatar: @file }
Dummy.create! avatar: @file Dummy.import dummys
end
end end
after { @file.close } after { @file.close }
it "does not exceed the open file limit" do it "does not exceed the open file limit" do
assert_nothing_raised do assert_nothing_raised do
Dummy.all.each { |dummy| dummy.avatar } Dummy.all.each { |dummy| dummy.avatar }
end end
end end
end end
...@@ -164,8 +163,8 @@ describe 'Paperclip' do ...@@ -164,8 +163,8 @@ describe 'Paperclip' do
context "A model with attachments scoped under an id" do context "A model with attachments scoped under an id" do
before do before do
rebuild_model styles: { large: "100x100", rebuild_model styles: { large: "100x100",
medium: "50x50" }, medium: "50x50" },
path: ":rails_root/tmp/:id/:attachments/:style.:extension" path: ":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy = Dummy.new @dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb') @file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file @dummy.avatar = @file
...@@ -265,11 +264,11 @@ describe 'Paperclip' do ...@@ -265,11 +264,11 @@ describe 'Paperclip' do
context "A model with a filesystem attachment" do context "A model with a filesystem attachment" do
before do before do
rebuild_model styles: { large: "300x300>", rebuild_model styles: { large: "300x300>",
medium: "100x100", medium: "100x100",
thumb: ["32x32#", :gif] }, thumb: ["32x32#", :gif] },
default_style: :medium, default_style: :medium,
url: "/:attachment/:class/:style/:id/:basename.:extension", url: "/:attachment/:class/:style/:id/:basename.:extension",
path: ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" path: ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new @dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb') @file = File.new(fixture_file("5k.png"), 'rb')
@bad_file = File.new(fixture_file("bad.png"), 'rb') @bad_file = File.new(fixture_file("bad.png"), 'rb')
...@@ -286,37 +285,37 @@ describe 'Paperclip' do ...@@ -286,37 +285,37 @@ describe 'Paperclip' do
["300x46", :large], ["300x46", :large],
["100x15", :medium], ["100x15", :medium],
["32x32", :thumb]].each do |geo, style| ["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@dummy.avatar.path(style)}"] cmd = %Q[identify -format "%wx%h" "#{@dummy.avatar.path(style)}"]
assert_equal geo, `#{cmd}`.chomp, cmd assert_equal geo, `#{cmd}`.chomp, cmd
end end
saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.path(s) } saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.path(s) }
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path}"`.chomp assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path}"`.chomp
assert_equal "434x66", `identify -format "%wx%h" "#{@d2.avatar.path(:original)}"`.chomp assert_equal "434x66", `identify -format "%wx%h" "#{@d2.avatar.path(:original)}"`.chomp
assert_equal "300x46", `identify -format "%wx%h" "#{@d2.avatar.path(:large)}"`.chomp assert_equal "300x46", `identify -format "%wx%h" "#{@d2.avatar.path(:large)}"`.chomp
assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path(:medium)}"`.chomp assert_equal "100x15", `identify -format "%wx%h" "#{@d2.avatar.path(:medium)}"`.chomp
assert_equal "32x32", `identify -format "%wx%h" "#{@d2.avatar.path(:thumb)}"`.chomp assert_equal "32x32", `identify -format "%wx%h" "#{@d2.avatar.path(:thumb)}"`.chomp
assert @dummy.valid? assert @dummy.valid?
assert @dummy.save assert @dummy.save
saved_paths.each do |p| saved_paths.each do |p|
assert_file_exists(p) assert_file_exists(p)
end end
@dummy.avatar.clear @dummy.avatar.clear
assert_nil @dummy.avatar_file_name assert_nil @dummy.avatar_file_name
assert @dummy.valid? assert @dummy.valid?
assert @dummy.save assert @dummy.save
saved_paths.each do |p| saved_paths.each do |p|
assert_file_not_exists(p) assert_file_not_exists(p)
end end
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name assert_nil @d2.avatar_file_name
end end
it "works exactly the same when new as when reloaded" do it "works exactly the same when new as when reloaded" do
...@@ -411,9 +410,9 @@ describe 'Paperclip' do ...@@ -411,9 +410,9 @@ describe 'Paperclip' do
context "A model with an attachment with hash in file name" do context "A model with an attachment with hash in file name" do
before do before do
@settings = { styles: { thumb: "50x50#" }, @settings = { styles: { thumb: "50x50#" },
path: ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension", path: ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
url: "/system/:attachment/:id_partition/:style/:hash.:extension", url: "/system/:attachment/:id_partition/:style/:hash.:extension",
hash_secret: "somesecret" } hash_secret: "somesecret" }
rebuild_model @settings rebuild_model @settings
...@@ -527,31 +526,31 @@ describe 'Paperclip' do ...@@ -527,31 +526,31 @@ describe 'Paperclip' do
["300x46", :large], ["300x46", :large],
["100x15", :medium], ["100x15", :medium],
["32x32", :thumb]].each do |geo, style| ["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@files_on_s3[style].path}"] cmd = %Q[identify -format "%wx%h" "#{@files_on_s3[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd assert_equal geo, `#{cmd}`.chomp, cmd
end end
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
@d2_files = s3_files_for @d2.avatar @d2_files = s3_files_for @d2.avatar
[["434x66", :original], [["434x66", :original],
["300x46", :large], ["300x46", :large],
["100x15", :medium], ["100x15", :medium],
["32x32", :thumb]].each do |geo, style| ["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@d2_files[style].path}"] cmd = %Q[identify -format "%wx%h" "#{@d2_files[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd assert_equal geo, `#{cmd}`.chomp, cmd
end end
@dummy.avatar.clear @dummy.avatar.clear
assert_nil @dummy.avatar_file_name assert_nil @dummy.avatar_file_name
assert @dummy.valid? assert @dummy.valid?
assert @dummy.save assert @dummy.save
[:thumb, :medium, :large, :original].each do |style| [:thumb, :medium, :large, :original].each do |style|
assert ! @dummy.avatar.exists?(style) assert ! @dummy.avatar.exists?(style)
end end
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name assert_nil @d2.avatar_file_name
end end
it "works exactly the same when new as when reloaded" do it "works exactly the same when new as when reloaded" do
......
...@@ -7,6 +7,7 @@ require 'active_support/core_ext' ...@@ -7,6 +7,7 @@ require 'active_support/core_ext'
require 'mocha/api' require 'mocha/api'
require 'bourne' require 'bourne'
require 'ostruct' require 'ostruct'
require 'activerecord-import'
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..'))) ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment