aboutsummaryrefslogblamecommitdiffstats
path: root/activemodel/test/cases/attributes_test.rb
blob: 5f3ea839a4fd7b2f0f2b53400bd3dcfdcc9c5a92 (plain) (tree)





























                                                  
require 'cases/helper'

class AttributesTest < ActiveModel::TestCase
  class Person
    include ActiveModel::Attributes
    attr_accessor :name
  end

  test "reads attribute" do
    p = Person.new
    assert_equal nil, p.read_attribute(:name)

    p.name = "Josh"
    assert_equal "Josh", p.read_attribute(:name)
  end

  test "writes attribute" do
    p = Person.new
    assert_equal nil, p.name

    p.write_attribute(:name, "Josh")
    assert_equal "Josh", p.name
  end

  test "returns all attributes" do
    p = Person.new
    p.name = "Josh"
    assert_equal({"name" => "Josh"}, p.attributes)
  end
end