upload screenshot anonymously, login in, get screenshots assigned

This commit is contained in:
Christoph Haas 2018-08-21 18:25:18 +02:00
parent 820ff2a30b
commit 2746b22c18
4 changed files with 70 additions and 32 deletions

View file

@ -21,43 +21,52 @@ class PackagesControllerTest < ActionController::TestCase
# assert_response :success
# end
test "upload screenshot anonymously then login and get screenshots assigned" do
newest_screenshot1 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# test "upload screenshot anonymously then login and get screenshots assigned" do
# newest_screenshot1 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# Load the upload page
get :upload, params: { name: 'firefox' }
assert_response :success
# # Load the upload page
# get :upload, params: { name: 'firefox' }
# assert_response :success
# Upload a screenshot and except to be redirected afterwards
post :upload_receive, params: { name: 'firefox', file: [ fixture_file_upload('test/fixtures/files/large1.png','image/png') ] }
assert_redirected_to package_path(name: 'firefox')
# # Upload a screenshot and expect to be redirected afterwards
# post :upload_receive, params: { name: 'firefox', file: [ fixture_file_upload('test/fixtures/files/large1.png','image/png') ] }
# assert_redirected_to package_path(name: 'firefox')
# Check that the newest screenshot is not yet approved
newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
assert_not_equal newest_screenshot1, newest_screenshot2
assert_equal newest_screenshot2.approved, false
# # Check that the newest screenshot is not yet approved
# newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# assert_not_equal newest_screenshot1, newest_screenshot2
# assert_equal newest_screenshot2.approved, false
# # Login
# sign_in users(:normal)
# # Get the information about the newest screenshot again
# newest_screenshot2 = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# # Expect the uploaded screenshot to be assigned to this user
# byebug
# assert_equal newest_screenshot2.user, users(:normal)
# # (name: 'firefox')
# # img_count_before = page.find_all('img').count
# # attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
# # click_on 'Start upload'
# (name: 'firefox')
# img_count_before = page.find_all('img').count
# attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
# click_on 'Start upload'
# # # The cookie session must remember this anonymous upload
# # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# # assert_equal session[:uploaded_screenshots].length, [newest_screenshot]
# # The cookie session must remember this anonymous upload
# newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# assert_equal session[:uploaded_screenshots].length, [newest_screenshot]
# # #
# # # sign_in users(:debian)
# #
# # sign_in users(:debian)
# # # # Screenshot is instantly public
# # # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# # # assert_equal newest_screenshot.approved, true
# # # Screenshot is instantly public
# # newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
# # assert_equal newest_screenshot.approved, true
# # # Clean up
# newest_screenshot.destroy
# sign_out users(:normal)
end
# # # # Clean up
# # newest_screenshot.destroy
# # sign_out users(:normal)
# end
end

View file

@ -26,4 +26,4 @@ debian:
sign_in_count: 0
provider: debian-sso
admin: 0
encrypted_password: <%= Devise::Encryptor.digest(User, 'normalsecret') %>
encrypted_password: nil

View file

@ -44,4 +44,31 @@ class BrowserBrowseTest < ActionDispatch::IntegrationTest
sign_out users(:debian)
end
test "upload screenshot anonymously, login in, get screenshots assigned" do
visit upload_path(name: 'firefox')
attach_file 'file[]', Rails.root.join('test/fixtures/files/large1.png')
click_on 'Start upload'
# Screenshot has not yet a user assigned
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
assert_nil newest_screenshot.user
# Login (sign_in is just a stub and would not call the callbacks!)
visit root_path
click_link 'Login'
within 'form' do
fill_in 'email address', with: users(:normal).email
fill_in 'password', with: 'normalsecret'
click_button 'Log in'
end
# Check if screenshot was assigned to the user
newest_screenshot = Package.find_by_name(:firefox).screenshots.order(id: :desc).first
assert_equal newest_screenshot.user, users(:normal)
# Clean up
newest_screenshot.destroy
sign_out users(:debian)
end
end