Skip to content

has_one must respect parent’s prefix when target is not a Singleton - #300

Closed
denis wants to merge 1 commit into
rails:masterfrom
denis:has_one-must-respect-parents-prefix
Closed

denis wants to merge 1 commit into
rails:masterfrom
denis:has_one-must-respect-parents-prefix

Conversation

@denis

@denis denis commented Oct 6, 2018 •

Copy link
Copy Markdown

Consider a simple case when URLs are prefixed with API version:

class ApplicationResource < ActiveResource::Base
  self.site = "https://api.quovo.com/v3"
  self.include_format_in_path = false
end

class Connection < ApplicationResource
  has_one :sync
end

class Sync < ApplicationResource
end

connection = Connection.find(1) fetches data from https://api.quovo.com:443/v3/connections/1.

connection.sync is expected to fetch from https://api.quovo.com:443/v3/connections/1/sync but before this fix it tries to fetch it from https://api.quovo.com:443/connections/1/sync (missing /v3/ prefix) that isn’t correct.

I believe that the bug was introduced in #100.

Consider a simple case when URLs are prefixed with API version:

    class ApplicationResource < ActiveResource::Base
      self.site = "https://api.quovo.com/v3"
      self.include_format_in_path = false
    end

    class Connection < ApplicationResource
      has_one :sync
    end

    class Sync < ApplicationResource
    end

`connection = Connection.find(1)` fetches data from `https://api.quovo.com:443/v3/connections/1`.

`connection.sync` is expected to fetch from `https://api.quovo.com:443/v3/connections/1/sync` but before this fix it tries to fetch it from `https://api.quovo.com:443/connections/1/sync` (missing `/v3/` prefix) that isn’t correct.


I believe that the bug was introduced in rails#100.

@rafaelfranca rafaelfranca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead of editing existing test add a new test?

Comment thread test/cases/base_test.rb
end

def test_parse_non_singleton_resource_with_has_one_makes_get_request_on_child_route
accepts = { 'Accept' => 'application/json' }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this code being removed?

@rails-bot

rails-bot Bot commented Jan 30, 2019

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.

If it is an issue and you can still reproduce this error on the master branch,
please reply with all of the information you have about it in order to keep the issue open.

If it is a pull request and you are still interested on having it merged please make sure it can be merged clearly.

Thank you for all your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants