<commit_before>require 'test_helper'

class BcRequestsControllerTest < ActionController::TestCase

	ASSERT_ACCESS_OPTIONS = { 
		:model => 'BcRequest',
		:actions => [:new,:edit,:update,:destroy],		#,:index], index is a bit tricky so done manually
		:attributes_for_create => :factory_attributes,
		:method_for_create => :create_bc_request
	}

	def factory_attributes(options={})
		Factory.attributes_for(:bc_request)
	end

	assert_access_with_login({    :logins => site_editors })
	assert_no_access_with_login({ :logins => non_site_editors })
	assert_no_access_without_login
	assert_access_with_https
	assert_no_access_with_http

	site_editors.each do |cu|

		test "should get new with existing bc_requests and #{cu} login" do
			login_as send(cu)
			case_subject = create_case_control_subject
			case_subject.bc_requests.create
			get :new
			assert_nil assigns(:subject)
			assert_not_nil assigns(:active_bc_requests)
			assert_not_nil assigns(:waitlist_bc_requests)
			assert_nil flash[:error]
			assert_response :success
			assert_template 'new'
		end

		test "should NOT add case subject to bc_requests without patid and #{cu} login" do
			login_as send(cu)
			assert_difference('BcRequest.count',0) {
				post :create
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		test "should NOT add case subject to bc_requests without matching patid and #{cu} login" do
			login_as send(cu)
			assert_difference('BcRequest.count',0) {
				post :create, :patid => 'donotmatchpatid'
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		test "should NOT add case subject to bc_requests with multiple matching patid and #{cu} login" do
			login_as send(cu)
			create_case_control_subject
			create_case_control_subject
			Subject.any_instance.stubs(:search).returns(Subject.all)
			assert_difference('BcRequest.count',0) {
				post :create, :patid => 'irrelevant_for_this_test'
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		#	non-case is effectively not a valid patid
		test "should NOT add case subject to bc_requests with non-case subject and #{cu} login" do
			login_as send(cu)<commit_msg>Added test for multiple matching patids (should never really happen).<commit_after>require 'test_helper'

class BcRequestsControllerTest < ActionController::TestCase

	ASSERT_ACCESS_OPTIONS = { 
		:model => 'BcRequest',
		:actions => [:new,:edit,:update,:destroy],		#,:index], index is a bit tricky so done manually
		:attributes_for_create => :factory_attributes,
		:method_for_create => :create_bc_request
	}

	def factory_attributes(options={})
		Factory.attributes_for(:bc_request)
	end

	assert_access_with_login({    :logins => site_editors })
	assert_no_access_with_login({ :logins => non_site_editors })
	assert_no_access_without_login
	assert_access_with_https
	assert_no_access_with_http

	site_editors.each do |cu|

		test "should get new with existing bc_requests and #{cu} login" do
			login_as send(cu)
			case_subject = create_case_control_subject
			case_subject.bc_requests.create
			get :new
			assert_nil assigns(:subject)
			assert_not_nil assigns(:active_bc_requests)
			assert_not_nil assigns(:waitlist_bc_requests)
			assert_nil flash[:error]
			assert_response :success
			assert_template 'new'
		end

		test "should NOT add case subject to bc_requests without patid and #{cu} login" do
			login_as send(cu)
			assert_difference('BcRequest.count',0) {
				post :create
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		test "should NOT add case subject to bc_requests without matching patid and #{cu} login" do
			login_as send(cu)
			assert_difference('BcRequest.count',0) {
				post :create, :patid => 'donotmatchpatid'
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		#	create multiple subjects and stub search so all returned mimicing multiple matches
		test "should NOT add case subject to bc_requests with multiple matching patid and #{cu} login" do
			login_as send(cu)
			create_case_control_subject
			create_case_control_subject
			Subject.any_instance.stubs(:search).returns(Subject.all)
			assert_difference('BcRequest.count',0) {
				post :create, :patid => 'irrelevant_for_this_test'
			}
			assert_nil assigns(:subject)
			assert_not_nil flash[:error]
			assert_redirected_to new_bc_request_path
		end

		#	non-case is effectively not a valid patid
		test "should NOT add case subject to bc_requests with non-case subject and #{cu} login" do
			login_as send(cu)
{'fraction_non_alphanumeric': 0.082122552116235, 'fraction_numerical': 0.0012634238787113076, 'mean_word_length': 5.058673469387755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '520796', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1510, 'n_words': 384}