Merge pull request #339 from mhluska/fix-params-not-being-default
Fix params not being hash by default
This commit is contained in:
commit
74bb9d6f6d
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'active_support/time'
|
||||
require 'active_support/json'
|
||||
require 'active_support/concern'
|
||||
require 'active_support/inflector'
|
||||
@ -72,6 +73,7 @@ module FastJsonapi
|
||||
|
||||
def process_options(options)
|
||||
@fieldsets = deep_symbolize(options[:fields].presence || {})
|
||||
@params = {}
|
||||
|
||||
return if options.blank?
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe FastJsonapi::ObjectSerializer do
|
||||
|
||||
class MovieSerializer
|
||||
attribute :viewed do |movie, params|
|
||||
params ? movie.viewed?(params[:user]) : false
|
||||
params[:user] ? movie.viewed?(params[:user]) : false
|
||||
end
|
||||
|
||||
attribute :no_param_attribute do |movie|
|
||||
|
@ -504,4 +504,10 @@ describe FastJsonapi::ObjectSerializer do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when attribute contents are determined by params data' do
|
||||
it 'does not throw an error with no params are passed' do
|
||||
expect { MovieOptionalAttributeContentsWithParamsSerializer.new(movie).serialized_json }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -313,7 +313,7 @@ RSpec.shared_context 'movie class' do
|
||||
include FastJsonapi::ObjectSerializer
|
||||
set_type :movie
|
||||
attributes :name
|
||||
attribute :director, if: Proc.new { |record, params| params && params[:admin] == true }
|
||||
attribute :director, if: Proc.new { |record, params| params[:admin] == true }
|
||||
end
|
||||
|
||||
class MovieOptionalRelationshipSerializer
|
||||
@ -327,7 +327,19 @@ RSpec.shared_context 'movie class' do
|
||||
include FastJsonapi::ObjectSerializer
|
||||
set_type :movie
|
||||
attributes :name
|
||||
belongs_to :owner, record_type: :user, if: Proc.new { |record, params| params && params[:admin] == true }
|
||||
belongs_to :owner, record_type: :user, if: Proc.new { |record, params| params[:admin] == true }
|
||||
end
|
||||
|
||||
class MovieOptionalAttributeContentsWithParamsSerializer
|
||||
include FastJsonapi::ObjectSerializer
|
||||
set_type :movie
|
||||
attributes :name
|
||||
attribute :director do |record, params|
|
||||
data = {}
|
||||
data[:first_name] = 'steven'
|
||||
data[:last_name] = 'spielberg' if params[:admin]
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user