<commit_before>require 'rails_helper'

RSpec.describe Course::Achievement, type: :model do
  it { is_expected.to have_many :conditions }
  it { is_expected.to validate_presence_of :title }
  it { is_expected.to belong_to(:creator).class_name User.name }
  it { is_expected.to belong_to(:course).inverse_of :achievements }

  let!(:instance) { create(:instance) }
  with_tenant(:instance) do
    describe '.default_scope' do
      before { Course::Achievement.delete_all }

      let!(:achievement_1st) { create(:course_achievement, weight: 1) }
      let!(:achievement_2nd) { create(:course_achievement, weight: 5) }
      let!(:achievement_3rd) { create(:course_achievement, weight: 3) }

      it 'orders by ascending weight' do
        expect(Course::Achievement.all).to eq [achievement_1st, achievement_3rd, achievement_2nd]
      end
    end
  end
end<commit_msg>Assert proper ordering instead of deleting everything. This is because we have more achievements and not just those that the test created.<commit_after>require 'rails_helper'

RSpec.describe Course::Achievement, type: :model do
  it { is_expected.to have_many :conditions }
  it { is_expected.to validate_presence_of :title }
  it { is_expected.to belong_to(:creator).class_name User.name }
  it { is_expected.to belong_to(:course).inverse_of :achievements }

  let!(:instance) { create(:instance) }
  with_tenant(:instance) do
    describe '.default_scope' do
      it 'orders by ascending weight' do
        weights = Course::Achievement.all.map(&:weight)
        prev_weights = [0] + weights[0..-2]
        zipped_weights = prev_weights.zip(weights)
        greater_than_previous = zipped_weights.map { |(a, b)| a <= b }
        expect(greater_than_previous.all?).to be_truthy
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10816901408450705, 'fraction_numerical': 0.0067605633802816905, 'mean_word_length': 4.103448275862069, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '5885547', 'n_tokens_mistral': 582, 'n_tokens_neox': 564, 'n_words': 134}