<commit_before>require "spec_helper"

ActiveRecord::Schema.define do
  create_table :refinery_crud_dummies, :force => true do |t|
    t.integer :parent_id
    t.integer :lft
    t.integer :rgt
    t.integer :depth
  end
end

module Refinery
  class CrudDummy < ActiveRecord::Base
    acts_as_nested_set
  end

  class CrudDummyController < ::ApplicationController
    crudify :'refinery/crud_dummy'
  end
end

module Refinery
  describe CrudDummyController, :type => :controller do

    describe "#update_positions" do
      context "with existing dummies" do
        let!(:crud_dummy_one) { Refinery::CrudDummy.create! }
        let!(:crud_dummy_two) { Refinery::CrudDummy.create! }
        let!(:crud_dummy_three) { Refinery::CrudDummy.create! }

        it "orders dummies" do
          post :update_positions, {
            "ul" => {
              "0" => {
                "0" => {"id" => "crud_dummy_#{crud_dummy_three.id}"},
                "1" => {"id" => "crud_dummy_#{crud_dummy_two.id}"},
                "2" => {"id" => "crud_dummy_#{crud_dummy_one.id}"}
              }
            }
          }

          dummy = crud_dummy_three.reload
          expect(dummy.lft).to eq(1)
          expect(dummy.rgt).to eq(2)

          dummy = crud_dummy_two.reload<commit_msg>Add routes for running the CrudDummyController tests<commit_after>require "spec_helper"

ActiveRecord::Schema.define do
  create_table :refinery_crud_dummies, :force => true do |t|
    t.integer :parent_id
    t.integer :lft
    t.integer :rgt
    t.integer :depth
  end
end

module Refinery
  class CrudDummyEngine < ::Rails::Engine
    isolate_namespace Refinery
  end

  CrudDummyEngine.routes.draw do
    resources :crud_dummy do
      post :update_positions, on: :collection
    end
  end

  class CrudDummy < ActiveRecord::Base
    acts_as_nested_set
  end

  class CrudDummyController < ::ApplicationController
    crudify :'refinery/crud_dummy'
  end
end

module Refinery
  describe CrudDummyController, :type => :controller do

    routes{ CrudDummyEngine.routes }

    describe "#update_positions" do
      context "with existing dummies" do
        let!(:crud_dummy_one) { Refinery::CrudDummy.create! }
        let!(:crud_dummy_two) { Refinery::CrudDummy.create! }
        let!(:crud_dummy_three) { Refinery::CrudDummy.create! }

        it "orders dummies" do
          post :update_positions, {
            "ul" => {
              "0" => {
                "0" => {"id" => "crud_dummy_#{crud_dummy_three.id}"},
                "1" => {"id" => "crud_dummy_#{crud_dummy_two.id}"},
                "2" => {"id" => "crud_dummy_#{crud_dummy_one.id}"}
              }
            }
          }

          dummy = crud_dummy_three.reload
          expect(dummy.lft).to eq(1)
          expect(dummy.rgt).to eq(2)

          dummy = crud_dummy_two.reload
{'fraction_non_alphanumeric': 0.11609033168666197, 'fraction_numerical': 0.004234297812279464, 'mean_word_length': 2.5173697270471465, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 23, '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': '5545550', 'n_tokens_mistral': 975, 'n_tokens_neox': 959, 'n_words': 184}