Skip to content

Commit

Permalink
Fast to slowly spec
Browse files Browse the repository at this point in the history
```
 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
  • Loading branch information
soramugi authored and Jon Yurek committed Dec 5, 2014
1 parent 3a76abe commit ae3ec23
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 62 deletions.
1 change: 1 addition & 0 deletions paperclip.gemspec
Expand Up @@ -48,4 +48,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('actionmailer', '>= 3.0.0')
s.add_development_dependency('generator_spec')
s.add_development_dependency('timecop')
s.add_development_dependency('activerecord-import')
end
123 changes: 61 additions & 62 deletions spec/paperclip/integration_spec.rb
Expand Up @@ -7,17 +7,16 @@
before do
rebuild_model
@file = File.new(fixture_file("5k.png"), 'rb')
300.times do |i|
Dummy.create! avatar: @file
end
dummys = 300.times.map { |i| Dummy.new avatar: @file }
Dummy.import dummys
end

after { @file.close }

it "does not exceed the open file limit" do
assert_nothing_raised do
Dummy.all.each { |dummy| dummy.avatar }
end
assert_nothing_raised do
Dummy.all.each { |dummy| dummy.avatar }
end
end
end

Expand Down Expand Up @@ -164,8 +163,8 @@
context "A model with attachments scoped under an id" do
before do
rebuild_model styles: { large: "100x100",
medium: "50x50" },
path: ":rails_root/tmp/:id/:attachments/:style.:extension"
medium: "50x50" },
path: ":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
Expand Down Expand Up @@ -265,11 +264,11 @@
context "A model with a filesystem attachment" do
before do
rebuild_model styles: { large: "300x300>",
medium: "100x100",
thumb: ["32x32#", :gif] },
default_style: :medium,
url: "/:attachment/:class/:style/:id/:basename.:extension",
path: ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
medium: "100x100",
thumb: ["32x32#", :gif] },
default_style: :medium,
url: "/:attachment/:class/:style/:id/:basename.:extension",
path: ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@bad_file = File.new(fixture_file("bad.png"), 'rb')
Expand All @@ -286,37 +285,37 @@
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@dummy.avatar.path(style)}"]
assert_equal geo, `#{cmd}`.chomp, cmd
end
cmd = %Q[identify -format "%wx%h" "#{@dummy.avatar.path(style)}"]
assert_equal geo, `#{cmd}`.chomp, cmd
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)
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 "300x46", `identify -format "%wx%h" "#{@d2.avatar.path(:large)}"`.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
@d2 = Dummy.find(@dummy.id)
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 "300x46", `identify -format "%wx%h" "#{@d2.avatar.path(:large)}"`.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 @dummy.valid?
assert @dummy.save
assert @dummy.valid?
assert @dummy.save

saved_paths.each do |p|
assert_file_exists(p)
end
saved_paths.each do |p|
assert_file_exists(p)
end

@dummy.avatar.clear
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save
@dummy.avatar.clear
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save

saved_paths.each do |p|
assert_file_not_exists(p)
end
saved_paths.each do |p|
assert_file_not_exists(p)
end

@d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name
@d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name
end

it "works exactly the same when new as when reloaded" do
Expand Down Expand Up @@ -411,9 +410,9 @@
context "A model with an attachment with hash in file name" do
before do
@settings = { styles: { thumb: "50x50#" },
path: ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
url: "/system/:attachment/:id_partition/:style/:hash.:extension",
hash_secret: "somesecret" }
path: ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
url: "/system/:attachment/:id_partition/:style/:hash.:extension",
hash_secret: "somesecret" }

rebuild_model @settings

Expand Down Expand Up @@ -527,31 +526,31 @@ def s3_headers_for attachment, style
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@files_on_s3[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd
end

@d2 = Dummy.find(@dummy.id)
@d2_files = s3_files_for @d2.avatar
[["434x66", :original],
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@d2_files[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd
end
cmd = %Q[identify -format "%wx%h" "#{@files_on_s3[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd
end

@d2 = Dummy.find(@dummy.id)
@d2_files = s3_files_for @d2.avatar
[["434x66", :original],
["300x46", :large],
["100x15", :medium],
["32x32", :thumb]].each do |geo, style|
cmd = %Q[identify -format "%wx%h" "#{@d2_files[style].path}"]
assert_equal geo, `#{cmd}`.chomp, cmd
end

@dummy.avatar.clear
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save
@dummy.avatar.clear
assert_nil @dummy.avatar_file_name
assert @dummy.valid?
assert @dummy.save

[:thumb, :medium, :large, :original].each do |style|
assert ! @dummy.avatar.exists?(style)
end
[:thumb, :medium, :large, :original].each do |style|
assert ! @dummy.avatar.exists?(style)
end

@d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name
@d2 = Dummy.find(@dummy.id)
assert_nil @d2.avatar_file_name
end

it "works exactly the same when new as when reloaded" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -7,6 +7,7 @@
require 'mocha/api'
require 'bourne'
require 'ostruct'
require 'activerecord-import'

ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))

Expand Down

0 comments on commit ae3ec23

Please sign in to comment.