Sha256: efa4674ad3e2570c8a8eb3f4e30279bc7c5718ca6286965e15403e0e849ffdc5

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 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

  # 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

11 entries across 11 versions & 1 rubygems

Version Path
superstore-1.0.11 test/unit/attribute_methods_test.rb
superstore-1.0.10 test/unit/attribute_methods_test.rb
superstore-1.0.9 test/unit/attribute_methods_test.rb
superstore-1.0.8 test/unit/attribute_methods_test.rb
superstore-1.0.7 test/unit/attribute_methods_test.rb
superstore-1.0.6 test/unit/attribute_methods_test.rb
superstore-1.0.5 test/unit/attribute_methods_test.rb
superstore-1.0.4 test/unit/attribute_methods_test.rb
superstore-1.0.3 test/unit/attribute_methods_test.rb
superstore-1.0.2 test/unit/attribute_methods_test.rb
superstore-1.0.0 test/unit/attribute_methods_test.rb