Sha256: 088b55401a1f3403ef12945eee0c63d5f30b6424276fee46b53c8b79fe1e0bbc

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

require 'test_helper'

class Superstore::AttributeMethodsTest < Superstore::TestCase
  test 'read and write attributes' do
    issue = Issue.new
    assert_nil issue.read_attribute(:description)

    issue.write_attribute(:description, nil)
    assert_nil issue.read_attribute(:description)

    issue.write_attribute(:description, 'foo')
    assert_equal 'foo', issue.read_attribute(:description)
  end

  test 'hash accessor aliases' do
    issue = Issue.new

    issue[:description] = 'bar'

    assert_equal 'bar', issue[:description]
  end

  test 'attributes setter' do
    issue = Issue.new

    issue.attributes = {
      description: 'foo'
    }

    assert_equal 'foo', issue.description
  end

  class ChildIssue < Issue
    def title=(val)
      self[:title] = val + ' lol'
    end
  end

  test 'override' do
    issue = ChildIssue.new(title: 'hey')

    assert_equal 'hey lol', issue.title
  end

  class ReservedWord < Superstore::Base
    string :system
  end

  test 'reserved words' do
    r = ReservedWord.new(system: 'hello')
    assert_equal 'hello', r.system
  end

  # test 'attribute_exists' do
  #   assert !Issue.new.attribute_exists?(:description)
  #   assert Issue.new(description: nil).attribute_exists?(:description)
  #   assert Issue.new(description: false).attribute_exists?(:description)
  #   assert Issue.new(description: 'hey').attribute_exists?(:description)
  # end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
superstore-2.0.1 test/unit/attribute_methods_test.rb
superstore-2.0.0 test/unit/attribute_methods_test.rb
superstore-1.2.0 test/unit/attribute_methods_test.rb
superstore-1.1.4 test/unit/attribute_methods_test.rb
superstore-1.1.3 test/unit/attribute_methods_test.rb
superstore-1.1.2 test/unit/attribute_methods_test.rb
superstore-1.1.1 test/unit/attribute_methods_test.rb
superstore-1.1.0 test/unit/attribute_methods_test.rb
superstore-1.0.12 test/unit/attribute_methods_test.rb