debshots/test/controllers/packages_controller_test.rb
2021-03-02 00:51:24 +01:00

74 lines
2.5 KiB
Ruby

require 'test_helper'
class PackagesControllerTest < ActionController::TestCase
test "should get index and contain dummy package-4" do
get :grid
assert_response :success
assert_select 'div', 'package-4'
end
test "should get list view with_screenshots and find Firefox" do
get :list, params: { show: 'with' }
assert_response :success
assert_select 'div', 'A program to browse web sites.'
end
# test "should get without_screenshots" do
# get :without_screenshots
# assert_response :success
# end
# test "should get moderate" do
# get :moderate
# 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
# # Load the upload page
# get :upload, params: { name: 'firefox' }
# assert_response :success
# # 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
# # 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'
# # # 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)
# # # # 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
end