Sha256: eb42a998269d2ffe0d933dc12c606f95c11a168955bd599941f2c8cc6e2ff11d

Contents?: true

Size: 1.59 KB

Versions: 17

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

module STISpec

  class Parent < ActiveRecord::Base
    self.table_name = 'sti_records'
  end

  class Child < Parent
  end

  class ExtendedChild < ActiveType::Record[Child]
  end

  class ExtendedExtendedChild < ActiveType::Record[ExtendedChild]
  end

end


describe 'ActiveType::Record[STIModel]' do

  describe 'persistence' do

    def should_save_and_load(save_as, load_as)
      record = save_as.new(:persisted_string => "string")
      record.save.should be_true

      reloaded_child = load_as.find(record.id)
      reloaded_child.persisted_string.should == "string"
      reloaded_child.should be_a(load_as)
    end

    it 'can save and load the active type record' do

      should_save_and_load(STISpec::ExtendedChild, STISpec::ExtendedChild)
    end

    it 'can save as base and load as active type record' do
      should_save_and_load(STISpec::Child, STISpec::ExtendedChild)
    end

    it 'can save as active type and load as base record' do
      should_save_and_load(STISpec::ExtendedChild, STISpec::Child)
    end

    it 'can load via the base class and convert to active type record' do
      record = STISpec::ExtendedChild.new(:persisted_string => "string")
      record.save.should be_true

      reloaded_child = STISpec::Child.find(record.id).becomes(STISpec::ExtendedChild)
      reloaded_child.persisted_string.should == "string"
      reloaded_child.should be_a(STISpec::ExtendedChild)
    end

    it 'can save classes further down the inheritance tree' do
      should_save_and_load(STISpec::ExtendedExtendedChild, STISpec::ExtendedExtendedChild)
    end

  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_type-0.4.4 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.4.3 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.4.2 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.4.1 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.4.0 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.5 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.4 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.3 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.2 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.1 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.3.0 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.2.1 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.2.0 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.1.3 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.1.2 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.1.1 spec/active_type/extended_record/single_table_inheritance_spec.rb
active_type-0.1.0 spec/active_type/extended_record/single_table_inheritance_spec.rb