Sha256: 260322289e4699e1541f50a4bf8e13a0d31b32f3f593d0b74ac8d0a4e64352bd

Contents?: true

Size: 1.83 KB

Versions: 9

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Highrise::Base do
  it { subject.should be_a_kind_of ActiveResource::Base }

  describe "dynamic finder methods" do
    context "without pagination" do
      before do
        @deal_one   = Highrise::Base.new(:id => 1, :name => "A deal")
        @deal_two   = Highrise::Base.new(:id => 2, :name => "A deal")
        @deal_three = Highrise::Base.new(:id => 3, :name => "Another deal")
        Highrise::Base.should_receive(:find).with(:all).and_return([@deal_one, @deal_two, @deal_three])
      end
      it ".find_by_(attribute) finds one" do
        Highrise::Base.find_by_name("A deal").should == @deal_one
      end

      it ".find_all_by_(attribute) finds all" do
        Highrise::Base.find_all_by_name("A deal").should == [@deal_one, @deal_two]
      end
    end

    context "with pagination" do
      before do
        class PaginatedBaseClass < Highrise::Base; include Highrise::Pagination; end
        @john_doe   = PaginatedBaseClass.new(:id => 1, :first_name => "John")
        @john_baker = PaginatedBaseClass.new(:id => 2, :first_name => "John")
        @joe_smith  = PaginatedBaseClass.new(:id => 3, :first_name => "Joe")
        PaginatedBaseClass.should_receive(:find_all_across_pages).and_return([@john_doe, @john_baker, @joe_smith])
      end
      it ".find_by_(attribute) finds one" do
        PaginatedBaseClass.find_by_first_name("John").should == @john_doe
      end

      it ".find_all_by_(attribute) finds all" do
        PaginatedBaseClass.find_all_by_first_name("John").should == [@john_doe, @john_baker]
      end
    end

    it "expects arguments to the finder" do
      expect { Highrise::Base.find_all_by_first_name }.to raise_error(ArgumentError)
    end

    it "falls back to regular method missing" do
      expect { Highrise::Base.any_other_method }.to raise_error(NoMethodError)
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
highrise-3.0.3 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.7 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.6 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.5 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.4 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.3 spec/highrise/base_spec.rb
peterosullivan-highrise-3.0.2 spec/highrise/base_spec.rb
highrise-3.0.1 spec/highrise/base_spec.rb
highrise-3.0.0 spec/highrise/base_spec.rb