Sha256: fca5d50b6d6be8a014bccc313e554af960eacb6578fead35f8c11211b9299798
Contents?: true
Size: 1.75 KB
Versions: 3
Compression:
Stored size: 1.75 KB
Contents
# frozen_string_literal: true require 'test_helper' class DecoratorTest < Test::Unit::TestCase test 'it returns the object on decoration' do book = Book.new title: 'Boek' assert_equal book, ActiveDecorator::Decorator.instance.decorate(book) end test 'it returns the object when it already is decorated on decorate' do book = Book.new title: 'Boek' assert_equal book, ActiveDecorator::Decorator.instance.decorate(ActiveDecorator::Decorator.instance.decorate(book)) end test 'it returns the object of ActiveRecord::Relation on decorate' do 3.times do |index| Book.create title: "ve#{index}" end books = Book.all assert_equal books, ActiveDecorator::Decorator.instance.decorate(books) end test 'it returns the object of ActiveRecord::Relation when it already is decorated on decorate' do 3.times do |index| Book.create title: "ve#{index}" end books = Book.all assert_equal books, ActiveDecorator::Decorator.instance.decorate(ActiveDecorator::Decorator.instance.decorate(books)) end test 'decorating Array decorates its each element' do array = [Book.new(title: 'Boek')] assert_equal array, ActiveDecorator::Decorator.instance.decorate(array) array.each do |value| assert value.is_a?(BookDecorator) end end test 'decorating Hash decorates its each value' do hash = {some_record: Book.new(title: 'Boek')} assert_equal hash, ActiveDecorator::Decorator.instance.decorate(hash) hash.values.each do |value| assert value.is_a?(BookDecorator) end end test "Don't use the wrong decorator for nested classes" do comic = Foo::Comic.new assert_equal comic, ActiveDecorator::Decorator.instance.decorate(comic) assert !comic.is_a?(ComicDecorator) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_decorator-1.3.3 | test/decorator_test.rb |
active_decorator-1.3.2 | test/decorator_test.rb |
active_decorator-1.3.1 | test/decorator_test.rb |