Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/tj-actions/changed…
Browse files Browse the repository at this point in the history
…-files-45.0.1
  • Loading branch information
lessthanjacob authored Sep 17, 2024
2 parents 42c7871 + ab3b5fe commit 9176021
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Initialize CodeQL
uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3
uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3
uses: github/codeql-action/autobuild@8214744c546c1e5c8f03dde8fab3a7353211988d # v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3
uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3
with:
category: "/language:${{matrix.language}}"
15 changes: 10 additions & 5 deletions lib/blueprinter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,16 @@ def self.association(method, options = {}, &block)

current_view << Association.new(
method: method,
name: options.delete(:name) || method,
extractor: options.delete(:extractor) || AssociationExtractor.new,
blueprint: options.delete(:blueprint),
view: options.delete(:view) || :default,
options: options.merge(block: block)
name: options.fetch(:name) { method },
extractor: options.fetch(:extractor) { AssociationExtractor.new },
blueprint: options.fetch(:blueprint),
view: options.fetch(:view, :default),
options: options.except(
:name,
:extractor,
:blueprint,
:view
).merge(block: block)
)
end

Expand Down
18 changes: 14 additions & 4 deletions lib/blueprinter/helpers/base_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ module SingletonMethods
private

def prepare_for_render(object, options)
view_name = options.delete(:view) || :default
root = options.delete(:root)
meta = options.delete(:meta)
view_name = options.fetch(:view, :default)
root = options[:root]
meta = options[:meta]
validate_root_and_meta!(root, meta)
prepare(object, view_name: view_name, local_options: options, root: root, meta: meta)
prepare(
object,
view_name: view_name,
local_options: options.except(
:view,
:root,
:meta
),
root: root,
meta: meta
)
end

def prepare_data(object, view_name, local_options)
Expand Down
21 changes: 21 additions & 0 deletions spec/integrations/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,27 @@ def extract(association_name, object, _local_options, _options={})
after { reset_blueprinter_config! }

it('returns the expected result') { should eq(result) }

context 'Given options containing `view` and rendered multiple times (as in batching)' do
let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id
view :with_make do
field :make
end
end
end

let(:options) { { view: :with_make } }

subject do
obj.map do |vehicle|
blueprint.render_as_hash(vehicle, options)
end.to_json
end

it('returns the expected result') { should eq(result) }
end
end
end
end
Expand Down

0 comments on commit 9176021

Please sign in to comment.