Sha256: 69828da9b4c96eff78a1752d7f6b3a6f0c1a07bfc90a2c882f4095c8e5a0e1f4

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 Bytes

Contents

require 'spec_helper'

describe EdgeRider::OriginClass do

  describe '#origin_class' do

    it "should return the class a scope is based on" do
      Forum.create!(id: 1)
      Forum.create!(id: 2)
      scope = Forum.scoped(conditions: { id: [1] })
      scope.origin_class.should == Forum
      scope.origin_class.collect_ids.should == [1, 2]
    end

    it "should return the class a scope chain is based on" do
      Forum.create!(id: 1, name: 'A')
      Forum.create!(id: 2, name: 'B')
      Forum.create!(id: 3, name: 'C')
      scope_chain = Forum.scoped(conditions: { id: [1, 2] }).scoped(conditions: { name: ['A', 'B'] })
      scope_chain.origin_class.should == Forum
      scope_chain.origin_class.collect_ids.should == [1, 2, 3]
    end

    it "should return itself when called on an ActiveRecord class" do
      Forum.create!(id: 1)
      Forum.create!(id: 2)
      Forum.origin_class.should == Forum
      Forum.origin_class.collect_ids.should == [1, 2]
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
edge_rider-1.1.0 spec/edge_rider/origin_class_spec.rb
edge_rider-1.0.0 spec/edge_rider/origin_class_spec.rb