Skip to content

Commit

Permalink
Make institution optional in the user factory
Browse files Browse the repository at this point in the history
Total institutions created went from 2703 to 157

[TEST PROF INFO] Factories usage

 Total: 11343
 Total top-level: 4276
 Total time: 02:41.449 (out of 04:37.450)
 Total uniq factories: 37

   total   top-level     total time      time per call      top-level time               name

    1535          62       10.4243s            0.0068s             0.4916s              judge
    1473         109       25.6807s            0.0174s             9.1480s         repository
    1458         435        7.9550s            0.0055s             2.2409s               user
    1293          11        2.5787s            0.0020s             0.0200s programming_language
    1283         262       52.8969s            0.0412s             9.2936s           exercise
     806         806       53.3182s            0.0662s            53.3182s         submission
     592         155       53.8062s            0.0909s            12.5099s correct_submission
     543         325       14.9243s            0.0275s            12.7668s             course
     496         496        2.2443s            0.0045s             2.2443s            student
     384         269       40.3077s            0.1050s            26.7965s             series
     381         381        1.6770s            0.0044s             1.6770s              staff
     280         280        1.2987s            0.0046s             1.2987s               zeus
     157          54        0.3056s            0.0019s             0.1023s        institution
      97          97        0.8352s            0.0086s             0.8352s           question
      90          90        0.9235s            0.0103s             0.9235s         score_item
      60          60       21.0340s            0.3506s            21.0340s         evaluation
      59          59        0.6514s            0.0110s             0.6514s              score
      48          48        3.3033s            0.0688s             3.3033s   wrong_submission
      42          15        0.5570s            0.0133s             0.2356s       content_page
      33          33        0.6919s            0.0210s             0.6919s activity_read_state
      33          33        0.0729s            0.0022s             0.0729s           identity
      32          32        0.1560s            0.0049s             0.1560s           provider
      26          26        0.1411s            0.0054s             0.1411s         annotation
      18          18        0.1241s            0.0069s             0.1241s       lti_provider
      16          16        0.0876s            0.0055s             0.0876s smartschool_provider
      16          16        0.0872s            0.0054s             0.0872s office365_provider
      15          15        0.1081s            0.0072s             0.1081s          api_token
      15          15        0.0838s            0.0056s             0.0838s    gsuite_provider
      13          13        0.0808s            0.0062s             0.0808s      saml_provider
      11          11        0.0174s            0.0016s             0.0174s              label
       9           9        0.1696s            0.0188s             0.1696s     rights_request
       7           7        0.5408s            0.0773s             0.5408s  course_submission
       6           6        0.0242s            0.0040s             0.0242s     temporary_user
       5           1        0.0328s            0.0066s             0.0060s             export
       5           5        0.1128s            0.0226s             0.1128s evaluation_exercise
       4           4        0.0424s            0.0106s             0.0424s       notification
       2           2        0.0126s            0.0063s             0.0126s    activity_status
  • Loading branch information
bmesuere committed Aug 31, 2021
1 parent 59a0097 commit 1c05c89
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions test/controllers/courses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,11 @@ def with_users_signed_in(users)
c1 = create :course, series_count: 1, activities_per_series: 1, submissions_per_exercise: 1
c2 = create :course, series_count: 1, activities_per_series: 1, submissions_per_exercise: 1
user = @subscribed.first
c1.update(institution: user.institution)
c2.update(institution: user.institution)
institution = create :institution
user.institution = institution
user.save
c1.update(institution: institution)
c2.update(institution: institution)
sign_in user

# all courses
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/rights_requests_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RightsRequestsControllerTest < ActionDispatch::IntegrationTest
crud_helpers RightsRequest, attrs: %i[context institution_name]

setup do
sign_in create(:student)
sign_in create(:student, :with_institution)
end

test_crud_actions only: %i[new create], except: %i[create_redirect]
Expand Down Expand Up @@ -55,7 +55,7 @@ class RightsRequestsControllerTest < ActionDispatch::IntegrationTest
end

test 'approval should update institution name' do
sign_in create(:zeus)
sign_in create(:zeus, :with_institution)
req = create(:rights_request)
req.update(institution_name: "#{req.user.institution.name}-different")
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
Expand Down
2 changes: 1 addition & 1 deletion test/factories/exercises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

submission_count { 0 }
submission_users do
create_list :user, 5 if submission_count.positive?
create_list :user, 3 if submission_count.positive?
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/factories/rights_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
FactoryBot.define do
factory :rights_request do
user
association :user, :with_institution
institution_name { Faker::University.unique.name.gsub(/[^[:ascii:]]/, '') }
context { Faker::Lorem.paragraph(sentence_count: 25) }
end
Expand Down
5 changes: 4 additions & 1 deletion test/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
username { Faker::Internet.unique.user_name(specifier: 5..32) }
email { "#{first_name}.#{last_name}.#{username}@ugent.be".downcase.gsub(' ', '_') }
permission { :student }
institution

trait :with_institution do
association :institution
end
end

factory :zeus, parent: :user do
Expand Down
6 changes: 3 additions & 3 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UserTest < ActiveSupport::TestCase
end

test 'user with username should not have a token' do
user = create :user
user = create :user, :with_institution
assert_nil user.token
end

Expand Down Expand Up @@ -264,8 +264,8 @@ def oauth_hash_for(user)
assert_not_equal username, user.username
end

test 'institution name should return a name that is not equal to actual institutio name of the user when in demo mode' do
user = create :user
test 'institution name should return a name that is not equal to actual institution name of the user when in demo mode' do
user = create :user, :with_institution
institution_name = user.institution&.name
Current.any_instance.stubs(:demo_mode).returns(true)
assert_not_equal institution_name, user.institution&.name
Expand Down

0 comments on commit 1c05c89

Please sign in to comment.