Permalink
Browse files

Fixes required to work with ActiveResouce > 3.0.0

* explicitly add active_support to the dependecies list
* update Gemfile.lock via bundler
* fix broken code inside of ReactiveResource::Base
* fix broken unit tests
  • Loading branch information...
1 parent 8160cd1 commit 770635336d1939c148f08ead84c1b453e2246097 @flavio flavio committed Jan 13, 2012
Showing with 52 additions and 36 deletions.
  1. +15 −12 Gemfile.lock
  2. +3 −2 lib/reactive_resource/base.rb
  3. +3 −2 reactive_resource.gemspec
  4. +31 −20 test/unit/base_test.rb
View
@@ -1,24 +1,27 @@
PATH
remote: .
specs:
- reactive_resource (0.6.0)
- activeresource (>= 2.3.10)
+ reactive_resource (0.6.1)
+ activeresource (>= 3.1.0)
+ activesupport (>= 3.1.0)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.6)
- activesupport (= 3.0.6)
- builder (~> 2.1.2)
- i18n (~> 0.5.0)
- activeresource (3.0.6)
- activemodel (= 3.0.6)
- activesupport (= 3.0.6)
- activesupport (3.0.6)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
addressable (2.2.2)
- builder (2.1.2)
+ builder (3.0.0)
crack (0.1.8)
- i18n (0.5.0)
+ i18n (0.6.0)
+ multi_json (1.0.4)
rake (0.8.7)
shoulda (2.11.3)
webmock (1.6.2)
@@ -1,4 +1,5 @@
require 'active_resource'
+require 'active_support/all'
module ReactiveResource
@@ -88,7 +89,7 @@ def self.element_path(id, prefix_options = {}, query_options = nil)
# keys corresponding to the belongs_to associations (since they'll
# be in the URL anyway), so we'll try to inject them based on the
# attributes of the object we just used.
- def load(attributes)
+ def load(attributes, remove_root=false)
attributes = attributes.stringify_keys
self.class.belongs_to_with_parents.each do |belongs_to_param|
attributes["#{belongs_to_param}_id"] ||= prefix_options["#{belongs_to_param}_id".intern]
@@ -98,7 +99,7 @@ def load(attributes)
# even if we aren't actually using the association.
@attributes["#{belongs_to_param}_id"] = attributes["#{belongs_to_param}_id"]
end
- super(attributes)
+ super(attributes, remove_root)
end
# Add all of the belongs_to attributes as prefix parameters. This is
@@ -14,10 +14,11 @@ Gem::Specification.new do |s|
s.rubyforge_project = "reactive_resource"
- s.add_dependency "activeresource", '>= 2.3.10'
+ s.add_dependency "activeresource", '>= 3.1.0'
+ s.add_dependency "activesupport", '>= 3.1.0'
s.add_development_dependency "shoulda", '~> 2.11.3'
s.add_development_dependency "webmock", '~> 1.6.1'
-
+
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
View
@@ -19,28 +19,30 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
assert_equal ReactiveResource::Lawyer, @object.class.associations.detect {|assoc| assoc.attribute == :lawyer }.associated_class
end
end
-
+
context "A resource that inherits from ReactiveResource::Base" do
-
+
setup do
@object = ReactiveResource::Lawyer.new
end
-
+
should "hit the Avvo API with the correct URL when saved" do
stub_request(:post, "https://api.avvo.com/api/1/lawyers.json")
@object.save
assert_requested(:post, "https://api.avvo.com/api/1/lawyers.json")
end
should "hit the Avvo API with the correct URL when retrieved" do
- stub_request(:get, "https://api.avvo.com/api/1/lawyers/1.json").to_return(:body => {:id => '1'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/1.json")\
+ .to_return(:body => {:lawyer => {:id => '1'}}.to_json)
ReactiveResource::Lawyer.find(1)
assert_requested(:get, "https://api.avvo.com/api/1/lawyers/1.json")
end
context "with a has_many relationship to another object" do
should "hit the associated object's URL with the correct parameters when requested" do
- stub_request(:get, "https://api.avvo.com/api/1/lawyers/1/addresses.json")
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/1/addresses.json")\
+ .to_return(:body => [{:address => {:id => 1}}].to_json)
@object.id = 1
@object.addresses
assert_requested(:get, "https://api.avvo.com/api/1/lawyers/1/addresses.json")
@@ -49,7 +51,8 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
context "with a has_one relationship to another object" do
should "hit the associated object's URL with the correct parameters when requested" do
- stub_request(:get, "https://api.avvo.com/api/1/lawyers/1/headshot.json").to_return(:body => {:headshot_url => "blah"}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/1/headshot.json")\
+ .to_return(:body => {:headhshot => {:headshot_url => "blah"}}.to_json)
@object.id = 1
@object.headshot
assert_requested(:get, "https://api.avvo.com/api/1/lawyers/1/headshot.json")
@@ -60,21 +63,23 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
setup do
@object = ReactiveResource::Address.new(:lawyer_id => 2)
end
-
+
should "hit the Avvo API with the correct URL when saved" do
stub_request(:post, "https://api.avvo.com/api/1/lawyers/2/addresses.json")
@object.save
assert_requested(:post, "https://api.avvo.com/api/1/lawyers/2/addresses.json")
end
-
+
should "hit the Avvo API with the correct URL when retrieved" do
- stub_request(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json").to_return(:body => {:id => '3'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")\
+ .to_return(:body => {:address => {:id => '3'}}.to_json)
ReactiveResource::Address.find(3, :params => {:lawyer_id => 2})
- assert_requested(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")
+ assert_requested(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")
end
should "hit the Avvo API with the correct URL when updated" do
- stub_request(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json").to_return(:body => {:id => '3'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")\
+ .to_return(:body => {:address => {:id => '3'}}.to_json)
license = ReactiveResource::Address.find(3, :params => {:lawyer_id => 2})
assert_requested(:get, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")
stub_request(:put, "https://api.avvo.com/api/1/lawyers/2/addresses/3.json")
@@ -83,7 +88,8 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
end
should "set the prefix parameters correctly when saved" do
- stub_request(:post, "https://api.avvo.com/api/1/lawyers/2/addresses.json").to_return(:body => {:id => '2'}.to_json)
+ stub_request(:post, "https://api.avvo.com/api/1/lawyers/2/addresses.json")\
+ .to_return(:body => {:address => {:id => '2'}}.to_json)
@object.save
assert_requested(:post, "https://api.avvo.com/api/1/lawyers/2/addresses.json")
@@ -112,7 +118,8 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
@object.doctor_id = 2
@object.address_id = 3
assert_equal 3, @object.address_id
- stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3.json").to_return(:body => {:id => '3'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3.json")\
+ .to_return(:body => {:address => {:id => '3'}}.to_json)
@object.address
@object.address
assert_requested(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3.json", :times => 1)
@@ -125,7 +132,8 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
end
should "hit the Avvo API with the correct URL when updated" do
- stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")\
+ .to_return(:body => {:address => {:id => '4'}}.to_json)
phone = ReactiveResource::Phone.find(4, :params => {:doctor_id => 2, :address_id => 3})
assert_requested(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
@@ -141,9 +149,10 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
assert_equal "/api/1/doctors/2/addresses/3/phones/4.json", @object.send(:element_path)
end
-
+
should "hit the Avvo API with the correct URL when retrieved" do
- stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json").to_return(:body => {:id => '4'}.to_json)
+ stub_request(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")\
+ .to_return(:body => {:phone => {:id => '4'}}.to_json)
ReactiveResource::Phone.find(4, :params => {:doctor_id => 2, :address_id => 3})
assert_requested(:get, "https://api.avvo.com/api/1/doctors/2/addresses/3/phones/4.json")
end
@@ -153,15 +162,17 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
context "A resource without an extension" do
should "hit the correct urls" do
- stub_request(:get, "https://api.avvo.com/api/1/no_extensions")
+ stub_request(:get, "https://api.avvo.com/api/1/no_extensions")\
+ .to_return(:body => [].to_json)
@object = ReactiveResource::NoExtension.find(:all)
assert_requested(:get, "https://api.avvo.com/api/1/no_extensions")
- stub_request(:put, "https://api.avvo.com/api/1/no_extensions/1")
+ stub_request(:post, "https://api.avvo.com/api/1/no_extensions")
@object = ReactiveResource::NoExtension.new(:id => 1).save
- assert_requested(:put, "https://api.avvo.com/api/1/no_extensions/1")
+ assert_requested(:post, "https://api.avvo.com/api/1/no_extensions")
- stub_request(:get, "https://api.avvo.com/api/1/no_extensions/test")
+ stub_request(:get, "https://api.avvo.com/api/1/no_extensions/test")\
+ .to_return(:body => {:test => {:id => 1}}.to_json)
@object = ReactiveResource::NoExtension.get(:test)
assert_requested(:get, "https://api.avvo.com/api/1/no_extensions/test")
end

0 comments on commit 7706353

Please sign in to comment.