Sha256: 9e89e15824daeb7cc321da4ca6247913e8bb5ffe21ffd3768e17cd44d8338748

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

require './spec/spec_helper'

class MyResource < Base
  extend Finders
  self.element_name = "my_resource"
end

describe Finders, "Finders model" do

  before(:each) do
    stub_auth_request
  end

  it "should get first result" do
    stub_api_get("/my_resource", 'finders.json')
    resource = MyResource.first
    resource.Id.should eq(1)
  end

  it "should get last result" do
    stub_api_get("/my_resource", 'finders.json')
    resource = MyResource.last
    resource.Id.should eq(2)
  end

  it "should find one result" do
    stub_api_get("/my_resource", 'finders.json', {
      :_limit => 1,
      :_filter => "Something Eq 'dude'"
    })
    resource = MyResource.find_one(:_filter => "Something Eq 'dude'")
    resource.Id.should eq(1)
  end

  describe "find" do

    it "should throw an error if no argument is passed" do
      stub_api_get("/my_resource/", 'finders.json')
      lambda {
        MyResource.find()
      }.should raise_error(ArgumentError)
    end

    it "should throw an error when the first argument is nil" do
      stub_api_get("/my_resource/", 'finders.json', {:_limit => 1})
      lambda {
        MyResource.find(nil, {:_limit => 1})
      }.should raise_error(ArgumentError)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spark_api-1.4.2 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.4.1 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.4.0 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.28 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.27 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.26 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.25 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.24 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.3.23 spec/unit/spark_api/models/finders_spec.rb