Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
tests for ApiQueryProvider::Base.extend
Browse files Browse the repository at this point in the history
  • Loading branch information
femaref committed Mar 21, 2012
1 parent 5c79c90 commit 80b9cac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/api-query-provider/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def extend
raise "not all needed values are present"
end

request = self.class
request = self.class.where

self.class.required_symbols.each do |sym|
request = request.where(sym => self.send(self.class.shadow(sym).to_sym))
Expand Down
17 changes: 17 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'lib/auto_generate_test_class'
require 'lib/parameterless_auto_generate_test_class'

describe ApiQueryProvider::Base do
it "should raise an exception being instanciated directly" do
Expand All @@ -11,4 +12,20 @@

ApiQueryProvider::Base.instance_methods.include?(:foo).should == false
end

describe "extend" do
it "should raise on missing symbol" do
real = AutoGenerateTestClass.new({})

lambda { real.extend }.should raise_error(Exception, "not all needed values are present")
end

it "should allow parameterless api calls" do
HTTParty.stub(:get) { double(:body => %q({ "id" : "1", "name": "test" })) }

real = ParameterlessAutoGenerateTestClass.new({})

lambda { real.extend }.should_not raise_error
end
end
end
6 changes: 6 additions & 0 deletions spec/lib/parameterless_auto_generate_test_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ParameterlessAutoGenerateTestClass < ApiQueryProvider::Base

self.api_url = "http://example.com"
self.api_path = "/foo/id"
self.autogenerate = true
end

0 comments on commit 80b9cac

Please sign in to comment.