mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add Model#attributes helper; make test attributes explicit
This commit is contained in:
@@ -3,18 +3,29 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class OptionsTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@profile = Profile.new(name: 'Name 1', description: 'Description 1')
|
||||
class ModelWithOptions < ActiveModelSerializers::Model
|
||||
attributes :name, :description
|
||||
end
|
||||
class ModelWithOptionsSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
|
||||
def arguments_passed_in?
|
||||
instance_options[:my_options] == :accessible
|
||||
end
|
||||
end
|
||||
|
||||
setup do
|
||||
@model_with_options = ModelWithOptions.new(name: 'Name 1', description: 'Description 1')
|
||||
end
|
||||
|
||||
def test_options_are_accessible
|
||||
@profile_serializer = ProfileSerializer.new(@profile, my_options: :accessible)
|
||||
assert @profile_serializer.arguments_passed_in?
|
||||
model_with_options_serializer = ModelWithOptionsSerializer.new(@model_with_options, my_options: :accessible)
|
||||
assert model_with_options_serializer.arguments_passed_in?
|
||||
end
|
||||
|
||||
def test_no_option_is_passed_in
|
||||
@profile_serializer = ProfileSerializer.new(@profile)
|
||||
refute @profile_serializer.arguments_passed_in?
|
||||
model_with_options_serializer = ModelWithOptionsSerializer.new(@model_with_options)
|
||||
refute model_with_options_serializer.arguments_passed_in?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user