Sha256: f1850444cd6dbafe80863e194c9f1aa62195a580071e7b5a0fc1c32ab5540be4

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'
require 'rake'

class TasksTest < ActiveSupport::TestCase

  setup do
    Dummy::Application.load_tasks
  end

  test 'refresh all styles' do
    Medium.create(attach: image_upload)
    original_small_time = small_time
    original_big_time = big_time
    ENV['CLASS'] = 'medium'
    ENV['ATTACHMENT'] = 'attach'
    sleep 1
    Rake::Task['attachs:refresh:all'].invoke
    assert File.file?(image_path(:small))
    assert File.file?(image_path(:big))
    assert_not_equal original_small_time, small_time
    assert_not_equal original_big_time, big_time
  end

  test 'refersh missing styles' do
    Medium.create(attach: image_upload)
    original_big_time = big_time
    original_small_time = small_time
    File.delete image_path(:small)
    ENV['CLASS'] = 'medium'
    ENV['ATTACHMENT'] = 'attach'
    sleep 1
    Rake::Task['attachs:refresh:missing'].invoke
    assert File.file?(image_path(:small))
    assert File.file?(image_path(:big))
    assert_not_equal original_small_time, small_time
    assert_equal original_big_time, big_time
  end

  private

  def image_path(style=:original)
    Rails.root.join("public/#{style}/180x150.gif")
  end

  def small_path
    image_path(:small)
  end

  def big_path
    image_path(:big)
  end

  def small_time
    File.mtime(small_path)
  end

  def big_time
    File.mtime(big_path)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachs-0.4.0 test/tasks_test.rb