<commit_before>
# In order to run the user specs the encrypted passwords
# for the '<PASSWORD>' and '<PASSWORD>' users in spec/fixtures/users.yml
# need to be created with a REST_AUTH_SITE_KEY used for testing.
#
# suppress_warnings is a Kernel extension ...
# See: config/initializers/00_core_extensions.rb
#
suppress_warnings { REST_AUTH_SITE_KEY = 'sitekeyforrunningtests' }

# This modification allows stubing helper methods when using integrate views
# the template object isn't ready until the render method is called, so this code
# adds a hook to be run before render is run.

# this commented out because it was breaking cucumber spork runs
# this ApplicationController definition was loaded before the main one so then
# the application controller wasn't extending ActionController::Base
# class ApplicationController
#   def before_render; end
#   def render(options=nil, extra_options={}, &bloc)
#     before_render
#     super
#   end
# 
#   # any stub information is stored in the @mock_proxy variable of the object being stubbed, 
#   # so adding it here prevents the controller @mock_proxy from clobbering the view @mock_proxy 
#   # when rails copies the instance variables from the controller to view.  This copying happens
#   # sometime during the render method (after before_render)
#   @@protected_instance_variables = %w(@mock_proxy)
# end

#
# Factory Generators
#
def generate_default_project_and_jnlps_with_factories
  # if USING_JNLPS
  #   @versioned_jnlp = Factory.create(:maven_jnlp_versioned_jnlp)
  #   @versioned_jnlp_url = @versioned_jnlp.versioned_jnlp_url
  #   @maven_jnlp_family = @versioned_jnlp_url.maven_jnlp_family
  #   @maven_jnlp_server = @maven_jnlp_family.maven_jnlp_server
  #   APP_CONFIG[:default_maven_jnlp][:version] = @maven_jnlp_family.snapshot_version
  #   @maven_jnlp_family.stub!(:newest_snapshot_version).and_return(@maven_jnlp_family.snapshot_version)
  # end
  if USING_JNLPS
    server, family, version = Admin::Project.default_jnlp_info
    @maven_jnlp_server = Factory.next(:default_maven_jnlp_maven_jnlp_server)
    @maven_jnlp_family = @maven_jnlp_server.maven_jnlp_families.find_by_name(family)
    if version == "snapshot"
      @versioned_jnlp_url = @maven_jnlp_family.snapshot_jnlp_url
    else
      @versioned_jnlp_url = @maven_jnlp_family.versioned_jnlp_urls.find_by_version_str(version)
    end
    @versioned_jnlp = @versioned_jnlp_url.versioned_jnlp
  end
  @admin_project = Factory.create(:admin_project)
  Admin::Project.create_or_update_default_project_from_settings_yml
  generate_default_users_with_factories
  generate_default_school_resources_with_factories
end

def generate_default_users_with_factories
  @anon_user =  Factory.next :anonymous_user
  @admin_user = Factory.next :admin_user
end

def generate_default_school_resources_with_factories
  @portal_school = Factory(:portal_school)
  @portal_district = @portal_school.district
  @portal_grade_level = Factory(:portal_grade_level)
  @portal_grade = @portal_grade_level.grade
  @rigse_domain = Factory(:rigse_domain)
end

#
# Mock Generators
#

class ArrayOfVersionedJars < Array
  def find_all_by_os(os)
    find { |i| i.os == os } || []
  end
end

class ArrayOfVersionedJnlpUrls < Array
  def find_by_version_str(version_str)
    find { |i| i.version_str == version_str } || []
  end
end

def generate_jnlps_with_mocks
  project_name, project_url = Admin::Project.default_project_name_url
  server, family, version = Admin::Project.default_jnlp_info

  @mock_maven_jnlp_icon ||= mock_model(MavenJnlp::Icon)

  @mock_maven_jnlp_jar = mock_model(MavenJnlp::Jar,
    :href => 'org/telscenter/sail-otrunk/sail-otrunk.jar',
    :name => 'sail-otrunk',
    :version_str => '0.1.0-20091009.031525-1075',
    :main => false,
    :os => nil)

  @versioned_jars = ArrayOfVersionedJars.new
  @versioned_jars[0] = @mock_maven_jnlp_jar

  @mock_maven_jnlp_property = mock_model(MavenJnlp::Property,
    :name => "maven.jnlp.version",
    :value => "all-otrunk-snapshot-0.1.0-20091013.161730")

  @mock_maven_jnlp_versioned_jnlp = mock_model(MavenJnlp::VersionedJnlp,
    :codebase => "http://jnlp.concord.org/dev",
    :j2se_version => '1.5+',
    :offline_allowed => true,
    :title => 'All OTrunk snapshot',
    :max_heap_size => "128",
    :vendor => 'Concord Consortium',
    :initial_heap_size => "32",
    :jars => @versioned_jars,
    :native_libraries => @versioned_jars,
    :properties => [@mock_maven_jnlp_property])

  @mock_maven_jnlp_versioned_jnlp_url = mock_model(MavenJnlp::VersionedJnlpUrl,
    :versioned_jnlp => @mock_maven_jnlp_versioned_jnlp,
    :version_str => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot-0.1.0-20070420.131610.jnlp')

  @versioned_jnlp_urls = ArrayOfVersionedJnlpUrls.new
  @versioned_jnlp_urls[0] = @mock_maven_jnlp_versioned_jnlp_url

  @mock_maven_jnlp_versioned_jnlp.stub!(:versioned_jnlp_url).and_return(@mock_maven_jnlp_versioned_jnlp_url)

  @mock_maven_jnlp_family = mock_model(MavenJnlp::MavenJnlpFamily,
    :name => family,
    :snapshot_version => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/',
    :update_snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :versioned_jnlp_urls => @versioned_jnlp_urls)

  @mock_maven_jnlp_versioned_jnlp_url.stub!(:maven_jnlp_family).and_return(@mock_maven_jnlp_family)

  @mock_gui_testing_maven_jnlp_family = mock_model(MavenJnlp::MavenJnlpFamily,
    :name => 'gui-testing',
    :snapshot_version => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/',
    :update_snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :snapshot_jnlp_url        => @mock_maven_jnlp_versioned_jnlp_url,
    :versioned_jnlp_urls => @versioned_jnlp_urls)

  @mock_maven_jnlp_server = mock_model( MavenJnlp::MavenJnlpServer,
    :host => server[:host],
    :path => server[:path],
    :name => server[:name],
    :maven_jnlp_family => @mock_maven_jnlp_family)

  @mock_maven_jnlp_family.stub!(:maven_jnlp_server).and_return(@mock_maven_jnlp_server)
end

# Generates a mock project and associated jnlp resources
def generate_default_project_and_jnlps_with_mocks
  project_name, project_url = Admin::Project.default_project_name_url
  server, family, version = Admin::Project.default_jnlp_info
  generate_jnlps_with_mocks
  @mock_project = mock_model(Admin::Project,
    :name                           => project_name,
    :url                            => project_url,
    :home_page_content              => nil,
    :use_student_security_questions => false,
    :jnlp_version_str               => version,
    :snapshot_enabled               => false,
    :enable_default_users           => APP_CONFIG[:enable_default_users],
    :states_and_provinces           => APP_CONFIG[:states_and_provinces],
    :maven_jnlp_server              => @mock_maven_jnlp_server,
    :maven_jnlp_family              => @mock_maven_jnlp_family,
    :using_custom_css?              => false,
    :use_bitmap_snapshots?          => false,
    :allow_adhoc_schools            => false,
    :allow_adhoc_schools?           => false,
    :require_user_consent?          => false,
    :allow_default_class            => false,
    :allow_default_class?           => false
  )

  MavenJnlp::Jar.stub!(:find_all_by_os).and_return(@versioned_jars)
  MavenJnlp::MavenJnlpFamily.stub!(:find_by_name).with("gui-testing").and_return(@mock_gui_testing_maven_jnlp_family)
  Admin::Project.stub!(:default_project).and_return(@mock_project)
  mock_anonymous_user
  mock_admin_user
  mock_researcher_user
  
  # we have to do this because we can't easily stub helper methods so instead we are stubbing one level lower
  mock_jnlp_adapter = JnlpAdaptor.new(@mock_project)
  JnlpAdaptor.stub(:new).and_return(mock_jnlp_adapter)
  @mock_project
end

def generate_portal_resources_with_mocks
  @mock_school = mock_model(Portal::School)
  @mock_grade = mock_model(Portal::Grade)
  @mock_grade_level = mock_model(Portal::GradeLevel)
  @mock_external_user = mock_model(ExternalUser)
  # @mock_grade ||= mock_model(Portal::Grade, stubs)
  # @mock_grade_level ||= mock_model(Portal::GradeLevel, stubs)
end<commit_msg>add jnlp_cdn_hostname to the mocks<commit_after>
# In order to run the user specs the encrypted passwords
# for the 'quentin' and 'aaron' users in spec/fixtures/users.yml
# need to be created with a REST_AUTH_SITE_KEY used for testing.
#
# suppress_warnings is a Kernel extension ...
# See: config/initializers/00_core_extensions.rb
#
suppress_warnings { REST_AUTH_SITE_KEY = 'sitekeyforrunningtests' }

# This modification allows stubing helper methods when using integrate views
# the template object isn't ready until the render method is called, so this code
# adds a hook to be run before render is run.

# this commented out because it was breaking cucumber spork runs
# this ApplicationController definition was loaded before the main one so then
# the application controller wasn't extending ActionController::Base
# class ApplicationController
#   def before_render; end
#   def render(options=nil, extra_options={}, &bloc)
#     before_render
#     super
#   end
# 
#   # any stub information is stored in the @mock_proxy variable of the object being stubbed, 
#   # so adding it here prevents the controller @mock_proxy from clobbering the view @mock_proxy 
#   # when rails copies the instance variables from the controller to view.  This copying happens
#   # sometime during the render method (after before_render)
#   @@protected_instance_variables = %w(@mock_proxy)
# end

#
# Factory Generators
#
def generate_default_project_and_jnlps_with_factories
  # if USING_JNLPS
  #   @versioned_jnlp = Factory.create(:maven_jnlp_versioned_jnlp)
  #   @versioned_jnlp_url = @versioned_jnlp.versioned_jnlp_url
  #   @maven_jnlp_family = @versioned_jnlp_url.maven_jnlp_family
  #   @maven_jnlp_server = @maven_jnlp_family.maven_jnlp_server
  #   APP_CONFIG[:default_maven_jnlp][:version] = @maven_jnlp_family.snapshot_version
  #   @maven_jnlp_family.stub!(:newest_snapshot_version).and_return(@maven_jnlp_family.snapshot_version)
  # end
  if USING_JNLPS
    server, family, version = Admin::Project.default_jnlp_info
    @maven_jnlp_server = Factory.next(:default_maven_jnlp_maven_jnlp_server)
    @maven_jnlp_family = @maven_jnlp_server.maven_jnlp_families.find_by_name(family)
    if version == "snapshot"
      @versioned_jnlp_url = @maven_jnlp_family.snapshot_jnlp_url
    else
      @versioned_jnlp_url = @maven_jnlp_family.versioned_jnlp_urls.find_by_version_str(version)
    end
    @versioned_jnlp = @versioned_jnlp_url.versioned_jnlp
  end
  @admin_project = Factory.create(:admin_project)
  Admin::Project.create_or_update_default_project_from_settings_yml
  generate_default_users_with_factories
  generate_default_school_resources_with_factories
end

def generate_default_users_with_factories
  @anon_user =  Factory.next :anonymous_user
  @admin_user = Factory.next :admin_user
end

def generate_default_school_resources_with_factories
  @portal_school = Factory(:portal_school)
  @portal_district = @portal_school.district
  @portal_grade_level = Factory(:portal_grade_level)
  @portal_grade = @portal_grade_level.grade
  @rigse_domain = Factory(:rigse_domain)
end

#
# Mock Generators
#

class ArrayOfVersionedJars < Array
  def find_all_by_os(os)
    find { |i| i.os == os } || []
  end
end

class ArrayOfVersionedJnlpUrls < Array
  def find_by_version_str(version_str)
    find { |i| i.version_str == version_str } || []
  end
end

def generate_jnlps_with_mocks
  project_name, project_url = Admin::Project.default_project_name_url
  server, family, version = Admin::Project.default_jnlp_info

  @mock_maven_jnlp_icon ||= mock_model(MavenJnlp::Icon)

  @mock_maven_jnlp_jar = mock_model(MavenJnlp::Jar,
    :href => 'org/telscenter/sail-otrunk/sail-otrunk.jar',
    :name => 'sail-otrunk',
    :version_str => '0.1.0-20091009.031525-1075',
    :main => false,
    :os => nil)

  @versioned_jars = ArrayOfVersionedJars.new
  @versioned_jars[0] = @mock_maven_jnlp_jar

  @mock_maven_jnlp_property = mock_model(MavenJnlp::Property,
    :name => "maven.jnlp.version",
    :value => "all-otrunk-snapshot-0.1.0-20091013.161730")

  @mock_maven_jnlp_versioned_jnlp = mock_model(MavenJnlp::VersionedJnlp,
    :codebase => "http://jnlp.concord.org/dev",
    :j2se_version => '1.5+',
    :offline_allowed => true,
    :title => 'All OTrunk snapshot',
    :max_heap_size => "128",
    :vendor => 'Concord Consortium',
    :initial_heap_size => "32",
    :jars => @versioned_jars,
    :native_libraries => @versioned_jars,
    :properties => [@mock_maven_jnlp_property])

  @mock_maven_jnlp_versioned_jnlp_url = mock_model(MavenJnlp::VersionedJnlpUrl,
    :versioned_jnlp => @mock_maven_jnlp_versioned_jnlp,
    :version_str => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/all-otrunk-snapshot-0.1.0-20070420.131610.jnlp')

  @versioned_jnlp_urls = ArrayOfVersionedJnlpUrls.new
  @versioned_jnlp_urls[0] = @mock_maven_jnlp_versioned_jnlp_url

  @mock_maven_jnlp_versioned_jnlp.stub!(:versioned_jnlp_url).and_return(@mock_maven_jnlp_versioned_jnlp_url)

  @mock_maven_jnlp_family = mock_model(MavenJnlp::MavenJnlpFamily,
    :name => family,
    :snapshot_version => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/',
    :update_snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :versioned_jnlp_urls => @versioned_jnlp_urls)

  @mock_maven_jnlp_versioned_jnlp_url.stub!(:maven_jnlp_family).and_return(@mock_maven_jnlp_family)

  @mock_gui_testing_maven_jnlp_family = mock_model(MavenJnlp::MavenJnlpFamily,
    :name => 'gui-testing',
    :snapshot_version => version,
    :url => 'http://jnlp.concord.org/dev/org/concord/maven-jnlp/all-otrunk-snapshot/',
    :update_snapshot_jnlp_url => @mock_maven_jnlp_versioned_jnlp_url,
    :snapshot_jnlp_url        => @mock_maven_jnlp_versioned_jnlp_url,
    :versioned_jnlp_urls => @versioned_jnlp_urls)

  @mock_maven_jnlp_server = mock_model( MavenJnlp::MavenJnlpServer,
    :host => server[:host],
    :path => server[:path],
    :name => server[:name],
    :maven_jnlp_family => @mock_maven_jnlp_family)

  @mock_maven_jnlp_family.stub!(:maven_jnlp_server).and_return(@mock_maven_jnlp_server)
end

# Generates a mock project and associated jnlp resources
def generate_default_project_and_jnlps_with_mocks
  project_name, project_url = Admin::Project.default_project_name_url
  server, family, version = Admin::Project.default_jnlp_info
  generate_jnlps_with_mocks
  @mock_project = mock_model(Admin::Project,
    :name                           => project_name,
    :url                            => project_url,
    :home_page_content              => nil,
    :use_student_security_questions => false,
    :jnlp_version_str               => version,
    :snapshot_enabled               => false,
    :enable_default_users           => APP_CONFIG[:enable_default_users],
    :states_and_provinces           => APP_CONFIG[:states_and_provinces],
    :maven_jnlp_server              => @mock_maven_jnlp_server,
    :maven_jnlp_family              => @mock_maven_jnlp_family,
    :using_custom_css?              => false,
    :use_bitmap_snapshots?          => false,
    :allow_adhoc_schools            => false,
    :allow_adhoc_schools?           => false,
    :require_user_consent?          => false,
    :allow_default_class            => false,
    :allow_default_class?           => false,
    :jnlp_cdn_hostname              => ''
  )

  MavenJnlp::Jar.stub!(:find_all_by_os).and_return(@versioned_jars)
  MavenJnlp::MavenJnlpFamily.stub!(:find_by_name).with("gui-testing").and_return(@mock_gui_testing_maven_jnlp_family)
  Admin::Project.stub!(:default_project).and_return(@mock_project)
  mock_anonymous_user
  mock_admin_user
  mock_researcher_user
  
  # we have to do this because we can't easily stub helper methods so instead we are stubbing one level lower
  mock_jnlp_adapter = JnlpAdaptor.new(@mock_project)
  JnlpAdaptor.stub(:new).and_return(mock_jnlp_adapter)
  @mock_project
end

def generate_portal_resources_with_mocks
  @mock_school = mock_model(Portal::School)
  @mock_grade = mock_model(Portal::Grade)
  @mock_grade_level = mock_model(Portal::GradeLevel)
  @mock_external_user = mock_model(ExternalUser)
  # @mock_grade ||= mock_model(Portal::Grade, stubs)
  # @mock_grade_level ||= mock_model(Portal::GradeLevel, stubs)
end
{'fraction_non_alphanumeric': 0.09871810231220798, 'fraction_numerical': 0.008026835988978076, 'mean_word_length': 4.743034055727554, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 112, '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': '1190993', 'n_tokens_mistral': 6296, 'n_tokens_neox': 6119, 'n_words': 944}