Sha256: ee76f8fe755d6f2322573493beda67f7caf2551ddfdd47f0927de7febfae3cd2

Contents?: true

Size: 1.21 KB

Versions: 12

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
    expect(resource.Id).to eq(1)
  end

  it "should get last result" do
    stub_api_get("/my_resource", 'finders.json')
    resource = MyResource.last
    expect(resource.Id).to 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'")
    expect(resource.Id).to eq(1)
  end

  describe "find" do

    it "should throw an error if no argument is passed" do
      stub_api_get("/my_resource/", 'finders.json')
      expect {
        MyResource.find()
      }.to 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})
      expect {
        MyResource.find(nil, {:_limit => 1})
      }.to raise_error(ArgumentError)
    end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spark_api-1.6.3 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.6.2 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.6.1 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.7 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.6.0 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.6 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.5 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.4 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.3 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.2 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.1 spec/unit/spark_api/models/finders_spec.rb
spark_api-1.5.0 spec/unit/spark_api/models/finders_spec.rb