Skip to content

has_one fallback works when target is not a Singleton - #100

Merged
guilleiguaran merged 1 commit into
rails:masterfrom
capitalfactory:has-one-for-non-singleton
Jan 31, 2014
Merged

guilleiguaran merged 1 commit into
rails:masterfrom
capitalfactory:has-one-for-non-singleton

Conversation

@ches

@ches ches commented Oct 1, 2013

Copy link
Copy Markdown
Contributor

As documented:

if a Product class has_one :inventory calling Product#inventory will generate a request on /products/:product_id/inventory.json.

This was implemented in #15, but only implemented and tested for a true Singleton target. It should also work when the target model does not actually include Singleton, e.g. a Post has one Author.

Forgive me for being unfamiliar with the test suite -- I didn't immediately grok why I needed to add the @post mock with an explicit Accept header. If someone can clarify for me I'll clean up as appropriate.

As documented:

> if a Product class `has_one :inventory` calling `Product#inventory`
> will generate a request on /products/:product_id/inventory.json.

This was implemented in #15, but only implemented and tested for a true
Singleton target. It should also work when the target model does not
actually include Singleton, e.g. a Post has one Author.
guilleiguaran added a commit that referenced this pull request Jan 31, 2014
…ngleton

has_one fallback works when target is not a Singleton
@guilleiguaran
guilleiguaran merged commit a44cd76 into rails:master Jan 31, 2014
guilleiguaran added a commit that referenced this pull request Nov 30, 2015
…ngleton

has_one fallback works when target is not a Singleton
denis added a commit to denis/activeresource that referenced this pull request Oct 6, 2018
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants