Sha256: 817980087aff54ce837fdf4c0611cee9bdea47322135b432a24c8608e27b408f

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

require "test_helper"

describe Vanity::Templates do
  before do
    not_collecting!
  end

  describe "template" do
    it "resolves templates from the configured path" do
      custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity')) # rubocop:todo Lint/UselessAssignment
      gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
      expected = File.join(gem_view_path, 'foo.html')

      assert_equal expected, Vanity::Templates.new.path('foo.html')
    end

    it "resolves templates from a Rails view directory when configured" do
      custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
      Vanity.configuration.templates_path = custom_view_path

      expected = File.expand_path(File.join(custom_view_path, 'foo.html'))

      FileUtils.mkpath(custom_view_path)
      File.open(expected, "w")

      assert_equal expected, Vanity::Templates.new.path('foo.html')
    ensure
      FileUtils.rm_rf(custom_view_path)
    end

    it "ignores an empty view directory" do
      custom_view_path = File.expand_path(File.join(Rails.root, 'app', 'views', 'vanity'))
      FileUtils.mkpath(custom_view_path)

      gem_view_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'vanity', 'templates'))
      expected = File.join(gem_view_path, 'foo.html')

      assert_equal expected, Vanity::Templates.new.path('foo.html')
    ensure
      FileUtils.rm_rf(custom_view_path)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vanity-4.0.4 test/templates_test.rb
vanity-4.0.3 test/templates_test.rb
vanity-4.0.2 test/templates_test.rb
vanity-4.0.1 test/templates_test.rb
vanity-4.0.0 test/templates_test.rb