Sha256: 0b1e16f2e334849dc60b0bbbac471c4b300edc315dd32803bad3be0f80ec2907

Contents?: true

Size: 1.61 KB

Versions: 11

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'

describe RankedModel::Ranker, 'initialized' do

  subject {
    RankedModel::Ranker.new \
      :overview,
      :column     => :a_sorting_column,
      :scope      => :a_scope,
      :with_same  => :a_column,
      :class_name => 'SomeClass',
      :unless     => :a_method
  }

  its(:name) { should == :overview }
  its(:column) { should == :a_sorting_column }
  its(:scope) { should == :a_scope }
  its(:with_same) { should == :a_column }
  its(:class_name) { should == 'SomeClass' }
  its(:unless) { should == :a_method }
end

describe RankedModel::Ranker, 'unless as Symbol' do
  let(:receiver) { mock('model') }

  subject {
    RankedModel::Ranker.new(:overview, :unless => :a_method).with(receiver)
  }

  context 'returns true' do
    before { receiver.expects(:a_method).once.returns(true) }

    its(:handle_ranking) { should == nil }
  end

  context 'returns false' do
    before { receiver.expects(:a_method).once.returns(false) }

    it {
      subject.expects(:update_index_from_position).once
      subject.expects(:assure_unique_position).once

      subject.handle_ranking
    }
  end
end

describe RankedModel::Ranker, 'unless as Proc' do
  context 'returns true' do
    subject { RankedModel::Ranker.new(:overview, :unless => Proc.new { true }).with(Class.new) }
    its(:handle_ranking) { should == nil }
  end

  context 'returns false' do
    subject { RankedModel::Ranker.new(:overview, :unless => Proc.new { false }).with(Class.new) }

    it {
      subject.expects(:update_index_from_position).once
      subject.expects(:assure_unique_position).once

      subject.handle_ranking
    }
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
ranked-model-0.4.6 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.5 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.4 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.3 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.2 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.1 spec/ranked-model/ranker_spec.rb
ranked-model-rails2-0.4.0 spec/ranked-model/ranker_spec.rb
ranked-model-0.4.0 spec/ranked-model/ranker_spec.rb
ranked-model-0.3 spec/ranked-model/ranker_spec.rb
ranked-model-0.2.1 spec/ranked-model/ranker_spec.rb
ranked-model-0.2.0 spec/ranked-model/ranker_spec.rb