Better usage of AMS::Model

This commit is contained in:
Benjamin Fleischer 2018-02-05 16:36:51 -06:00 committed by Shishir Kakaraddi
parent 7b029991b8
commit 7843e411f6

View File

@ -1,34 +1,28 @@
RSpec.shared_context 'ams movie class' do RSpec.shared_context 'ams movie class' do
before(:context) do before(:context) do
# models # models
class AMSMovie < ActiveModelSerializers::Model class AMSModel < ActiveModelSerializers::Model
attr_accessor :id, :name, :release_year, :actors, :owner, :movie_type derive_attributes_from_names_and_fix_accessors
end
class AMSMovie < AMSModel
attributes :id, :name, :release_year, :actors, :owner, :movie_type
end end
class AMSActor < ActiveModelSerializers::Model class AMSActor < AMSModel
attr_accessor :id, :name, :email attributes :id, :name, :email
end end
class AMSUser < ActiveModelSerializers::Model class AMSUser < AMSModel
attr_accessor :id, :name attributes :id, :name
end end
class AMSMovieType < ActiveModelSerializers::Model class AMSMovieType < AMSModel
attr_accessor :id, :name attributes :id, :name
end end
# serializers # serializers
class AMSMovieSerializer < ActiveModel::Serializer
type 'movie'
attributes :name, :release_year
has_many :actors
has_one :owner
belongs_to :movie_type
end
class AMSActorSerializer < ActiveModel::Serializer class AMSActorSerializer < ActiveModel::Serializer
type 'actor' type 'actor'
attributes :name, :email attributes :name, :email
end end
class AMSUserSerializer < ActiveModel::Serializer class AMSUserSerializer < ActiveModel::Serializer
type 'user' type 'user'
attributes :name attributes :name
@ -37,6 +31,13 @@ RSpec.shared_context 'ams movie class' do
type 'movie_type' type 'movie_type'
attributes :name attributes :name
end end
class AMSMovieSerializer < ActiveModel::Serializer
type 'movie'
attributes :name, :release_year
has_many :actors
has_one :owner
belongs_to :movie_type
end
end end
after(:context) do after(:context) do