Sha256: ad869676efe512ef488bbac44a319bf1db80b8a6f8b77769a15b39974c3329a8

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'test_helper'

class NavigationTest < ActionDispatch::IntegrationTest
  fixtures :all
  include Capybara::DSL
  
  def clean_database
    User.destroy_all
  end
  
  setup do
    clean_database
    @user = User.create!
  end
  
  def assert_image(image)
    assert page.has_css?("img[src$='#{image}']"), page.body.inspect
  end
  
  def find_attachment(attachment)
    File.expand_path("test/fixtures/#{attachment}")
  end
  
  test "fail to upload avatar" do
    visit '/avatar'
    attach_file "avatar_field", find_attachment('invalid.txt')
    click_button 'Upload'
    assert page.has_content?('Invalid image format')
  end

  test "upload avatar" do
    visit '/avatar'
    attach_file "avatar_field", find_attachment('panda.jpg')
    click_button "Upload"
    assert_equal '/avatar/crop', page.current_path
    assert_image('panda.jpg')
  end
  
  test "crop avatar" do
    @user.update_attributes avatar: File.open(find_attachment('panda.jpg'))
    visit '/avatar/crop'
    click_button "Crop"
    assert_equal '/avatar', page.current_path
  end
  
  test "default avatar" do
    visit '/avatar'
    assert_image('avatar_missing.png')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buddies_avatar-0.0.1 test/integration/navigation_test.rb