Skip to content

Commit

Permalink
Change according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
simozhan committed Jan 17, 2018
1 parent 56de980 commit 7d2b5b1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lib/pdc/resource/associations/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def custom_class
@options[:class_name].constantize if @options[:class_name]
end

# Compute class if no custom class name provided.
# Referencing the codes from rails in following link:
# https://github.com/rails/rails/blob/70ac072976c8cc6f013f0df3777e54ccae3f4f8c/activerecord/lib/active_record/inheritance.rb#L132-L150
def compute_class(type_name)
parent_name = @parent_class.to_s
Expand Down
3 changes: 3 additions & 0 deletions lib/pdc/resource/associations/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Associations
class HasMany < Association
def initialize(*args)
super
# This is the default uri. It can be overrided when defining a has_many association
# if the uri is different with the default one.
# E.g: has_many :releases, uri: 'rest_api/v1/releases/?product_version=:product_version_id'
@options.reverse_merge!(uri: "#{parent_path}/:#{foreign_key}/#{@name}/(:#{primary_key})")
@params[foreign_key] = parent.id
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/fixtures/vcr/find_on_has_many_association.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/fixtures/vcr/has_many_association.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spec/fixtures/vcr/scopes_on_associations.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/pdc/resource/associations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
VCR.eject_cassette
end

let(:site) { 'https://pdc.host.dev.eng.pek2.redhat.com' }
let(:site) { 'https://example.com' }

let(:releases_url1) do
URI.join(site, PDC.config.api_root, 'v1/releases/?product_version=ceph-1&release_id=ceph-1.3@rhel-7')
Expand Down Expand Up @@ -46,7 +46,7 @@
end

describe 'array like' do
it 'array like behavior' do
it 'behaves like an array' do
product_version = Fixtures::ProductVersion.new(product_version_id: 'ceph-1')
assert_equal %w[ceph-1.3@rhel-7 ceph-1.3-updates@rhel-7], product_version.releases[0..1].map(&:release_id)
assert_equal 'ceph-1.3@rhel-7', product_version.releases.first.release_id
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CustomParserModel < Base
module Fixtures
class Association < PDC::Base
# stub the connection
SITE = 'https://pdc.host.dev.eng.pek2.redhat.com/'.freeze
SITE = 'https://example.com/'.freeze
self.connection = Faraday.new(url: SITE) do |faraday|
faraday.request :json
faraday.use PDC::Response::Parser
Expand Down

0 comments on commit 7d2b5b1

Please sign in to comment.