require 'test_helper' class NavigationTest < ActionDispatch::IntegrationTest 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