Sha256: 228f0858731238d3640cc3dc5c784dfde76fdb2f178b159051a09249c304cae4

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

require 'test_helper'

module AdminModule
  module Engine
  end
  class SmartThing
    include ExpressTemplates::Components::Capabilities::Resourceful

    attr_accessor :virtual_path, :config

    def initialize(virtual_path, config = {})
      @virtual_path = virtual_path
      @config = config
      @args = [self]
    end

    def template_virtual_path
      @virtual_path
    end
  end
end

module Admin; end

class FooBar; end

class Something; end

module ExpressTemplates

  class ResourcefulTest < ActiveSupport::TestCase
    test 'infers namespace and path prefix within an engine and scope' do
      smart_thing = AdminModule::SmartThing.new('admin_module/admin/something/index')
      assert_equal 'admin_module', smart_thing.namespace
      assert_equal 'admin', smart_thing.path_prefix
    end

    test 'infers a namespace and no prefix within an engine' do
      # if defined? ExpressFoo::Engine
      smart_thing = AdminModule::SmartThing.new('admin_module/something/index')
      assert_equal 'admin_module', smart_thing.namespace
      assert_equal nil, smart_thing.path_prefix
    end

    test 'no namespace, infers prefix within a scope within an app' do
      # else of case above
      smart_thing = AdminModule::SmartThing.new('admin/something/index')
      assert_equal nil, smart_thing.namespace
      assert_equal 'admin', smart_thing.path_prefix
    end

    test 'no namespace, no prefix within an app' do
      smart_thing = AdminModule::SmartThing.new('somethings/index')
      assert_equal nil, smart_thing.namespace
      assert_equal nil, smart_thing.path_prefix
    end

    test "#resource_class returns resource_class option if specified" do
      assert_equal FooBar, AdminModule::SmartThing.new('somethings/index', resource_class: 'FooBar').resource_class
      assert_equal Something, AdminModule::SmartThing.new('somethings/index', id: :something).resource_class
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
express_admin-1.3.2 vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb
express_admin-1.3.1 vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb
express_templates-0.7.1 test/components/capabilities/resourceful_test.rb
express_templates-0.7.0 test/components/capabilities/resourceful_test.rb
express_admin-1.3.0 vendor/gems/express_templates/test/components/capabilities/resourceful_test.rb