Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ def primary_key
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.json</tt>)
# This method is regenerated at runtime based on what the \prefix is set to.
def prefix(options = {})
raise ArgumentError, "Missing site URI" unless site
default = site.path
default << "/" unless default[-1..-1] == "/"
# generate the actual method based on the current site path
Expand Down Expand Up @@ -899,6 +900,7 @@ def element_path(id, prefix_options = {}, query_options = nil)
# # => https://37s.sunrise.com/posts/5/comments/1.json?active=1
#
def element_url(id, prefix_options = {}, query_options = nil)
raise ArgumentError, "Missing site URI" unless site
URI.join(site, element_path(id, prefix_options, query_options)).to_s
end

Expand Down Expand Up @@ -971,6 +973,7 @@ def collection_path(prefix_options = {}, query_options = nil)
# # => https://example.com/posts/5/comments.json?active=1
#
def collection_url(prefix_options = {}, query_options = nil)
raise ArgumentError, "Missing site URI" unless site
URI.join(site, collection_path(prefix_options, query_options)).to_s
end

Expand Down
14 changes: 14 additions & 0 deletions test/cases/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ def teardown
# Tests relating to setting up the API-connection configuration
########################################################################

def test_site_missing_error_message
Person.site = nil

assert_raises ArgumentError, match: "Missing site URI" do
Person.find(1)
end
assert_raises ArgumentError, match: "Missing site URI" do
Person.element_url(1)
end
assert_raises ArgumentError, match: "Missing site URI" do
Person.collection_url(1)
end
end

def test_site_accessor_accepts_uri_or_string_argument
site = URI.parse("http://localhost")

Expand Down
6 changes: 6 additions & 0 deletions test/cases/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ def test_disable_net_connection
end
end

def test_site_missing_error_message
assert_raises ArgumentError, match: "Missing site URI" do
ActiveResource::Connection.new(nil)
end
end

def keep_net_connection_status
old = ActiveResource::HttpMock.net_connection_enabled?
begin
Expand Down