Sha256: 9c34ecc012bba5b5502206a1cad08569ef3806e10d984af7539ef2ac97aa24da

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require 'cases/helper'
require 'models/contact'
require 'models/helicopter'

class ConversionTest < ActiveModel::TestCase
  test "to_model default implementation returns self" do
    contact = Contact.new
    assert_equal contact, contact.to_model
  end

  test "to_key default implementation returns nil for new records" do
    assert_nil Contact.new.to_key
  end

  test "to_key default implementation returns the id in an array for persisted records" do
    assert_equal [1], Contact.new(id: 1).to_key
  end

  test "to_param default implementation returns nil for new records" do
    assert_nil Contact.new.to_param
  end

  test "to_param default implementation returns a string of ids for persisted records" do
    assert_equal "1", Contact.new(id: 1).to_param
  end

  test "to_param returns the string joined by '-'" do
    assert_equal "abc-xyz", Contact.new(id: ["abc", "xyz"]).to_param
  end

  test "to_param returns nil if to_key is nil" do
    klass = Class.new(Contact) do
      def persisted?
        true
      end
    end

    assert_nil klass.new.to_param
  end

  test "to_partial_path default implementation returns a string giving a relative path" do
    assert_equal "contacts/contact", Contact.new.to_partial_path
    assert_equal "helicopters/helicopter", Helicopter.new.to_partial_path,
      "ActiveModel::Conversion#to_partial_path caching should be class-specific"
  end

  test "to_partial_path handles namespaced models" do
    assert_equal "helicopter/comanches/comanche", Helicopter::Comanche.new.to_partial_path
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/activemodel/test/cases/conversion_test.rb
activejob-lock-0.0.1 rails/activemodel/test/cases/conversion_test.rb