Sha256: 7c6d983230682c3939faf7540ee118120cbad01e707d5a3a05799d834be0bd3a

Contents?: true

Size: 1.26 KB

Versions: 22

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe RailsCoreExtensions::PositionInitializer, 'When repositioning' do
  class Child < ActiveRecord::Base; end

  before do
    connect_to_sqlite
    Child.create!(parent_id: 1, name: 'A child')
  end

  after do
    child.destroy
  end

  subject { RailsCoreExtensions::PositionInitializer.new(Child, :parent_id) }
  let(:child) { Child.find_by_name('A child') }

  context 'when not initialized' do
    specify { expect(child.position).to be_nil }
  end

  context 'when positioned' do
    before { subject.positionalize }

    specify { expect(child.position).to eq 1 }

    context 'when additional models are created' do
      let(:child2) { Child.find_by_name('Another child') }
      let(:child3) { Child.find_by_name('Third child')   }

      before do
        Child.create!(parent_id: 2, name: 'Another child')
        Child.create!(parent_id: 1, name: 'Third child')
      end

      after do
        child2.destroy
        child3.destroy
      end

      context 'when re-positioned' do
        before { subject.positionalize }

        it 'should reposition in groups by linked parent' do
          expect(child.position).to eq 2
          expect(child3.position).to eq 1
          expect(child2.position).to eq 1
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rails_core_extensions-0.15.0 spec/position_initializer_spec.rb
rails_core_extensions-0.14.0 spec/position_initializer_spec.rb
rails_core_extensions-0.13.2 spec/position_initializer_spec.rb
rails_core_extensions-0.13.1 spec/position_initializer_spec.rb
rails_core_extensions-0.13.0 spec/position_initializer_spec.rb
rails_core_extensions-0.12.0 spec/position_initializer_spec.rb
rails_core_extensions-0.11.3 spec/position_initializer_spec.rb
rails_core_extensions-0.11.2 spec/position_initializer_spec.rb
rails_core_extensions-0.11.1 spec/position_initializer_spec.rb
rails_core_extensions-0.11.0.beta.11 spec/position_initializer_spec.rb
rails_core_extensions-0.10.0 spec/position_initializer_spec.rb
rails_core_extensions-0.9.0 spec/position_initializer_spec.rb
rails_core_extensions-0.8.0 spec/position_initializer_spec.rb
rails_core_extensions-0.7.1 spec/position_initializer_spec.rb
rails_core_extensions-0.7.0 spec/position_initializer_spec.rb
rails_core_extensions-0.6.1 spec/position_initializer_spec.rb
rails_core_extensions-0.6.0 spec/position_initializer_spec.rb
rails_core_extensions-0.4.0 spec/position_initializer_spec.rb
rails_core_extensions-0.3.0 spec/position_initializer_spec.rb
rails_core_extensions-0.2.0 spec/position_initializer_spec.rb