Sha256: 901380b9b0b9bb699267ce24d63404b7746448e18f2d1b477a24bc22dbad5b46

Contents?: true

Size: 606 Bytes

Versions: 16

Compression:

Stored size: 606 Bytes

Contents

require_relative 'helper'

class User < Ohm::Model
end

test "returns an empty hash if model doesn't have set attributes" do
  assert_equal Hash.new, User.new.to_hash
end

test "returns a hash with its id if model is persisted" do
  user = User.create

  assert_equal Hash[id: user.id], user.to_hash
end

class Person < Ohm::Model
  attribute :name

  def to_hash
    super.merge(name: name)
  end
end

test "returns additional attributes if the method is overrided" do
  person   = Person.create(name: "John")
  expected = { id: person.id, name: person.name }

  assert_equal expected, person.to_hash
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
ohm_util-0.1 test/to_hash.rb
ohm-3.1.1 test/to_hash.rb
ohm-3.1.0 test/to_hash.rb
ohm-3.0.3 test/to_hash.rb
ohm-3.0.2 test/to_hash.rb
ohm-3.0.1 test/to_hash.rb
ohm-3.0.0 test/to_hash.rb
ohm-2.3.0 test/to_hash.rb
ohm-2.2.1 test/to_hash.rb
sohm-0.0.1 test/to_hash.rb
ohm-2.2.0 test/to_hash.rb
ohm-2.1.0 test/to_hash.rb
ohm-2.0.1 test/to_hash.rb
ohm-2.0.0 test/to_hash.rb
ohm-2.0.0.rc2 test/to_hash.rb
ohm-2.0.0.rc1 test/to_hash.rb