Sha256: 521209547370fec0daa174b7c36c1370d03e4517a4e2e3e8a8a7b98d168c470c
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') class CatBreed < ClassyEnum::Base enum_classes :abyssian, :bengal, :birman, :persian owner :cat def breed_color "#{cat.color} #{name}" end end class Cat < ActiveRecord::Base classy_enum_attr :breed, :enum => :cat_breed attr_accessor :color delegate :breed_color, :to => :breed end class OtherCat < ActiveRecord::Base classy_enum_attr :breed, :enum => :cat_breed, :serialize_as_json => true attr_accessor :color delegate :breed_color, :to => :breed end describe Cat do let(:abyssian) { Cat.new(:breed => :abyssian, :color => 'black') } let(:persian) { OtherCat.new(:breed => :persian, :color => 'white') } it 'should delegate breed color to breed with an ownership reference' do abyssian.breed_color { should eql('black Abyssian') } persian.breed_color { should eql('white Persian') } end it 'should correctly serialize without the owner reference' do abyssian.to_json.should == "{\"cat\":{\"breed\":\"abyssian\"}}" end it 'should convert the enum to a string when serializing' do persian.to_json.should == "{\"other_cat\":{\"breed\":{}}}" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
classy_enum-1.4.0 | spec/classy_enum_owner_reference_spec.rb |
classy_enum-1.3.2 | spec/classy_enum_owner_reference_spec.rb |