Sha256: ab0b9ba562bc3291b5524db996b00707a2f8e4067dd9f41165e9b39c1bf84cc3

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'test_helper'

class AttachmentMagick::ImagesControllerTest < ActionController::TestCase

  setup do
    create_artist
    create_work(@artist)
    create_place
  end

  test "should create artist image" do
    post :create, artist_hash.merge({ :Filedata => exemple_file })
    assert_response :success
    assert  assert_element_in(response.body, "img")
  end

  test "should create work image" do
    post :create, work_hash.merge({ :Filedata => exemple_file })
    assert_response :success
    assert  assert_element_in(response.body, "img")
  end

  test "should create place image" do
    post :create, place_hash.merge({ :Filedata => exemple_file })
    assert_response :success
    assert  assert_element_in(response.body, "img")
  end

  test "should update priority order" do
    4.times{ @artist.images.create(:photo => exemple_file) }
    @artist.save
    @artist.reload

    image_first = @artist.images.first
    image_last  = @artist.images.last

    post :update_sortable, artist_hash.merge({ :images => @artist.images.map(&:id).reverse })

    @artist.reload

    assert_equal image_first, @artist.images.order_by(:priority.asc).last
    assert_equal image_last,  @artist.images.order_by(:priority.asc).first
  end

  test "should destroy image" do
    get :destroy, artist_hash.merge({ :id => @artist.images.first.to_param })

    @artist.reload
    assert_response :success
    assert_nil @artist.images.first
  end


  private

  def artist_hash
    {:data_attachment => "#{@artist.class.name}_#{@artist.id}"}
  end

  def work_hash
    {:data_attachment => "#{@artist.class.name}_#{@artist.id}_works_#{@artist.works.last.id}", :data_partial => exemple_partial}
  end

  def place_hash
    {:data_attachment => "#{@place.class.name}_#{@place.id}"}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachment_magick-0.1.0 test/attachment_magick/controllers/images_controller_test.rb