mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Getting started: attributes.
Super super basic collection of attributes. Nothing fancy.
This commit is contained in:
18
test/attributes_test.rb
Normal file
18
test/attributes_test.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class AttributesTest < Minitest::Test
|
||||
def setup
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
@profile_serializer = ProfileSerializer.new(@profile)
|
||||
end
|
||||
|
||||
def test_attributes_definition
|
||||
assert_equal([:name, :description],
|
||||
@profile_serializer.class._attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
12
test/fixtures/poro.rb
vendored
Normal file
12
test/fixtures/poro.rb
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
class Model
|
||||
def initialize(hash={})
|
||||
@attributes = hash
|
||||
end
|
||||
end
|
||||
|
||||
class Profile < Model
|
||||
end
|
||||
|
||||
class ProfileSerializer < ActiveModel::Serializer
|
||||
attributes :name, :description
|
||||
end
|
||||
@@ -1,8 +1,9 @@
|
||||
require "bundler/setup"
|
||||
|
||||
require "active_model_serializers"
|
||||
require "active_support/json"
|
||||
|
||||
require 'rails'
|
||||
|
||||
require "active_support/json"
|
||||
require 'minitest/autorun'
|
||||
|
||||
require "active_model_serializers"
|
||||
|
||||
require 'fixtures/poro'
|
||||
|
||||
Reference in New Issue
Block a user