<commit_before>require 'spec_helper'

describe 'DataMapper::Is::List' do

  supported_by :in_memory, :yaml, :sqlite, :postgres, :mysql, :oracle, :sqlserver do

    before do
      DataMapper::Model.descendants.each { |model| model.destroy! }

      @u1 = User.create(:name => 'Johnny')
      Todo.create(:user => @u1, :title => 'Write down what is needed in a list-plugin')
      Todo.create(:user => @u1, :title => 'Complete a temporary version of is-list')
      Todo.create(:user => @u1, :title => 'Squash any reported bugs')
      Todo.create(:user => @u1, :title => 'Make public and await public scrutiny')
      Todo.create(:user => @u1, :title => 'Rinse and repeat')
      @u2 = User.create(:name => 'Freddy')
      Todo.create(:user => @u2, :title => 'Eat tasty cupcake')
      Todo.create(:user => @u2, :title => 'Procrastinate on paid work')
      Todo.create(:user => @u2, :title => 'Go to sleep')
    end

    describe "Class Methods" do

      describe "#repair_list" do

        it "should repair a scoped list" do
          DataMapper.repository(:default) do |repos|
            items = Todo.all(:user => @u1, :order => [:position])
            items.each{ |item| item.update(:position => [4,2,8,32,16][item.id - 1]) }
            todo_list.should == [ [2, 2], [1, 4], [3, 8], [5, 16], [4, 32] ]

            Todo.repair_list(:user_id => @u1.id).should be(true)
            todo_list.should == [ [2, 1], [1, 2], [3, 3], [5, 4], [4, 5] ]
          end
        end

        it "should repair unscoped lists" do<commit_msg>Revert "Removed unecessary auto-migration"<commit_after>require 'spec_helper'

describe 'DataMapper::Is::List' do

  supported_by :in_memory, :yaml, :sqlite, :postgres, :mysql, :oracle, :sqlserver do

    before do
      DataMapper.auto_migrate!
      DataMapper::Model.descendants.each { |model| model.destroy! }

      @u1 = User.create(:name => 'Johnny')
      Todo.create(:user => @u1, :title => 'Write down what is needed in a list-plugin')
      Todo.create(:user => @u1, :title => 'Complete a temporary version of is-list')
      Todo.create(:user => @u1, :title => 'Squash any reported bugs')
      Todo.create(:user => @u1, :title => 'Make public and await public scrutiny')
      Todo.create(:user => @u1, :title => 'Rinse and repeat')
      @u2 = User.create(:name => 'Freddy')
      Todo.create(:user => @u2, :title => 'Eat tasty cupcake')
      Todo.create(:user => @u2, :title => 'Procrastinate on paid work')
      Todo.create(:user => @u2, :title => 'Go to sleep')
    end

    describe "Class Methods" do

      describe "#repair_list" do

        it "should repair a scoped list" do
          DataMapper.repository(:default) do |repos|
            items = Todo.all(:user => @u1, :order => [:position])
            items.each{ |item| item.update(:position => [4,2,8,32,16][item.id - 1]) }
            todo_list.should == [ [2, 2], [1, 4], [3, 8], [5, 16], [4, 32] ]

            Todo.repair_list(:user_id => @u1.id).should be(true)
            todo_list.should == [ [2, 1], [1, 2], [3, 3], [5, 4], [4, 5] ]
          end
        end

        it "should repair unscoped lists" do
{'fraction_non_alphanumeric': 0.17412140575079874, 'fraction_numerical': 0.0268370607028754, 'mean_word_length': 2.795151515151515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1183356', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1066, 'n_words': 297}