Sha256: 9fffd6fa3563f7b6144e5d9503899f5af3c0a8872b361e3e2e7784689353c552

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

require 'test_helper'

class TestToriDefine < Test::Unit::TestCase
  class CustomBackend
    def read(filename)
      "read:#{filename}"
    end
  end

  class Dammy
    extend Tori::Define
    tori :test_image
    bird = "piyo"
    tori :def_image do |model|
      "foo/#{__tori__}/bar/#{bird}"
    end
    tori :custom, to: CustomBackend.new do |model|
      "#{__tori__}/baz"
    end
  end

  class Uploader
  end

  test "#tori" do
    assert_respond_to Dammy.new, :test_image
    assert_respond_to Dammy.new, :test_image=
    assert_respond_to Dammy.new, :def_image
    assert_respond_to Dammy.new, :def_image=
    assert_respond_to Dammy.new, :custom
    assert_respond_to Dammy.new, :custom=
  end

  test "defined methods" do
    dammy = Dammy.new
    assert_instance_of Tori::File, dammy.test_image
    assert_instance_of Uploader, dammy.test_image = Uploader.new
    assert_instance_of Tori::File, dammy.test_image
    assert_instance_of Tori::Backend::FileSystem, dammy.test_image.backend
    assert_instance_of CustomBackend, dammy.custom.backend
  end

  test "defined method" do
    dammy = Dammy.new
    assert { false == dammy.def_image.exist? }
    assert { "read:custom/baz" == dammy.custom.read }
  end

  test "define name" do
    dammy = Dammy.new
    assert_instance_of Tori::File, dammy.def_image
    assert { "foo/def_image/bar/piyo" == dammy.def_image.name }
    assert { "custom/baz" == dammy.custom.name }
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
tori-0.8.0 test/test_tori_define.rb
tori-0.7.2 test/test_tori_define.rb
tori-0.7.1 test/test_tori_define.rb
tori-0.7.0 test/test_tori_define.rb
tori-0.6.6 test/test_tori_define.rb
tori-0.6.5 test/test_tori_define.rb
tori-0.6.4 test/test_tori_define.rb
tori-0.6.3 test/test_tori_define.rb
tori-0.6.2 test/test_tori_define.rb
tori-0.6.1 test/test_tori_define.rb
tori-0.6.0 test/test_tori_define.rb
tori-0.5.0 test/test_tori_define.rb