Sha256: c63d25c40e77ff389b6a996aac73d2e3659deae17141c4eedc3e8c429714fe61
Contents?: true
Size: 976 Bytes
Versions: 4
Compression:
Stored size: 976 Bytes
Contents
require File.expand_path("#{File.dirname(__FILE__)}/helpers/helper") describe Sinatra::Decorator::DecorateHelpers do class User attr_accessor :username, :full_name def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) rescue nil end end end class UserDecorator < Sinatra::Decorator::Base def name object.full_name.present? ? object.full_name : object.username end end include Sinatra::Decorator::DecorateHelpers describe '.decorate' do let(:dorothy) { User.new(username: 'Dorothy', full_name: 'Dorothy Gale') } let(:toto) { User.new(username: 'Toto') } it 'Possible to decorate the single object' do assert_equal decorate(dorothy).name, dorothy.full_name end it 'Possible to decorate the collections' do users = [] users << dorothy users << toto assert_equal decorate(users).first.name, dorothy.full_name end end end
Version data entries
4 entries across 4 versions & 1 rubygems